forked from VimPlug/jedi-vim
Compare commits
218 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc23f0b859 | ||
|
|
217e56d9bd | ||
|
|
0c2831d9a6 | ||
|
|
b3e91e8de2 | ||
|
|
13a4a0c0c4 | ||
|
|
2cf1d42fff | ||
|
|
84f5cd92c7 | ||
|
|
9af06424fb | ||
|
|
4b32847110 | ||
|
|
a5be01fb0b | ||
|
|
267df8b3da | ||
|
|
005cb5225f | ||
|
|
95d8eb1b08 | ||
|
|
431a0b11e5 | ||
|
|
9a258c74f5 | ||
|
|
5c868b9a1f | ||
|
|
62c423bf29 | ||
|
|
7abc3ad8d4 | ||
|
|
9633044332 | ||
|
|
067ab1ea4b | ||
|
|
e38981fc4f | ||
|
|
8ee4e12d3e | ||
|
|
b38ec94646 | ||
|
|
9c235c79ac | ||
|
|
8cfa121b4d | ||
|
|
c94fe6fcee | ||
|
|
5041224c13 | ||
|
|
4867831ad0 | ||
|
|
610cbcacb7 | ||
|
|
b5ec9ac3ed | ||
|
|
253eb5102c | ||
|
|
9ec2fb44b0 | ||
|
|
e241cf87fd | ||
|
|
525524b5cf | ||
|
|
267f66755d | ||
|
|
6b96313930 | ||
|
|
afc02a3621 | ||
|
|
bcf24529fa | ||
|
|
676b37812b | ||
|
|
0d52b56a72 | ||
|
|
45c0b91c5e | ||
|
|
261261af3d | ||
|
|
3f259c2a9e | ||
|
|
83e62d56ba | ||
|
|
ed09c7c1af | ||
|
|
2fbcc5b991 | ||
|
|
7890339ca8 | ||
|
|
91c2a031df | ||
|
|
0703494188 | ||
|
|
6dedbf339e | ||
|
|
889feae117 | ||
|
|
ac1615c647 | ||
|
|
d3484afe20 | ||
|
|
dc9688602c | ||
|
|
ed4a8be12e | ||
|
|
924b4db962 | ||
|
|
95b8dd77ba | ||
|
|
2e0be9069a | ||
|
|
b3978bc4aa | ||
|
|
91b4332774 | ||
|
|
133281a021 | ||
|
|
439e50e9d1 | ||
|
|
56b2268df3 | ||
|
|
a135f3b75b | ||
|
|
bce599fc9c | ||
|
|
0dd1b9fd44 | ||
|
|
6c1719a68a | ||
|
|
d79f41149f | ||
|
|
651eac91ff | ||
|
|
abc0c07d0f | ||
|
|
0747189516 | ||
|
|
dd33e38631 | ||
|
|
9a13f143a8 | ||
|
|
6025f59945 | ||
|
|
1bf69c5844 | ||
|
|
054285e2b7 | ||
|
|
fb77981040 | ||
|
|
de410d9347 | ||
|
|
299c9b26d3 | ||
|
|
4d67c1a6e3 | ||
|
|
154e2dbae3 | ||
|
|
b9ba141069 | ||
|
|
bf281dabda | ||
|
|
afb84a837c | ||
|
|
7539614f09 | ||
|
|
fc95545378 | ||
|
|
676c558110 | ||
|
|
65c06553fd | ||
|
|
4095d0efef | ||
|
|
527562208c | ||
|
|
baa2969427 | ||
|
|
dd4cb80911 | ||
|
|
e5038cc9fa | ||
|
|
2f06d90f95 | ||
|
|
03805f87f5 | ||
|
|
c38b549a95 | ||
|
|
83d398bc5d | ||
|
|
0f203c12b9 | ||
|
|
cfb76259f1 | ||
|
|
78ac52a26e | ||
|
|
3b26cf376b | ||
|
|
d76c00eff4 | ||
|
|
3c79979c50 | ||
|
|
1837cdee1f | ||
|
|
e43012afc8 | ||
|
|
2d74fe6c51 | ||
|
|
9779628322 | ||
|
|
3497a9644e | ||
|
|
0cd664d8f7 | ||
|
|
7784c29a59 | ||
|
|
8f7f07fb58 | ||
|
|
63dc0badac | ||
|
|
cc254432b6 | ||
|
|
ae8a2505bc | ||
|
|
839e1b5b85 | ||
|
|
27df21c7bf | ||
|
|
acdd711d84 | ||
|
|
9b11e70afe | ||
|
|
ab04982d63 | ||
|
|
a0bb09e891 | ||
|
|
2611ea3c27 | ||
|
|
fe517fae74 | ||
|
|
401731c98b | ||
|
|
b78f1d74c5 | ||
|
|
2bfae0acfa | ||
|
|
b7bdb5a06e | ||
|
|
a233d603e3 | ||
|
|
1005d1ad64 | ||
|
|
c22e2bcdf5 | ||
|
|
bf96f7d611 | ||
|
|
a120f428ff | ||
|
|
d3fadd54c7 | ||
|
|
d65c35a69d | ||
|
|
f714b58300 | ||
|
|
e87e7db0e9 | ||
|
|
cc9837dc23 | ||
|
|
43dcc4809f | ||
|
|
620b538f34 | ||
|
|
2ee17b3be6 | ||
|
|
69160c329a | ||
|
|
3071700635 | ||
|
|
075cd9ce69 | ||
|
|
2ba5656606 | ||
|
|
d82df60392 | ||
|
|
c9c0198467 | ||
|
|
6dcebb4644 | ||
|
|
28497ec3a9 | ||
|
|
78fc26456a | ||
|
|
55929b2713 | ||
|
|
b6bef9a056 | ||
|
|
59c98d61cf | ||
|
|
733ba775b0 | ||
|
|
b71ef1176c | ||
|
|
8016665639 | ||
|
|
bf4a8bfd5a | ||
|
|
789d06b573 | ||
|
|
9eaede84b2 | ||
|
|
18b9f08336 | ||
|
|
e3f4474dd7 | ||
|
|
c5c69f0ee1 | ||
|
|
74d51815a5 | ||
|
|
43d16b9966 | ||
|
|
2bccea9b5d | ||
|
|
05f2565dac | ||
|
|
57e476c214 | ||
|
|
48c9420136 | ||
|
|
a3210ce7b6 | ||
|
|
409da304b4 | ||
|
|
8ce612e3a6 | ||
|
|
f44ae4efe0 | ||
|
|
9ea98e2e81 | ||
|
|
fb1eaa611e | ||
|
|
e1a49790cb | ||
|
|
048b9dc286 | ||
|
|
cfd71a6b54 | ||
|
|
0ce1af78b2 | ||
|
|
3a8560ac58 | ||
|
|
6cc1d8c34a | ||
|
|
10cd4c6cfb | ||
|
|
2a6f35a91e | ||
|
|
d477ee6557 | ||
|
|
4ec0edafd8 | ||
|
|
2192f41442 | ||
|
|
8fded9837e | ||
|
|
6fabdd2fab | ||
|
|
997220d3a5 | ||
|
|
21efb8a0e8 | ||
|
|
1e0ae6bd35 | ||
|
|
b25db7ff5d | ||
|
|
a6f711fbbc | ||
|
|
12e9235bfd | ||
|
|
43eaec0aee | ||
|
|
089f9b0027 | ||
|
|
671b12da9a | ||
|
|
e620b5bf50 | ||
|
|
1792fb9e1b | ||
|
|
c32844dfec | ||
|
|
4e9aa671a7 | ||
|
|
61e1f46626 | ||
|
|
f8e5b8dbec | ||
|
|
503fe3da67 | ||
|
|
0f591e1283 | ||
|
|
21192f55f4 | ||
|
|
aa1d83cf68 | ||
|
|
feb7688d07 | ||
|
|
5e0bf55972 | ||
|
|
c9bede82b6 | ||
|
|
fa08586a94 | ||
|
|
bbe2861fa1 | ||
|
|
bb5c473633 | ||
|
|
4724e18b63 | ||
|
|
d9a43db019 | ||
|
|
ce7ba53224 | ||
|
|
154d9b8295 | ||
|
|
8f1e8f62fb | ||
|
|
ee46c28669 | ||
|
|
38f966092e | ||
|
|
99a9445acb |
10
AUTHORS.txt
10
AUTHORS.txt
@@ -40,6 +40,14 @@ Justin M. Keyes (@justinmk)
|
||||
nagev (@np1)
|
||||
Chris Lasher (@gotgenes) <chris.lasher@gmail.com>
|
||||
Doan Thanh Nam (@tndoan)
|
||||
|
||||
Markus Koller (@toupeira)
|
||||
Justin Cheevers @justincheevers
|
||||
Talha Ahmed (@talha81) <talha.ahmed@gmail.com>
|
||||
Matthew Tylee Atkinson (@matatk)
|
||||
Pedro Ferrari (@petobens)
|
||||
Daniel Hahler (@blueyed)
|
||||
Dave Honneffer (@pearofducks)
|
||||
Bagrat Aznauryan (@n9code)
|
||||
Tomoyuki Kashiro (@kashiro)
|
||||
|
||||
@something are github user names.
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
Pull Requests are great (on the **dev** branch)!
|
||||
# We <3 pull requests!
|
||||
|
||||
1. Fork the Repo on github.
|
||||
2. Add yourself to AUTHORS.txt
|
||||
3. Add a test if possible.
|
||||
4. Push to your fork and submit a **pull request to the dev branch**.
|
||||
4. Push to your fork and submit a pull request.
|
||||
|
||||
My **master** branch is a 100% stable (should be). I only push to it after I am
|
||||
certain that things are working out. Many people are using Jedi directly from
|
||||
the github master branch.
|
||||
Please use PEP8 as a Python code style. For VIM, just try to style your
|
||||
code similar to the jedi-vim code that is already there.
|
||||
|
||||
Please use Pep8 to style your code.
|
||||
# Bug reports
|
||||
Please include the output of `:version` and `:JediDebugInfo`.
|
||||
|
||||
59
README.rst
59
README.rst
@@ -6,7 +6,7 @@ jedi-vim - awesome Python autocompletion with VIM
|
||||
:target: https://travis-ci.org/davidhalter/jedi-vim
|
||||
:alt: Travis-CI build status
|
||||
|
||||
jedi-vim is a is a VIM binding to the autocompletion library
|
||||
jedi-vim is a VIM binding to the autocompletion library
|
||||
`Jedi <http://github.com/davidhalter/jedi>`_.
|
||||
|
||||
Here are some pictures:
|
||||
@@ -32,10 +32,14 @@ Documentation
|
||||
=============
|
||||
|
||||
Documentation is available in your vim: ``:help jedi-vim``. You can also look
|
||||
it up `on github <http://github.com/davidhalter/jedi-vim>`_.
|
||||
it up `on github <http://github.com/davidhalter/jedi-vim/blob/master/doc/jedi-vim.txt>`_.
|
||||
|
||||
You can read the Jedi library documentation `here <http://jedi.jedidjah.ch>`_.
|
||||
|
||||
If you want to report issues, just use the github issue tracker. In case of
|
||||
questions about the software, please use `stackoverflow
|
||||
<https://stackoverflow.com>`_ and tag your question with ``jedi-vim``.
|
||||
|
||||
|
||||
Contributing
|
||||
============
|
||||
@@ -67,22 +71,36 @@ Installation
|
||||
You might want to use `pathogen <https://github.com/tpope/vim-pathogen>`_ or
|
||||
`vundle <https://github.com/gmarik/vundle>`_ to install jedi in VIM. Also you
|
||||
need a VIM version that was compiled with ``+python``, which is typical for most
|
||||
distributions on Linux.
|
||||
distributions on Linux. The Python version compiled into VIM must be 2.6 or later
|
||||
(you can check this from within VIM using ``:python import sys; print sys.version`` )
|
||||
|
||||
The first thing you need after that is an up-to-date version of Jedi. You can
|
||||
either get it via ``pip install jedi`` or with ``git submodule update --init``
|
||||
in your jedi-vim repository.
|
||||
|
||||
On Arch Linux, you can also install jedi-vim from AUR: `vim-jedi
|
||||
<https://aur.archlinux.org/packages/vim-jedi/>`__.
|
||||
Example Installation Command using Pathogen:
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
cd ~/.vim/bundle/ && git clone --recursive https://github.com/davidhalter/jedi-vim.git
|
||||
|
||||
|
||||
On Arch Linux, you can also install jedi-vim from official repositories as `vim-jedi
|
||||
<https://www.archlinux.org/packages/community/any/vim-jedi/>`__. It is also available
|
||||
on `Debian (≥8) <https://packages.debian.org/vim-python-jedi>`__ and `Ubuntu (≥14.04)
|
||||
<http://packages.ubuntu.com/vim-python-jedi>`__ as vim-python-jedi. On Fedora Linux,
|
||||
it is available as `vim-jedi <https://apps.fedoraproject.org/packages/vim-jedi>`__.
|
||||
|
||||
Note that the `python-mode <https://github.com/klen/python-mode>`_ VIM plugin seems
|
||||
to conflict with jedi-vim, therefore you should disable it before enabling
|
||||
jedi-vim.
|
||||
|
||||
To enjoy the full features of Jedi-Vim, you should have VIM >= 7.3. For older
|
||||
version of VIM, the parameter recommendation list maybe not appeared when you type
|
||||
open bracket after the function name.
|
||||
To enjoy the full features of jedi-vim, you should have VIM >= 7.3, compiled with
|
||||
``+conceal`` (which is not the case on some platforms, including OS X). If your VIM
|
||||
does not meet these requirements, the parameter recommendation list may not appear
|
||||
when you type an open bracket after a function name. Please read
|
||||
`the documentation <http://github.com/davidhalter/jedi-vim/blob/master/doc/jedi-vim.txt>`_
|
||||
for details.
|
||||
|
||||
|
||||
Settings
|
||||
@@ -96,19 +114,18 @@ you disable the auto-initialization in your ``.vimrc``:
|
||||
let g:jedi#auto_initialization = 0
|
||||
|
||||
There are also some VIM options (like ``completeopt`` and key defaults) which
|
||||
are automatically initialized, but you can change all of them:
|
||||
are automatically initialized, but you can skip this:
|
||||
|
||||
.. code-block:: vim
|
||||
|
||||
let g:jedi#auto_vim_configuration = 0
|
||||
|
||||
|
||||
If you are a person who likes to use VIM-buffers not tabs, you might want to
|
||||
put that in your ``.vimrc``:
|
||||
You can make jedi-vim use tabs when going to a definition etc:
|
||||
|
||||
.. code-block:: vim
|
||||
|
||||
let g:jedi#use_tabs_not_buffers = 0
|
||||
let g:jedi#use_tabs_not_buffers = 1
|
||||
|
||||
If you are a person who likes to use VIM-splits, you might want to put this in your ``.vimrc``:
|
||||
|
||||
@@ -116,7 +133,7 @@ If you are a person who likes to use VIM-splits, you might want to put this in y
|
||||
|
||||
let g:jedi#use_splits_not_buffers = "left"
|
||||
|
||||
This options could be "left", "right", "top" or "bottom". It will decide the direction where the split open.
|
||||
This options could be "left", "right", "top", "bottom" or "winwidth". It will decide the direction where the split open.
|
||||
|
||||
Jedi automatically starts the completion, if you type a dot, e.g. ``str.``, if
|
||||
you don't want this:
|
||||
@@ -132,18 +149,30 @@ and usually saves one keypress.
|
||||
|
||||
let g:jedi#popup_select_first = 0
|
||||
|
||||
Jedi displays function call signatures in insert mode in real-time, highlighting
|
||||
the current argument. The call signatures can be displayed as a pop-up in the
|
||||
buffer (set to 1, the default), which has the advantage of being easier to refer
|
||||
to, or in Vim's command line aligned with the function call (set to 2), which
|
||||
can improve the integrity of Vim's undo history.
|
||||
|
||||
.. code-block:: vim
|
||||
|
||||
let g:jedi#show_call_signatures = "1"
|
||||
|
||||
Here are a few more defaults for actions, read the docs (``:help jedi-vim``) to
|
||||
get more information. If you set them to ``""``, they are not assigned.
|
||||
|
||||
.. code-block:: vim
|
||||
|
||||
NOTE: subject to change!
|
||||
|
||||
let g:jedi#goto_command = "<leader>d"
|
||||
let g:jedi#goto_assignments_command = "<leader>g"
|
||||
let g:jedi#goto_definitions_command = "<leader>d"
|
||||
let g:jedi#goto_definitions_command = ""
|
||||
let g:jedi#documentation_command = "K"
|
||||
let g:jedi#usages_command = "<leader>n"
|
||||
let g:jedi#completions_command = "<C-Space>"
|
||||
let g:jedi#rename_command = "<leader>r"
|
||||
let g:jedi#show_call_signatures = "1"
|
||||
|
||||
|
||||
Finally, if you don't want completion, but all the other features, use:
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
if !jedi#init_python()
|
||||
finish
|
||||
endif
|
||||
|
||||
if g:jedi#auto_initialization
|
||||
if g:jedi#completions_enabled
|
||||
" We need our own omnifunc, so this overrides the omnifunc set by
|
||||
@@ -6,11 +10,14 @@ if g:jedi#auto_initialization
|
||||
|
||||
" map ctrl+space for autocompletion
|
||||
if g:jedi#completions_command == "<C-Space>"
|
||||
" in terminals, <C-Space> sometimes equals <Nul>
|
||||
inoremap <expr> <Nul> jedi#complete_string(0)
|
||||
" In terminals, <C-Space> sometimes equals <Nul>.
|
||||
imap <buffer> <Nul> <C-Space>
|
||||
smap <buffer> <Nul> <C-Space>
|
||||
endif
|
||||
if g:jedi#completions_command != ""
|
||||
execute "inoremap <expr> <buffer> ".g:jedi#completions_command." jedi#complete_string(0)"
|
||||
" A separate mapping for select mode: deletes and completes.
|
||||
execute "snoremap <expr> <buffer> ".g:jedi#completions_command." '\<C-g>c'.jedi#complete_string(0)"
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
@@ -1,15 +1,22 @@
|
||||
if g:jedi#show_call_signatures == 1 && has('conceal')
|
||||
" conceal is normal for vim >= 7.3
|
||||
if !jedi#init_python()
|
||||
finish
|
||||
endif
|
||||
|
||||
let e = g:jedi#call_signature_escape
|
||||
let l1 = e.'jedi=[^'.e.']*'.e.'[^'.e.']*'.e.'jedi'.e
|
||||
let l2 = e.'jedi=\?[^'.e.']*'.e
|
||||
exe 'syn match jediIgnore "'.l2.'" contained conceal'
|
||||
if g:jedi#show_call_signatures > 0 && has('conceal')
|
||||
" +conceal is the default for vim >= 7.3
|
||||
|
||||
let s:e = g:jedi#call_signature_escape
|
||||
let s:full = s:e.'jedi=.\{-}'.s:e.'.\{-}'.s:e.'jedi'.s:e
|
||||
let s:ignore = s:e.'jedi.\{-}'.s:e
|
||||
exe 'syn match jediIgnore "'.s:ignore.'" contained conceal'
|
||||
setlocal conceallevel=2
|
||||
syn match jediFatSymbol "*" contained conceal
|
||||
syn match jediFat "\*[^*]\+\*" contained contains=jediFatSymbol
|
||||
syn match jediFatSymbol "\*_\*" contained conceal
|
||||
syn match jediFat "\*_\*.\{-}\*_\*" contained contains=jediFatSymbol
|
||||
syn match jediSpace "\v[ ]+( )@=" contained
|
||||
exe 'syn match jediFunction "'.l1.'" keepend extend contains=jediIgnore,jediFat,jediSpace'
|
||||
exe 'syn match jediFunction "'.s:full.'" keepend extend '
|
||||
\ .' contains=jediIgnore,jediFat,jediSpace'
|
||||
\ .' containedin=pythonComment,pythonString,pythonRawString'
|
||||
unlet! s:e s:full s:ignore
|
||||
|
||||
hi def link jediIgnore Ignore
|
||||
hi def link jediFatSymbol Ignore
|
||||
@@ -21,20 +28,5 @@ if g:jedi#show_call_signatures == 1 && has('conceal')
|
||||
else
|
||||
hi jediFunction term=NONE cterm=NONE ctermfg=6 guifg=Black gui=NONE ctermbg=0 guibg=Grey
|
||||
hi jediFat term=bold,underline cterm=bold,underline gui=bold,underline ctermbg=0 guibg=#555555
|
||||
end
|
||||
|
||||
" override defaults (add jediFunction to contains)
|
||||
syn match pythonComment "#.*$" contains=pythonTodo,@Spell,jediFunction
|
||||
syn region pythonString
|
||||
\ start=+[uU]\=\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
|
||||
\ contains=pythonEscape,@Spell,jediFunction
|
||||
syn region pythonString
|
||||
\ start=+[uU]\=\z('''\|"""\)+ end="\z1" keepend
|
||||
\ contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell,jediFunction
|
||||
syn region pythonRawString
|
||||
\ start=+[uU]\=[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
|
||||
\ contains=@Spell,jediFunction
|
||||
syn region pythonRawString
|
||||
\ start=+[uU]\=[rR]\z('''\|"""\)+ end="\z1" keepend
|
||||
\ contains=pythonSpaceError,pythonDoctest,@Spell,jediFunction
|
||||
endif
|
||||
endif
|
||||
|
||||
@@ -1,44 +1,263 @@
|
||||
scriptencoding utf-8
|
||||
|
||||
" ------------------------------------------------------------------------
|
||||
" Settings initialization
|
||||
" ------------------------------------------------------------------------
|
||||
let s:deprecations = {
|
||||
\ 'get_definition_command': 'goto_definitions_command',
|
||||
\ 'pydoc': 'documentation_command',
|
||||
\ 'related_names_command': 'usages_command',
|
||||
\ 'autocompletion_command': 'completions_command',
|
||||
\ 'show_function_definition': 'show_call_signatures',
|
||||
\ }
|
||||
|
||||
let s:default_settings = {
|
||||
\ 'use_tabs_not_buffers': 0,
|
||||
\ 'use_splits_not_buffers': 1,
|
||||
\ 'auto_initialization': 1,
|
||||
\ 'auto_vim_configuration': 1,
|
||||
\ 'goto_command': "'<leader>d'",
|
||||
\ 'goto_assignments_command': "'<leader>g'",
|
||||
\ 'goto_definitions_command': "''",
|
||||
\ 'completions_command': "'<C-Space>'",
|
||||
\ 'call_signatures_command': "'<leader>n'",
|
||||
\ 'usages_command': "'<leader>n'",
|
||||
\ 'rename_command': "'<leader>r'",
|
||||
\ 'popup_on_dot': 1,
|
||||
\ 'documentation_command': "'K'",
|
||||
\ 'show_call_signatures': 1,
|
||||
\ 'show_call_signatures_delay': 500,
|
||||
\ 'call_signature_escape': "'=`='",
|
||||
\ 'auto_close_doc': 1,
|
||||
\ 'max_doc_height': 30,
|
||||
\ 'popup_select_first': 1,
|
||||
\ 'quickfix_window_height': 10,
|
||||
\ 'completions_enabled': 1,
|
||||
\ 'force_py_version': "'auto'",
|
||||
\ 'smart_auto_mappings': 1,
|
||||
\ 'use_tag_stack': 1
|
||||
\ }
|
||||
|
||||
for [s:key, s:val] in items(s:deprecations)
|
||||
if exists('g:jedi#'.s:key)
|
||||
echom "'g:jedi#".s:key."' is deprecated. Please use 'g:jedi#".s:val."' instead. Sorry for the inconvenience."
|
||||
exe 'let g:jedi#'.s:val.' = g:jedi#'.s:key
|
||||
endif
|
||||
endfor
|
||||
|
||||
for [s:key, s:val] in items(s:default_settings)
|
||||
if !exists('g:jedi#'.s:key)
|
||||
exe 'let g:jedi#'.s:key.' = '.s:val
|
||||
endif
|
||||
endfor
|
||||
|
||||
|
||||
" ------------------------------------------------------------------------
|
||||
" Python initialization
|
||||
" ------------------------------------------------------------------------
|
||||
let s:script_path = fnameescape(expand('<sfile>:p:h:h'))
|
||||
|
||||
function! s:init_python()
|
||||
if g:jedi#force_py_version != 'auto'
|
||||
" Always use the user supplied version.
|
||||
try
|
||||
return jedi#force_py_version(g:jedi#force_py_version)
|
||||
catch
|
||||
throw "Could not setup g:jedi#force_py_version: ".v:exception
|
||||
endtry
|
||||
endif
|
||||
|
||||
" Handle "auto" version.
|
||||
if has('nvim') || (has('python') && has('python3'))
|
||||
" Neovim usually has both python providers. Skipping the `has` check
|
||||
" avoids starting both of them.
|
||||
|
||||
" Get default python version from interpreter in $PATH.
|
||||
let s:def_py = system('python -c '.shellescape('import sys; sys.stdout.write(str(sys.version_info[0]))'))
|
||||
if v:shell_error != 0 || !len(s:def_py)
|
||||
if !exists("g:jedi#squelch_py_warning")
|
||||
echohl WarningMsg
|
||||
echom "Warning: jedi-vim failed to get Python version from sys.version_info: " . s:def_py
|
||||
echom "Falling back to version 2."
|
||||
echohl None
|
||||
endif
|
||||
let s:def_py = 2
|
||||
elseif &verbose
|
||||
echom "jedi-vim: auto-detected Python: ".s:def_py
|
||||
endif
|
||||
|
||||
" Make sure that the auto-detected version is available in Vim.
|
||||
if !has('nvim') || has('python'.(s:def_py == 2 ? '' : s:def_py))
|
||||
return jedi#force_py_version(s:def_py)
|
||||
endif
|
||||
|
||||
" Add a warning in case the auto-detected version is not available,
|
||||
" usually because of a missing neovim module in a VIRTUAL_ENV.
|
||||
if has('nvim')
|
||||
echohl WarningMsg
|
||||
echom "jedi-vim: the detected Python version (".s:def_py.")"
|
||||
\ "is not functional."
|
||||
\ "Is the 'neovim' module installed?"
|
||||
\ "While jedi-vim will work, it might not use the"
|
||||
\ "expected Python path."
|
||||
echohl None
|
||||
endif
|
||||
endif
|
||||
|
||||
if has('python')
|
||||
call jedi#setup_py_version(2)
|
||||
elseif has('python3')
|
||||
call jedi#setup_py_version(3)
|
||||
else
|
||||
throw "jedi-vim requires Vim with support for Python 2 or 3."
|
||||
endif
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
|
||||
function! jedi#reinit_python()
|
||||
unlet! s:_init_python
|
||||
call jedi#init_python()
|
||||
endfunction
|
||||
|
||||
|
||||
function! jedi#init_python()
|
||||
if !exists('s:_init_python')
|
||||
try
|
||||
let s:_init_python = s:init_python()
|
||||
catch
|
||||
if !exists("g:jedi#squelch_py_warning")
|
||||
echohl WarningMsg
|
||||
echom "Error: jedi-vim failed to initialize Python: ".v:exception." (in ".v:throwpoint.")"
|
||||
echohl None
|
||||
endif
|
||||
let s:_init_python = 0
|
||||
endtry
|
||||
endif
|
||||
return s:_init_python
|
||||
endfunction
|
||||
|
||||
|
||||
let s:python_version = 'null'
|
||||
function! jedi#setup_py_version(py_version)
|
||||
if a:py_version == 2
|
||||
let cmd_init = 'pyfile'
|
||||
let cmd_exec = 'python'
|
||||
let s:python_version = 2
|
||||
elseif a:py_version == 3
|
||||
let cmd_init = 'py3file'
|
||||
let cmd_exec = 'python3'
|
||||
let s:python_version = 3
|
||||
else
|
||||
throw "jedi#setup_py_version: invalid py_version: ".a:py_version
|
||||
endif
|
||||
|
||||
try
|
||||
execute cmd_init.' '.s:script_path.'/initialize.py'
|
||||
execute 'command! -nargs=1 PythonJedi '.cmd_exec.' <args>'
|
||||
return 1
|
||||
catch
|
||||
throw "jedi#setup_py_version: ".v:exception
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
|
||||
function! jedi#debug_info()
|
||||
echom "Using Python version:" s:python_version
|
||||
endfunction
|
||||
|
||||
|
||||
function! jedi#force_py_version(py_version)
|
||||
let g:jedi#force_py_version = a:py_version
|
||||
return jedi#setup_py_version(a:py_version)
|
||||
endfunction
|
||||
|
||||
|
||||
function! jedi#force_py_version_switch()
|
||||
if g:jedi#force_py_version == 2
|
||||
call jedi#force_py_version(3)
|
||||
elseif g:jedi#force_py_version == 3
|
||||
call jedi#force_py_version(2)
|
||||
else
|
||||
throw "Don't know how to switch from ".g:jedi#force_py_version."!"
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
" Helper function instead of `python vim.eval()`, and `.command()` because
|
||||
" these also return error definitions.
|
||||
function! jedi#_vim_exceptions(str, is_eval)
|
||||
let l:result = {}
|
||||
try
|
||||
if a:is_eval
|
||||
let l:result.result = eval(a:str)
|
||||
else
|
||||
execute a:str
|
||||
let l:result.result = ''
|
||||
endif
|
||||
catch
|
||||
let l:result.exception = v:exception
|
||||
let l:result.throwpoint = v:throwpoint
|
||||
endtry
|
||||
return l:result
|
||||
endfunction
|
||||
|
||||
|
||||
if !jedi#init_python()
|
||||
" Do not define any functions when Python initialization failed.
|
||||
finish
|
||||
endif
|
||||
|
||||
|
||||
" ------------------------------------------------------------------------
|
||||
" functions that call python code
|
||||
" ------------------------------------------------------------------------
|
||||
function! jedi#goto()
|
||||
PythonJedi jedi_vim.goto(mode="goto")
|
||||
endfunction
|
||||
|
||||
function! jedi#goto_assignments()
|
||||
Python jedi_vim.goto()
|
||||
PythonJedi jedi_vim.goto(mode="assignment")
|
||||
endfunction
|
||||
|
||||
function! jedi#goto_definitions()
|
||||
Python jedi_vim.goto(is_definition=True)
|
||||
PythonJedi jedi_vim.goto(mode="definition")
|
||||
endfunction
|
||||
|
||||
function! jedi#usages()
|
||||
Python jedi_vim.goto(is_related_name=True)
|
||||
PythonJedi jedi_vim.goto(mode="related_name")
|
||||
endfunction
|
||||
|
||||
function! jedi#rename(...)
|
||||
Python jedi_vim.rename()
|
||||
PythonJedi jedi_vim.rename()
|
||||
endfunction
|
||||
|
||||
function! jedi#rename_visual(...)
|
||||
PythonJedi jedi_vim.rename_visual()
|
||||
endfunction
|
||||
|
||||
function! jedi#completions(findstart, base)
|
||||
Python jedi_vim.completions()
|
||||
PythonJedi jedi_vim.completions()
|
||||
endfunction
|
||||
|
||||
function! jedi#enable_speed_debugging()
|
||||
Python jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout, speed=True, warnings=False, notices=False)
|
||||
PythonJedi jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout, speed=True, warnings=False, notices=False)
|
||||
endfunction
|
||||
|
||||
function! jedi#enable_debugging()
|
||||
Python jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout)
|
||||
PythonJedi jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout)
|
||||
endfunction
|
||||
|
||||
function! jedi#disable_debugging()
|
||||
Python jedi_vim.jedi.set_debug_function(None)
|
||||
PythonJedi jedi_vim.jedi.set_debug_function(None)
|
||||
endfunction
|
||||
|
||||
function! jedi#py_import(args)
|
||||
Python jedi_vim.py_import()
|
||||
PythonJedi jedi_vim.py_import()
|
||||
endfun
|
||||
|
||||
function! jedi#py_import_completions(argl, cmdl, pos)
|
||||
Python jedi_vim.py_import_completions()
|
||||
PythonJedi jedi_vim.py_import_completions()
|
||||
endfun
|
||||
|
||||
|
||||
@@ -46,11 +265,17 @@ endfun
|
||||
" show_documentation
|
||||
" ------------------------------------------------------------------------
|
||||
function! jedi#show_documentation()
|
||||
Python jedi_vim.show_documentation()
|
||||
PythonJedi if jedi_vim.show_documentation() is None: vim.command('return')
|
||||
|
||||
if bufnr("__doc__") > 0
|
||||
" If the __doc__ buffer is open in the current window, jump to it
|
||||
silent execute "sbuffer ".bufnr("__doc__")
|
||||
let bn = bufnr("__doc__")
|
||||
if bn > 0
|
||||
let wi=index(tabpagebuflist(tabpagenr()), bn)
|
||||
if wi >= 0
|
||||
" If the __doc__ buffer is open in the current tab, jump to it
|
||||
silent execute (wi+1).'wincmd w'
|
||||
else
|
||||
silent execute "sbuffer ".bn
|
||||
endif
|
||||
else
|
||||
split '__doc__'
|
||||
endif
|
||||
@@ -65,14 +290,14 @@ function! jedi#show_documentation()
|
||||
setlocal nomodified
|
||||
setlocal filetype=rst
|
||||
|
||||
if l:doc_lines > 30 " max lines for plugin
|
||||
let l:doc_lines = 30
|
||||
if l:doc_lines > g:jedi#max_doc_height " max lines for plugin
|
||||
let l:doc_lines = g:jedi#max_doc_height
|
||||
endif
|
||||
execute "resize ".l:doc_lines
|
||||
|
||||
" quit comands
|
||||
nnoremap <buffer> q ZQ
|
||||
nnoremap <buffer> K ZQ
|
||||
execute "nnoremap <buffer> ".g:jedi#documentation_command." ZQ"
|
||||
|
||||
" highlight python code within rst
|
||||
unlet! b:current_syntax
|
||||
@@ -88,13 +313,14 @@ endfunction
|
||||
" helper functions
|
||||
" ------------------------------------------------------------------------
|
||||
|
||||
function! jedi#add_goto_window()
|
||||
function! jedi#add_goto_window(len)
|
||||
set lazyredraw
|
||||
cclose
|
||||
execute 'belowright copen '.g:jedi#quickfix_window_height
|
||||
let height = min([a:len, g:jedi#quickfix_window_height])
|
||||
execute 'belowright copen '.height
|
||||
set nolazyredraw
|
||||
if g:jedi#use_tabs_not_buffers == 1
|
||||
map <buffer> <CR> :call jedi#goto_window_on_enter()<CR>
|
||||
noremap <buffer> <CR> :call jedi#goto_window_on_enter()<CR>
|
||||
endif
|
||||
au WinLeave <buffer> q " automatically leave, if an option is chosen
|
||||
redraw!
|
||||
@@ -107,7 +333,7 @@ function! jedi#goto_window_on_enter()
|
||||
if l:data.bufnr
|
||||
" close goto_window buffer
|
||||
normal ZQ
|
||||
Python jedi_vim.new_buffer(vim.eval('bufname(l:data.bufnr)'))
|
||||
PythonJedi jedi_vim.new_buffer(vim.eval('bufname(l:data.bufnr)'))
|
||||
call cursor(l:data.lnum, l:data.col)
|
||||
else
|
||||
echohl WarningMsg | echo "Builtin module cannot be opened." | echohl None
|
||||
@@ -142,31 +368,104 @@ function! jedi#do_popup_on_dot_in_highlight()
|
||||
endfunc
|
||||
|
||||
|
||||
function! jedi#popup_on_dot_string()
|
||||
let s:show_call_signatures_last = [0, 0, '']
|
||||
function! jedi#show_call_signatures()
|
||||
let [line, col] = [line('.'), col('.')]
|
||||
let curline = getline(line)
|
||||
let reload_signatures = 1
|
||||
|
||||
" Caching. On the same line only.
|
||||
if line == s:show_call_signatures_last[0]
|
||||
" Check if the number of commas and parenthesis before or after the
|
||||
" cursor has not changed since the last call, which means that the
|
||||
" argument position was not changed and we can skip repainting.
|
||||
let prevcol = s:show_call_signatures_last[1]
|
||||
let prevline = s:show_call_signatures_last[2]
|
||||
if substitute(curline[:col-2], '[^,()]', '', 'g')
|
||||
\ == substitute(prevline[:prevcol-2], '[^,()]', '', 'g')
|
||||
\ && substitute(curline[(col-2):], '[^,()]', '', 'g')
|
||||
\ == substitute(prevline[(prevcol-2):], '[^,()]', '', 'g')
|
||||
let reload_signatures = 0
|
||||
endif
|
||||
endif
|
||||
let s:show_call_signatures_last = [line, col, curline]
|
||||
|
||||
if reload_signatures
|
||||
PythonJedi jedi_vim.show_call_signatures()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
function! jedi#clear_call_signatures()
|
||||
let s:show_call_signatures_last = [0, 0, '']
|
||||
PythonJedi jedi_vim.clear_call_signatures()
|
||||
endfunction
|
||||
|
||||
|
||||
function! jedi#configure_call_signatures()
|
||||
autocmd InsertLeave <buffer> Python jedi_vim.clear_call_signatures()
|
||||
autocmd CursorMovedI <buffer> Python jedi_vim.show_call_signatures()
|
||||
augroup jedi_call_signatures
|
||||
autocmd! * <buffer>
|
||||
if g:jedi#show_call_signatures == 2 " Command line call signatures
|
||||
autocmd InsertEnter <buffer> let g:jedi#first_col = s:save_first_col()
|
||||
endif
|
||||
autocmd InsertEnter <buffer> let s:show_call_signatures_last = [0, 0, '']
|
||||
autocmd InsertLeave <buffer> call jedi#clear_call_signatures()
|
||||
if g:jedi#show_call_signatures_delay > 0
|
||||
autocmd InsertEnter <buffer> let b:_jedi_orig_updatetime = &updatetime
|
||||
\ | let &updatetime = g:jedi#show_call_signatures_delay
|
||||
autocmd InsertLeave <buffer> if exists('b:_jedi_orig_updatetime')
|
||||
\ | let &updatetime = b:_jedi_orig_updatetime
|
||||
\ | unlet b:_jedi_orig_updatetime
|
||||
\ | endif
|
||||
autocmd CursorHoldI <buffer> call jedi#show_call_signatures()
|
||||
else
|
||||
autocmd CursorMovedI <buffer> call jedi#show_call_signatures()
|
||||
endif
|
||||
augroup END
|
||||
endfunction
|
||||
|
||||
" Helper function instead of `python vim.eval()`, and `.command()` because
|
||||
" these also return error definitions.
|
||||
function! jedi#_vim_exceptions(str, is_eval)
|
||||
let l:result = {}
|
||||
try
|
||||
if a:is_eval
|
||||
let l:result.result = eval(a:str)
|
||||
else
|
||||
execute a:str
|
||||
let l:result.result = ''
|
||||
|
||||
" Determine where the current window is on the screen for displaying call
|
||||
" signatures in the correct column.
|
||||
function! s:save_first_col()
|
||||
if bufname('%') ==# '[Command Line]' || winnr('$') == 1
|
||||
return 0
|
||||
endif
|
||||
catch
|
||||
let l:result.exception = v:exception
|
||||
let l:result.throwpoint = v:throwpoint
|
||||
endtry
|
||||
return l:result
|
||||
|
||||
let startwin = winnr()
|
||||
let winwidth = winwidth(0)
|
||||
if winwidth == &columns
|
||||
return 0
|
||||
elseif winnr('$') == 2
|
||||
return startwin == 1 ? 0 : (winwidth(1) + 1)
|
||||
elseif winnr('$') == 3
|
||||
if startwin == 1
|
||||
return 0
|
||||
endif
|
||||
let ww1 = winwidth(1)
|
||||
let ww2 = winwidth(2)
|
||||
let ww3 = winwidth(3)
|
||||
if ww1 + ww2 + ww3 + 2 == &columns
|
||||
if startwin == 2
|
||||
return ww1 + 1
|
||||
else
|
||||
return ww1 + ww2 + 2
|
||||
endif
|
||||
elseif startwin == 2
|
||||
if ww2 + ww3 + 1 == &columns
|
||||
return 0
|
||||
else
|
||||
return ww1 + 1
|
||||
endif
|
||||
else " startwin == 3
|
||||
if ww2 + ww3 + 1 == &columns
|
||||
return ww2 + 1
|
||||
else
|
||||
return ww1 + 1
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -175,124 +474,44 @@ function! jedi#complete_string(is_popup_on_dot)
|
||||
if a:is_popup_on_dot && !(g:jedi#popup_on_dot && jedi#do_popup_on_dot_in_highlight())
|
||||
return ''
|
||||
|
||||
end
|
||||
endif
|
||||
if pumvisible() && !a:is_popup_on_dot
|
||||
return "\<C-n>"
|
||||
else
|
||||
return "\<C-x>\<C-o>\<C-r>=jedi#complete_opened()\<CR>"
|
||||
end
|
||||
return "\<C-x>\<C-o>\<C-r>=jedi#complete_opened(".a:is_popup_on_dot.")\<CR>"
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
function! jedi#complete_opened()
|
||||
if pumvisible() && g:jedi#popup_select_first && stridx(&completeopt, 'longest') > -1
|
||||
" only go down if it is visible, user-enabled and the longest option is set
|
||||
function! jedi#complete_opened(is_popup_on_dot)
|
||||
if pumvisible()
|
||||
" Only go down if it is visible, user-enabled and the longest
|
||||
" option is set.
|
||||
if g:jedi#popup_select_first && stridx(&completeopt, 'longest') > -1
|
||||
return "\<Down>"
|
||||
end
|
||||
endif
|
||||
if a:is_popup_on_dot
|
||||
if &completeopt !~ '\(noinsert\|noselect\)'
|
||||
" Prevent completion of the first entry with dot completion.
|
||||
return "\<C-p>"
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
return ""
|
||||
endfunction
|
||||
|
||||
|
||||
function! jedi#force_py_version(py_version)
|
||||
let g:jedi#force_py_version = a:py_version
|
||||
if g:jedi#force_py_version == 2
|
||||
command! -nargs=1 Python python <args>
|
||||
execute 'pyfile '.s:script_path.'/initialize.py'
|
||||
elseif g:jedi#force_py_version == 3
|
||||
command! -nargs=1 Python python3 <args>
|
||||
execute 'py3file '.s:script_path.'/initialize.py'
|
||||
function! jedi#smart_auto_mappings()
|
||||
" Auto put import statement after from module.name<space> and complete
|
||||
if search('^\s*from\s\+[A-Za-z0-9._]\{1,50}\%#\s*$', 'bcn', line('.'))
|
||||
" Enter character and start completion.
|
||||
return "\<space>import \<C-x>\<C-o>\<C-r>=jedi#complete_opened(1)\<CR>"
|
||||
endif
|
||||
return "\<space>"
|
||||
endfunction
|
||||
|
||||
|
||||
function! jedi#force_py_version_switch()
|
||||
if g:jedi#force_py_version == 2
|
||||
call jedi#force_py_version(3)
|
||||
elseif g:jedi#force_py_version == 3
|
||||
call jedi#force_py_version(2)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
" ------------------------------------------------------------------------
|
||||
" deprecations
|
||||
" ------------------------------------------------------------------------
|
||||
let s:deprecations = {
|
||||
\ 'get_definition_command': 'goto_definitions_command',
|
||||
\ 'goto_command': 'goto_assignments_command',
|
||||
\ 'pydoc': 'documentation_command',
|
||||
\ 'related_names_command': 'usages_command',
|
||||
\ 'autocompletion_command': 'completions_command',
|
||||
\ 'show_function_definition': 'show_call_signatures',
|
||||
\ }
|
||||
|
||||
" ------------------------------------------------------------------------
|
||||
" defaults for jedi-vim
|
||||
" ------------------------------------------------------------------------
|
||||
let s:settings = {
|
||||
\ 'use_tabs_not_buffers': 1,
|
||||
\ 'use_splits_not_buffers': 1,
|
||||
\ 'auto_initialization': 1,
|
||||
\ 'auto_vim_configuration': 1,
|
||||
\ 'goto_assignments_command': "'<leader>g'",
|
||||
\ 'completions_command': "'<C-Space>'",
|
||||
\ 'goto_definitions_command': "'<leader>d'",
|
||||
\ 'call_signatures_command': "'<leader>n'",
|
||||
\ 'usages_command': "'<leader>n'",
|
||||
\ 'rename_command': "'<leader>r'",
|
||||
\ 'popup_on_dot': 1,
|
||||
\ 'documentation_command': "'K'",
|
||||
\ 'show_call_signatures': 1,
|
||||
\ 'call_signature_escape': "'≡'",
|
||||
\ 'auto_close_doc': 1,
|
||||
\ 'popup_select_first': 1,
|
||||
\ 'quickfix_window_height': 10,
|
||||
\ 'completions_enabled': 1,
|
||||
\ 'force_py_version': 2
|
||||
\ }
|
||||
|
||||
|
||||
function! s:init()
|
||||
for [key, val] in items(s:deprecations)
|
||||
if exists('g:jedi#'.key)
|
||||
echom "'g:jedi#".key."' is deprecated. Please use 'g:jedi#".val."' instead. Sorry for the inconvenience."
|
||||
exe 'let g:jedi#'.val.' = g:jedi#'.key
|
||||
end
|
||||
endfor
|
||||
|
||||
for [key, val] in items(s:settings)
|
||||
if !exists('g:jedi#'.key)
|
||||
exe 'let g:jedi#'.key.' = '.val
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
|
||||
call s:init()
|
||||
|
||||
" ------------------------------------------------------------------------
|
||||
" Python initialization
|
||||
" ------------------------------------------------------------------------
|
||||
|
||||
let s:script_path = fnameescape(expand('<sfile>:p:h:h'))
|
||||
|
||||
if has('python') && has('python3')
|
||||
call jedi#force_py_version(g:jedi#force_py_version)
|
||||
elseif has('python')
|
||||
command! -nargs=1 Python python <args>
|
||||
execute 'pyfile '.s:script_path.'/initialize.py'
|
||||
elseif has('python3')
|
||||
command! -nargs=1 Python python3 <args>
|
||||
execute 'py3file '.s:script_path.'/initialize.py'
|
||||
else
|
||||
if !exists("g:jedi#squelch_py_warning")
|
||||
echomsg "Error: jedi-vim requires vim compiled with +python"
|
||||
endif
|
||||
finish
|
||||
end
|
||||
|
||||
|
||||
"Python jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout, speed=True, warnings=False, notices=False)
|
||||
"Python jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout)
|
||||
"PythonJedi jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout, speed=True, warnings=False, notices=False)
|
||||
"PythonJedi jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout)
|
||||
|
||||
" vim: set et ts=4:
|
||||
|
||||
21
conftest.py
21
conftest.py
@@ -1,10 +1,13 @@
|
||||
import os
|
||||
import subprocess
|
||||
import urllib
|
||||
import zipfile
|
||||
import subprocess
|
||||
|
||||
import pytest
|
||||
|
||||
VSPEC_URL = 'https://github.com/kana/vim-vspec/archive/1.4.1.zip'
|
||||
CACHE_FOLDER = '.cache'
|
||||
VSPEC_FOLDER = os.path.join(CACHE_FOLDER, 'vim-vspec-master')
|
||||
VSPEC_FOLDER = os.path.join(CACHE_FOLDER, 'vim-vspec-1.4.1')
|
||||
VSPEC_RUNNER = os.path.join(VSPEC_FOLDER, 'bin/vspec')
|
||||
TEST_DIR = 'test'
|
||||
|
||||
@@ -14,11 +17,12 @@ class IntegrationTestFile(object):
|
||||
self.path = path
|
||||
|
||||
def run(self):
|
||||
output = subprocess.check_output([VSPEC_RUNNER, '.', VSPEC_FOLDER, self.path])
|
||||
output = subprocess.check_output(
|
||||
[VSPEC_RUNNER, '.', VSPEC_FOLDER, self.path])
|
||||
for line in output.splitlines():
|
||||
if line.startswith('not ok') or line.startswith('Error'):
|
||||
print(output)
|
||||
assert False
|
||||
if line.startswith(b'not ok') or line.startswith(b'Error'):
|
||||
pytest.fail("{} failed:\n{}".format(
|
||||
self.path, output.decode('utf-8')), pytrace=False)
|
||||
|
||||
def __repr__(self):
|
||||
return "<%s: %s>" % (type(self), self.path)
|
||||
@@ -29,8 +33,7 @@ def pytest_configure(config):
|
||||
os.mkdir(CACHE_FOLDER)
|
||||
|
||||
if not os.path.exists(VSPEC_FOLDER):
|
||||
url = 'https://github.com/kana/vim-vspec/archive/master.zip'
|
||||
name, hdrs = urllib.urlretrieve(url)
|
||||
name, hdrs = urllib.urlretrieve(VSPEC_URL)
|
||||
z = zipfile.ZipFile(name)
|
||||
for n in z.namelist():
|
||||
dest = os.path.join(CACHE_FOLDER, n)
|
||||
@@ -42,7 +45,7 @@ def pytest_configure(config):
|
||||
with open(dest, 'w') as f:
|
||||
f.write(data)
|
||||
z.close()
|
||||
os.chmod(VSPEC_RUNNER, 0777)
|
||||
os.chmod(VSPEC_RUNNER, 0o777)
|
||||
|
||||
|
||||
def pytest_generate_tests(metafunc):
|
||||
|
||||
190
doc/jedi-vim.txt
190
doc/jedi-vim.txt
@@ -1,4 +1,4 @@
|
||||
*jedi-vim.txt* - For Vim version 7.3 - Last change: 2013/3/1
|
||||
*jedi-vim.txt* - For Vim version 7.3 - Last change: 2014/07/29
|
||||
__ _______ _______ __ ____ ____ __ .___ ___.~
|
||||
| | | ____|| \ | | \ \ / / | | | \/ |~
|
||||
| | | |__ | .--. || | _____\ \/ / | | | \ / |~
|
||||
@@ -17,16 +17,18 @@ Contents *jedi-vim-contents*
|
||||
2.1. Manually |jedi-vim-installation-manually|
|
||||
2.2. Using Pathogen |jedi-vim-installation-pathogen|
|
||||
2.3. Using Vundle |jedi-vim-installation-vundle|
|
||||
2.4. Installing from Repositories |jedi-vim-installation-repos|
|
||||
3. Supported Python features |jedi-vim-support|
|
||||
4. Usage |jedi-vim-usage|
|
||||
5. Mappings |jedi-vim-keybindings|
|
||||
5.1. Start completion |g:jedi#completions_command|
|
||||
5.2. Go to assignment |g:jedi#goto_assignments_command|
|
||||
5.3. Get original definition |g:jedi#goto_definitions_command|
|
||||
5.4. Show documentation |g:jedi#documentation_command|
|
||||
5.5. Rename variables |g:jedi#rename_command|
|
||||
5.6. Show name usages |g:jedi#usages_command|
|
||||
5.7. Open module by name |:Pyimport|
|
||||
5.2. Go to definition |g:jedi#goto_command|
|
||||
5.3. Go to assignment |g:jedi#goto_assignments_command|
|
||||
5.4 Go to definition (deprecated) |g:jedi#goto_definitions_command|
|
||||
5.5. Show documentation |g:jedi#documentation_command|
|
||||
5.6. Rename variables |g:jedi#rename_command|
|
||||
5.7. Show name usages |g:jedi#usages_command|
|
||||
5.8. Open module by name |:Pyimport|
|
||||
6. Configuration |jedi-vim-configuration|
|
||||
6.1. auto_initialization |g:jedi#auto_initialization|
|
||||
6.2. auto_vim_configuration |g:jedi#auto_vim_configuration|
|
||||
@@ -34,11 +36,14 @@ Contents *jedi-vim-contents*
|
||||
6.4. popup_select_first |g:jedi#popup_select_first|
|
||||
6.5. auto_close_doc |g:jedi#auto_close_doc|
|
||||
6.6. show_call_signatures |g:jedi#show_call_signatures|
|
||||
6.7. use_tabs_not_buffers |g:jedi#use_tabs_not_buffers|
|
||||
6.8. squelch_py_warning |g:jedi#squelch_py_warning|
|
||||
6.9. completions_enable |g:jedi#completions_enable|
|
||||
6.10. use_splits_not_buffers |g:jedi#use_splits_not_buffers|
|
||||
6.11. force_py_version |g:jedi#force_py_version|
|
||||
6.7. show_call_signatures_delay |g:jedi#show_call_signatures_delay|
|
||||
6.8. use_tabs_not_buffers |g:jedi#use_tabs_not_buffers|
|
||||
6.9. squelch_py_warning |g:jedi#squelch_py_warning|
|
||||
6.10. completions_enabled |g:jedi#completions_enabled|
|
||||
6.11. use_splits_not_buffers |g:jedi#use_splits_not_buffers|
|
||||
6.12. force_py_version |g:jedi#force_py_version|
|
||||
6.13. smart_auto_mappings |g:jedi#smart_auto_mappings|
|
||||
6.14. use_tag_stack |g:jedi#use_tag_stack|
|
||||
7. Testing |jedi-vim-testing|
|
||||
8. Contributing |jedi-vim-contributing|
|
||||
9. License |jedi-vim-license|
|
||||
@@ -46,7 +51,7 @@ Contents *jedi-vim-contents*
|
||||
==============================================================================
|
||||
1. Introduction *jedi-vim-introduction*
|
||||
|
||||
Jedi-vim is a is a Vim binding to the awesome Python autocompletion library
|
||||
Jedi-vim is a Vim binding to the awesome Python autocompletion library
|
||||
`jedi`. Among jedi's (and, therefore, jedi-vim's) features are:
|
||||
|
||||
- Completion for a wide array of Python features (see |jedi-vim-support|)
|
||||
@@ -82,9 +87,22 @@ using pip: >
|
||||
However, you can also install it as a git submodule if you don't want to use
|
||||
jedi for anything but this plugin. How to do this is detailed below.
|
||||
|
||||
It is the best if you have VIM >= 7.3. For the older version, you probably
|
||||
cannot see the parameter recommendation list of function after typing open
|
||||
bracket.
|
||||
It is best if you have VIM >= 7.3, compiled with the `+conceal` option. With
|
||||
older versions, you will probably not see the parameter recommendation list
|
||||
for functions after typing the open bracket. Some platforms (including OS X
|
||||
releases) do not ship a VIM with `+conceal`. You can check if your VIM has the
|
||||
feature with >
|
||||
|
||||
:ver
|
||||
|
||||
and look for "`+conceal`" (as opposed to "`-conceal`") or >
|
||||
|
||||
:echo has('conceal')
|
||||
|
||||
which will report 0 (not included) or 1 (included). If your VIM lacks this
|
||||
feature and you would like function parameter completion, you will need to
|
||||
build your own VIM, or use a package for your operating system that has this
|
||||
feature (such as MacVim on OS X, which also contains a console binary).
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
2.1. Installing manually *jedi-vim-installation-manually*
|
||||
@@ -125,14 +143,21 @@ Pathogen simplifies installation considerably.
|
||||
will automatically get the jedi library with the jedi-vim plugin. Add the
|
||||
following to the Bundles section in your .vimrc file: >
|
||||
|
||||
Bundle 'git://github.com/davidhalter/jedi-vim'
|
||||
Plugin 'davidhalter/jedi-vim'
|
||||
|
||||
2. Issue the following command in Vim: >
|
||||
|
||||
:BundleInstall
|
||||
:PluginInstall
|
||||
|
||||
Help tags are generated automatically, so you should be good to go.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
2.4. Installing from Repositories *jedi-vim-installation-repos*
|
||||
|
||||
Some Linux distributions have jedi-vim packages in their official
|
||||
repositories. On Arch Linux, install vim-jedi. On Debian (8+) or Ubuntu
|
||||
(14.04+) install vim-python-jedi.
|
||||
|
||||
==============================================================================
|
||||
3. Supported Python features *jedi-vim-support*
|
||||
|
||||
@@ -212,17 +237,15 @@ Note: If you want to use <Tab> for completion, please install Supertab:
|
||||
https://github.com/ervandew/supertab.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
5.2. `g:jedi#goto_assignments_command` *g:jedi#goto_assignments_command*
|
||||
Function: `jedi#goto_assignments()`
|
||||
Default: <leader>g Go to definition
|
||||
5.2. `g:jedi#goto_command` *g:jedi#goto_command*
|
||||
Function: `jedi#goto()`
|
||||
Default: <leader>d Go to definition (or assignment)
|
||||
|
||||
This function finds the first definition of the function/class under the
|
||||
cursor. It produces an error if the definition is not in a Python file.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
5.3. `g:jedi#goto_definitions_command` *g:jedi#goto_definitions_command*
|
||||
Function: `jedi#goto_definitions()`
|
||||
Default: <leader>d Go to original definition
|
||||
This function first tries |jedi#goto_definitions|, and falls back to
|
||||
|jedi#goto_assignments| for builtin modules. It produces an error if nothing
|
||||
could be found.
|
||||
NOTE: this implementation is subject to change.
|
||||
Ref: https://github.com/davidhalter/jedi/issues/570
|
||||
|
||||
This command tries to find the original definition of the function/class under
|
||||
the cursor. Just like the `jedi#goto_assignments()` function, it does not work
|
||||
@@ -254,15 +277,32 @@ you all the way to the >
|
||||
line in file3.py.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
5.4. `g:jedi#documentation_command` *g:jedi#documentation_command*
|
||||
5.3. `g:jedi#goto_assignments_command` *g:jedi#goto_assignments_command*
|
||||
Function: `jedi#goto_assignments()`
|
||||
Default: <leader>g Go to assignment
|
||||
|
||||
This function finds the first definition of the function/class under the
|
||||
cursor. It produces an error if the definition is not in a Python file.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
5.4. `g:jedi#goto_definitions_command` *g:jedi#goto_definitions_command*
|
||||
Function: `jedi#goto_definitions()`
|
||||
Default: - Go to original definition
|
||||
|
||||
NOTE: Deprecated. Use |g:jedi#goto_command| / |jedi#goto()| instead, which
|
||||
currently uses this internally.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
5.5. `g:jedi#documentation_command` *g:jedi#documentation_command*
|
||||
Function: `jedi#show_documentation()`
|
||||
Default: <K> Show pydoc documentation
|
||||
|
||||
This shows the pydoc documentation for the item currently under the cursor.
|
||||
The documentation is opened in a horizontally split buffer.
|
||||
The documentation is opened in a horizontally split buffer. The height of this
|
||||
buffer is controlled by `g:jedi#max_doc_height` (set by default to 30).
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
5.5. `g:jedi#rename_command` *g:jedi#rename_command*
|
||||
5.6. `g:jedi#rename_command` *g:jedi#rename_command*
|
||||
Function: `jedi#rename()`
|
||||
Default: <leader>r Rename variables
|
||||
|
||||
@@ -273,7 +313,7 @@ with the new one. The number of performed renames is displayed in the command
|
||||
line.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
5.6. `g:jedi#usages_command` *g:jedi#usages_command*
|
||||
5.7. `g:jedi#usages_command` *g:jedi#usages_command*
|
||||
Function: `jedi#usages()`
|
||||
Default: <leader>n Show usages of a name.
|
||||
|
||||
@@ -281,7 +321,7 @@ The quickfix window is populated with a list of all names which point to the
|
||||
definition of the name under the cursor.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
5.7. Open module by name *:Pyimport*
|
||||
5.8. Open module by name *:Pyimport*
|
||||
Function: `jedi#py_import(args)`
|
||||
Default: :Pyimport e.g. `:Pyimport os` shows os.py in VIM.
|
||||
|
||||
@@ -301,7 +341,7 @@ plugin.
|
||||
Upon initialization, jedi-vim performs the following steps:
|
||||
|
||||
1. Set the current buffers 'omnifunc' to its own completion function
|
||||
`jedi#complete`
|
||||
`jedi#completions`
|
||||
2. Create mappings to commands specified in |jedi-vim-keybindings|
|
||||
3. Call `jedi#configure_call_signatures()` if
|
||||
`g:jedi#show_call_signatures` is set
|
||||
@@ -315,9 +355,11 @@ Default: 1 (Perform automatic initialization)
|
||||
------------------------------------------------------------------------------
|
||||
6.2. `g:jedi#auto_vim_configuration` *g:jedi#auto_vim_configuration*
|
||||
|
||||
Jedi-vim sets 'completeopt' to `menuone,longest,preview` by default. It also
|
||||
remaps <Ctrl-C> to <Esc> in insert mode. If you want to keep your own
|
||||
configuration, disable this setting.
|
||||
Jedi-vim sets 'completeopt' to `menuone,longest,preview` by default, if
|
||||
'completeopt' is not changed from Vim's default.
|
||||
It also remaps <Ctrl-C> to <Esc> in insert mode.
|
||||
|
||||
If you want to keep your own configuration, disable this setting.
|
||||
|
||||
Options: 0 or 1
|
||||
Default: 1 (Set 'completeopt' and mapping as described above)
|
||||
@@ -355,7 +397,7 @@ When doing completion, jedi-vim shows the docstring of the currently selected
|
||||
item in a preview window. By default, this window is being closed after
|
||||
insertion of a completion item.
|
||||
|
||||
Set this to 1 to leave the preview window open even after leaving insert mode.
|
||||
Set this to 0 to leave the preview window open even after leaving insert mode.
|
||||
This could be useful if you want to browse longer docstrings.
|
||||
|
||||
Options: 0 or 1
|
||||
@@ -366,11 +408,15 @@ Default: 1 (Automatically close preview window upon leaving insert mode)
|
||||
|
||||
Jedi-vim can display a small window detailing the arguments of the currently
|
||||
completed function and highlighting the currently selected argument. This can
|
||||
be disabled by setting this option to 0.
|
||||
be disabled by setting this option to 0. Setting this option to 2 shows call
|
||||
signatures in the command line instead of a popup window.
|
||||
|
||||
Options: 0 or 1
|
||||
Options: 0, 1, or 2
|
||||
Default: 1 (Show call signatures window)
|
||||
|
||||
Note: 'showmode' must be disabled for command line call signatures to be
|
||||
visible.
|
||||
|
||||
Note: This setting is ignored if |g:jedi#auto_initialization| is set to 0. In
|
||||
that case, if you want to see call signatures, you have to set it up
|
||||
manually by calling a function in your configuration file: >
|
||||
@@ -378,17 +424,27 @@ manually by calling a function in your configuration file: >
|
||||
call jedi#configure_call_signatures()
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
6.7. `g:jedi#use_tabs_not_buffers` *g:jedi#use_tabs_not_buffers*
|
||||
6.7. `g:jedi#show_call_signatures_delay` *g:jedi#show_call_signatures_delay*
|
||||
|
||||
By default, jedi-vim opens a new tab if you use the "go to", "show
|
||||
definition", or "related names" commands. When you set this option to 0, they
|
||||
open in the current buffer instead.
|
||||
The delay to be used with |g:jedi#show_call_signatures|. If it is greater
|
||||
than 0 it will use Vim's |CursorHoldI| event instead of |CursorMovedI|.
|
||||
It will temporarily set Vim's |'updatetime'| option during insert mode.
|
||||
|
||||
Options: 0 or 1
|
||||
Default: 1 (Command output is put in a new tab)
|
||||
Options: delay in milliseconds
|
||||
Default: 500
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
6.8. `g:jedi#squelch_py_warning` *g:jedi#squelch_py_warning*
|
||||
6.8. `g:jedi#use_tabs_not_buffers` *g:jedi#use_tabs_not_buffers*
|
||||
|
||||
You can make jedi-vim open a new tab if you use the "go to", "show
|
||||
definition", or "related names" commands. When you leave this at the default
|
||||
(0), they open in the current buffer instead.
|
||||
|
||||
Options: 0 or 1
|
||||
Default: 0 (Command output is put in a new tab)
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
6.9. `g:jedi#squelch_py_warning` *g:jedi#squelch_py_warning*
|
||||
|
||||
When Vim has not been compiled with +python, jedi-vim shows a warning to that
|
||||
effect and aborts loading itself. Set this to 1 to suppress that warning.
|
||||
@@ -397,7 +453,7 @@ Options: 0 or 1
|
||||
Default: 0 (Warning is shown)
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
6.9. `g:jedi#completions_enable` *g:jedi#completions_enable*
|
||||
6.10. `g:jedi#completions_enabled` *g:jedi#completions_enabled*
|
||||
|
||||
If you don't want Jedi completion, but all the other features, you can disable
|
||||
it in favor of another completion engine (that probably also uses Jedi, like
|
||||
@@ -407,16 +463,21 @@ Options: 0 or 1
|
||||
Default: 1
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
6.10. `g:jedi#use_splits_not_buffers` *g:jedi#use_splits_not_buffers*
|
||||
6.11. `g:jedi#use_splits_not_buffers` *g:jedi#use_splits_not_buffers*
|
||||
|
||||
If you want to open new split for "go to", you could set this option to the
|
||||
direction which you want to open a split with.
|
||||
|
||||
Options: top, left, right or bottom
|
||||
Options: top, left, right, bottom or winwidth
|
||||
Default: "" (not enabled by default)
|
||||
|
||||
Note: with the 'winwidth' option the window is split vertically or horizontally
|
||||
depending on the width of the window relative to 'textwidth'. This essentially
|
||||
means that if the window is big enough it will be split vertically but if it is
|
||||
small a horizontal split happens.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
6.11. `g:jedi#force_py_version` *g:jedi#force_py_version*
|
||||
6.12. `g:jedi#force_py_version` *g:jedi#force_py_version*
|
||||
|
||||
If you have installed both python 2 and python 3, you can force which one jedi
|
||||
should use by setting this variable. It forces the internal Vim command, which
|
||||
@@ -432,7 +493,30 @@ or set directly using this function, which has the same name as the variable:
|
||||
Function: `jedi#force_py_version(py_version)`
|
||||
|
||||
Options: 2 or 3
|
||||
Default: 2
|
||||
Default: "auto" (will use sys.version_info from "python" in your $PATH)
|
||||
------------------------------------------------------------------------------
|
||||
6.13. `g:jedi#smart_auto_mappings` *g:jedi#smart_auto_mappings*
|
||||
|
||||
When you start typing `from module.name<space>` jedi-vim automatically
|
||||
adds the "import" statement and displays the autocomplete popup.
|
||||
|
||||
This option can be disabled in the .vimrc:
|
||||
|
||||
`let g:jedi#smart_auto_mappings = 0`
|
||||
|
||||
Options: 0 or 1
|
||||
Default: 1 (enabled by default)
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
6.14. `g:jedi#use_tag_stack` *g:jedi#use_tag_stack*
|
||||
|
||||
Write results of |jedi#goto| to a temporary file and use the *:tjump* command
|
||||
to enable full |tagstack| functionality. Use of the tag stack allows
|
||||
returning to the usage of a function with CTRL-T after exploring the
|
||||
definition with arbitrary changes to the |jumplist|.
|
||||
|
||||
Options: 0 or 1
|
||||
Default: 1 (enabled by default)
|
||||
|
||||
==============================================================================
|
||||
7. Testing *jedi-vim-testing*
|
||||
@@ -457,4 +541,4 @@ We love Pull Requests! Read the instructions in `CONTRIBUTING.md`.
|
||||
|
||||
Jedi-vim is licensed with the MIT license.
|
||||
|
||||
vim: textwidth=78 tabstop=8 filetype=help:norightleft:
|
||||
vim: textwidth=78 et filetype=help:norightleft:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
if !has('python') && !has('python3')
|
||||
if !jedi#init_python()
|
||||
finish
|
||||
endif
|
||||
" ------------------------------------------------------------------------
|
||||
@@ -7,6 +7,9 @@ endif
|
||||
|
||||
if g:jedi#auto_initialization
|
||||
" goto / get_definition / usages
|
||||
if g:jedi#goto_command != ''
|
||||
execute "nnoremap <buffer> ".g:jedi#goto_command." :call jedi#goto()<CR>"
|
||||
endif
|
||||
if g:jedi#goto_assignments_command != ''
|
||||
execute "nnoremap <buffer> ".g:jedi#goto_assignments_command." :call jedi#goto_assignments()<CR>"
|
||||
endif
|
||||
@@ -19,13 +22,14 @@ if g:jedi#auto_initialization
|
||||
" rename
|
||||
if g:jedi#rename_command != ''
|
||||
execute "nnoremap <buffer> ".g:jedi#rename_command." :call jedi#rename()<CR>"
|
||||
execute "vnoremap <buffer> ".g:jedi#rename_command." :call jedi#rename_visual()<CR>"
|
||||
endif
|
||||
" documentation/pydoc
|
||||
if g:jedi#documentation_command != ''
|
||||
execute "nnoremap <silent> <buffer>".g:jedi#documentation_command." :call jedi#show_documentation()<CR>"
|
||||
endif
|
||||
|
||||
if g:jedi#show_call_signatures == 1 && has('conceal')
|
||||
if g:jedi#show_call_signatures > 0 && has('conceal')
|
||||
call jedi#configure_call_signatures()
|
||||
endif
|
||||
|
||||
@@ -33,15 +37,12 @@ if g:jedi#auto_initialization
|
||||
inoremap <silent> <buffer> . .<C-R>=jedi#complete_string(1)<CR>
|
||||
endif
|
||||
|
||||
if g:jedi#smart_auto_mappings == 1
|
||||
inoremap <silent> <buffer> <space> <C-R>=jedi#smart_auto_mappings()<CR>
|
||||
end
|
||||
|
||||
if g:jedi#auto_close_doc
|
||||
" close preview if its still open after insert
|
||||
autocmd InsertLeave <buffer> if pumvisible() == 0|pclose|endif
|
||||
end
|
||||
end
|
||||
|
||||
if g:jedi#auto_vim_configuration
|
||||
setlocal completeopt=menuone,longest,preview
|
||||
if len(mapcheck('<C-c>', 'i')) == 0
|
||||
inoremap <C-c> <ESC>
|
||||
end
|
||||
end
|
||||
endif
|
||||
endif
|
||||
|
||||
@@ -11,16 +11,12 @@ import os
|
||||
|
||||
# vim.command('echom expand("<sfile>:p:h:h")') # broken, <sfile> inside function
|
||||
# sys.path.insert(0, os.path.join(vim.eval('expand("<sfile>:p:h:h")'), 'jedi'))
|
||||
sys.path.insert(0, os.path.join(vim.eval('s:script_path'), 'jedi'))
|
||||
sys.path.insert(0, os.path.join(vim.eval('expand(s:script_path)'), 'jedi'))
|
||||
|
||||
# to display errors correctly
|
||||
import traceback
|
||||
|
||||
# update the sys path to include the jedi_vim script
|
||||
sys.path.insert(0, vim.eval('s:script_path'))
|
||||
try:
|
||||
import jedi_vim
|
||||
except ImportError:
|
||||
vim.command('echoerr "Please install Jedi if you want to use jedi_vim."')
|
||||
sys.path.insert(0, vim.eval('expand(s:script_path)'))
|
||||
import jedi_vim
|
||||
sys.path.pop(1)
|
||||
|
||||
|
||||
2
jedi
2
jedi
Submodule jedi updated: 78f1ae5e71...995a653122
436
jedi_vim.py
436
jedi_vim.py
@@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
The Python parts of the Jedi library for VIM. It is mostly about communicating
|
||||
with VIM.
|
||||
@@ -6,27 +7,49 @@ with VIM.
|
||||
import traceback # for exception output
|
||||
import re
|
||||
import os
|
||||
import sys
|
||||
from shlex import split as shsplit
|
||||
|
||||
import vim
|
||||
import jedi
|
||||
import jedi.keywords
|
||||
from jedi._compatibility import unicode, is_py3k
|
||||
from contextlib import contextmanager
|
||||
try:
|
||||
from itertools import zip_longest
|
||||
except ImportError:
|
||||
from itertools import izip_longest as zip_longest # Python 2
|
||||
|
||||
|
||||
def catch_and_print_exceptions(func):
|
||||
def wrapper(*args, **kwargs):
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except (Exception, vim.error):
|
||||
print(traceback.format_exc())
|
||||
return None
|
||||
return wrapper
|
||||
is_py3 = sys.version_info[0] >= 3
|
||||
if is_py3:
|
||||
ELLIPSIS = "…"
|
||||
unicode = str
|
||||
else:
|
||||
ELLIPSIS = u"…"
|
||||
|
||||
|
||||
class PythonToVimStr(unicode):
|
||||
""" Vim has a different string implementation of single quotes """
|
||||
__slots__ = []
|
||||
|
||||
def __new__(cls, obj, encoding='UTF-8'):
|
||||
if is_py3 or isinstance(obj, unicode):
|
||||
return unicode.__new__(cls, obj)
|
||||
else:
|
||||
return unicode.__new__(cls, obj, encoding)
|
||||
|
||||
def __repr__(self):
|
||||
# this is totally stupid and makes no sense but vim/python unicode
|
||||
# support is pretty bad. don't ask how I came up with this... It just
|
||||
# works...
|
||||
# It seems to be related to that bug: http://bugs.python.org/issue5876
|
||||
if unicode is str:
|
||||
s = self
|
||||
else:
|
||||
s = self.encode('UTF-8')
|
||||
return '"%s"' % s.replace('\\', '\\\\').replace('"', r'\"')
|
||||
|
||||
|
||||
class VimError(Exception):
|
||||
def __init__(self, message, throwpoint, executing):
|
||||
super(type(self), self).__init__(message)
|
||||
self.message = message
|
||||
self.throwpoint = throwpoint
|
||||
self.executing = executing
|
||||
|
||||
@@ -46,43 +69,76 @@ def _catch_exception(string, is_eval):
|
||||
return result['result']
|
||||
|
||||
|
||||
def vim_eval(string):
|
||||
return _catch_exception(string, 1)
|
||||
|
||||
|
||||
def vim_command(string):
|
||||
_catch_exception(string, 0)
|
||||
|
||||
|
||||
def vim_eval(string):
|
||||
return _catch_exception(string, 1)
|
||||
|
||||
|
||||
def no_jedi_warning(error=None):
|
||||
msg = "Please install Jedi if you want to use jedi-vim."
|
||||
if error:
|
||||
msg = '{} The error was: {}'.format(msg, error)
|
||||
vim.command('echohl WarningMsg'
|
||||
'| echom "Please install Jedi if you want to use jedi-vim."'
|
||||
'| echohl None')
|
||||
|
||||
|
||||
def echo_highlight(msg):
|
||||
vim_command('echohl WarningMsg | echom "%s" | echohl None' % msg)
|
||||
vim_command('echohl WarningMsg | echom "{}" | echohl None'.format(
|
||||
msg.replace('"', '\\"')))
|
||||
|
||||
|
||||
class PythonToVimStr(unicode):
|
||||
""" Vim has a different string implementation of single quotes """
|
||||
__slots__ = []
|
||||
def __new__(cls, obj, encoding='UTF-8'):
|
||||
if is_py3k or isinstance(obj, unicode):
|
||||
return unicode.__new__(cls, obj)
|
||||
import vim
|
||||
try:
|
||||
import jedi
|
||||
except ImportError as e:
|
||||
no_jedi_warning(str(e))
|
||||
jedi = None
|
||||
else:
|
||||
try:
|
||||
version = jedi.__version__
|
||||
except Exception as e: # e.g. AttributeError
|
||||
echo_highlight("Could not load jedi python module: {}".format(e))
|
||||
jedi = None
|
||||
else:
|
||||
return unicode.__new__(cls, obj, encoding)
|
||||
if isinstance(version, str):
|
||||
# the normal use case, now.
|
||||
from jedi import utils
|
||||
version = utils.version_info()
|
||||
if version < (0, 7):
|
||||
echo_highlight('Please update your Jedi version, it is too old.')
|
||||
|
||||
def __repr__(self):
|
||||
# this is totally stupid and makes no sense but vim/python unicode
|
||||
# support is pretty bad. don't ask how I came up with this... It just
|
||||
# works...
|
||||
# It seems to be related to that bug: http://bugs.python.org/issue5876
|
||||
if unicode is str:
|
||||
s = self
|
||||
|
||||
def catch_and_print_exceptions(func):
|
||||
def wrapper(*args, **kwargs):
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except (Exception, vim.error):
|
||||
print(traceback.format_exc())
|
||||
return None
|
||||
return wrapper
|
||||
|
||||
|
||||
def _check_jedi_availability(show_error=False):
|
||||
def func_receiver(func):
|
||||
def wrapper(*args, **kwargs):
|
||||
if jedi is None:
|
||||
if show_error:
|
||||
no_jedi_warning()
|
||||
return
|
||||
else:
|
||||
s = self.encode('UTF-8')
|
||||
return '"%s"' % s.replace('\\', '\\\\').replace('"', r'\"')
|
||||
return func(*args, **kwargs)
|
||||
return wrapper
|
||||
return func_receiver
|
||||
|
||||
|
||||
@catch_and_print_exceptions
|
||||
def get_script(source=None, column=None):
|
||||
jedi.settings.additional_dynamic_modules = [b.name for b in vim.buffers
|
||||
if b.name is not None and b.name.endswith('.py')]
|
||||
jedi.settings.additional_dynamic_modules = \
|
||||
[b.name for b in vim.buffers if b.name is not None and b.name.endswith('.py')]
|
||||
if source is None:
|
||||
source = '\n'.join(vim.current.buffer)
|
||||
row = vim.current.window.cursor[0]
|
||||
@@ -93,9 +149,13 @@ def get_script(source=None, column=None):
|
||||
return jedi.Script(source, row, column, buf_path, encoding)
|
||||
|
||||
|
||||
@_check_jedi_availability(show_error=False)
|
||||
@catch_and_print_exceptions
|
||||
def completions():
|
||||
row, column = vim.current.window.cursor
|
||||
# Clear call signatures in the buffer so they aren't seen by the completer.
|
||||
# Call signatures in the command line can stay.
|
||||
if vim_eval("g:jedi#show_call_signatures") == '1':
|
||||
clear_call_signatures()
|
||||
if vim.eval('a:findstart') == '1':
|
||||
count = 0
|
||||
@@ -127,7 +187,7 @@ def completions():
|
||||
abbr=PythonToVimStr(c.name),
|
||||
# stuff directly behind the completion
|
||||
menu=PythonToVimStr(c.description),
|
||||
info=PythonToVimStr(c.doc), # docstr
|
||||
info=PythonToVimStr(c.docstring()), # docstr
|
||||
icase=1, # case insensitive
|
||||
dup=1 # allow duplicates (maybe later remove this)
|
||||
)
|
||||
@@ -145,25 +205,47 @@ def completions():
|
||||
vim.command('return ' + strout)
|
||||
|
||||
|
||||
@contextmanager
|
||||
def tempfile(content):
|
||||
# Using this instead of the tempfile module because Windows won't read
|
||||
# from a file not yet written to disk
|
||||
with open(vim_eval('tempname()'), 'w') as f:
|
||||
f.write(content)
|
||||
try:
|
||||
yield f
|
||||
finally:
|
||||
os.unlink(f.name)
|
||||
|
||||
@_check_jedi_availability(show_error=True)
|
||||
@catch_and_print_exceptions
|
||||
def goto(is_definition=False, is_related_name=False, no_output=False):
|
||||
definitions = []
|
||||
def goto(mode="goto", no_output=False):
|
||||
"""
|
||||
:param str mode: "related_name", "definition", "assignment", "auto"
|
||||
:return: list of definitions/assignments
|
||||
:rtype: list
|
||||
"""
|
||||
script = get_script()
|
||||
try:
|
||||
if is_related_name:
|
||||
if mode == "goto":
|
||||
definitions = [x for x in script.goto_definitions()
|
||||
if not x.in_builtin_module()]
|
||||
if not definitions:
|
||||
definitions = script.goto_assignments()
|
||||
elif mode == "related_name":
|
||||
definitions = script.usages()
|
||||
elif is_definition:
|
||||
elif mode == "definition":
|
||||
definitions = script.goto_definitions()
|
||||
else:
|
||||
elif mode == "assignment":
|
||||
definitions = script.goto_assignments()
|
||||
except jedi.NotFoundError:
|
||||
echo_highlight( "Cannot follow nothing. Put your cursor on a valid name.")
|
||||
echo_highlight("Cannot follow nothing. Put your cursor on a valid name.")
|
||||
definitions = []
|
||||
else:
|
||||
if no_output:
|
||||
return definitions
|
||||
if not definitions:
|
||||
echo_highlight("Couldn't find any definitions for this.")
|
||||
elif len(definitions) == 1 and not is_related_name:
|
||||
elif len(definitions) == 1 and mode != "related_name":
|
||||
# just add some mark to add the current position to the jumplist.
|
||||
# this is ugly, because it overrides the mark for '`', so if anyone
|
||||
# has a better idea, let me know.
|
||||
@@ -172,34 +254,51 @@ def goto(is_definition=False, is_related_name=False, no_output=False):
|
||||
d = list(definitions)[0]
|
||||
if d.in_builtin_module():
|
||||
if d.is_keyword:
|
||||
echo_highlight(
|
||||
"Cannot get the definition of Python keywords.")
|
||||
echo_highlight("Cannot get the definition of Python keywords.")
|
||||
else:
|
||||
echo_highlight("Builtin modules cannot be displayed (%s)."
|
||||
% d.module_path)
|
||||
% d.desc_with_module)
|
||||
else:
|
||||
using_tagstack = vim_eval('g:jedi#use_tag_stack') == '1'
|
||||
if d.module_path != vim.current.buffer.name:
|
||||
result = new_buffer(d.module_path)
|
||||
result = new_buffer(d.module_path,
|
||||
using_tagstack=using_tagstack)
|
||||
if not result:
|
||||
return
|
||||
return []
|
||||
if d.module_path and using_tagstack:
|
||||
tagname = d.name
|
||||
with tempfile('{0}\t{1}\t{2}'.format(tagname, d.module_path,
|
||||
'call cursor({0}, {1})'.format(d.line, d.column + 1))) as f:
|
||||
old_tags = vim.eval('&tags')
|
||||
old_wildignore = vim.eval('&wildignore')
|
||||
try:
|
||||
# Clear wildignore to ensure tag file isn't ignored
|
||||
vim.command('set wildignore=')
|
||||
vim.command('let &tags = %s' %
|
||||
repr(PythonToVimStr(f.name)))
|
||||
vim.command('tjump %s' % tagname)
|
||||
finally:
|
||||
vim.command('let &tags = %s' %
|
||||
repr(PythonToVimStr(old_tags)))
|
||||
vim.command('let &wildignore = %s' %
|
||||
repr(PythonToVimStr(old_wildignore)))
|
||||
vim.current.window.cursor = d.line, d.column
|
||||
vim_command('normal! zt') # cursor at top of screen
|
||||
else:
|
||||
# multiple solutions
|
||||
lst = []
|
||||
for d in definitions:
|
||||
if d.in_builtin_module():
|
||||
lst.append(dict(text=
|
||||
PythonToVimStr('Builtin ' + d.description)))
|
||||
lst.append(dict(text=PythonToVimStr('Builtin ' + d.description)))
|
||||
else:
|
||||
lst.append(dict(filename=PythonToVimStr(d.module_path),
|
||||
lnum=d.line, col=d.column + 1,
|
||||
text=PythonToVimStr(d.description)))
|
||||
vim_eval('setqflist(%s)' % repr(lst))
|
||||
vim_eval('jedi#add_goto_window()')
|
||||
vim_eval('jedi#add_goto_window(' + str(len(lst)) + ')')
|
||||
return definitions
|
||||
|
||||
|
||||
@_check_jedi_availability(show_error=True)
|
||||
@catch_and_print_exceptions
|
||||
def show_documentation():
|
||||
script = get_script()
|
||||
@@ -217,30 +316,40 @@ def show_documentation():
|
||||
echo_highlight('No documentation found for that.')
|
||||
vim.command('return')
|
||||
else:
|
||||
docs = ['Docstring for %s\n%s\n%s' % (d.desc_with_module, '='*40, d.doc) if d.doc
|
||||
else '|No Docstring for %s|' % d for d in definitions]
|
||||
docs = ['Docstring for %s\n%s\n%s' % (d.desc_with_module, '=' * 40, d.docstring())
|
||||
if d.docstring() else '|No Docstring for %s|' % d for d in definitions]
|
||||
text = ('\n' + '-' * 79 + '\n').join(docs)
|
||||
vim.command('let l:doc = %s' % repr(PythonToVimStr(text)))
|
||||
vim.command('let l:doc_lines = %s' % len(text.split('\n')))
|
||||
return True
|
||||
|
||||
|
||||
@catch_and_print_exceptions
|
||||
def clear_call_signatures():
|
||||
# Check if using command line call signatures
|
||||
if vim_eval("g:jedi#show_call_signatures") == '2':
|
||||
vim_command('echo ""')
|
||||
return
|
||||
cursor = vim.current.window.cursor
|
||||
e = vim_eval('g:jedi#call_signature_escape')
|
||||
regex = r'%sjedi=([0-9]+), ([^%s]*)%s.*%sjedi%s'.replace('%s', e)
|
||||
# We need two turns here to search and replace certain lines:
|
||||
# 1. Search for a line with a call signature and save the appended
|
||||
# characters
|
||||
# 2. Actually replace the line and redo the status quo.
|
||||
py_regex = r'%sjedi=([0-9]+), (.*?)%s.*?%sjedi%s'.replace('%s', e)
|
||||
for i, line in enumerate(vim.current.buffer):
|
||||
match = re.search(r'%s' % regex, line)
|
||||
match = re.search(py_regex, line)
|
||||
if match is not None:
|
||||
vim_regex = r'\v' + regex.replace('=', r'\=') + '.{%s}' % \
|
||||
int(match.group(1))
|
||||
vim_command(r'try | %s,%ss/%s/\2/g | catch | endtry' \
|
||||
% (i + 1, i + 1, vim_regex))
|
||||
vim_eval('histdel("search", -1)')
|
||||
vim_command('let @/ = histget("search", -1)')
|
||||
# Some signs were added to minimize syntax changes due to call
|
||||
# signatures. We have to remove them again. The number of them is
|
||||
# specified in `match.group(1)`.
|
||||
after = line[match.end() + int(match.group(1)):]
|
||||
line = line[:match.start()] + match.group(2) + after
|
||||
vim.current.buffer[i] = line
|
||||
vim.current.window.cursor = cursor
|
||||
|
||||
|
||||
@_check_jedi_availability(show_error=False)
|
||||
@catch_and_print_exceptions
|
||||
def show_call_signatures(signatures=()):
|
||||
if vim_eval("has('conceal') && g:jedi#show_call_signatures") == '0':
|
||||
@@ -253,6 +362,9 @@ def show_call_signatures(signatures=()):
|
||||
if not signatures:
|
||||
return
|
||||
|
||||
if vim_eval("g:jedi#show_call_signatures") == '2':
|
||||
return cmdline_call_signatures(signatures)
|
||||
|
||||
for i, signature in enumerate(signatures):
|
||||
line, column = signature.bracket_start
|
||||
# signatures are listed above each other
|
||||
@@ -266,9 +378,10 @@ def show_call_signatures(signatures=()):
|
||||
# TODO check if completion menu is above or below
|
||||
line = vim_eval("getline(%s)" % line_to_replace)
|
||||
|
||||
params = [p.get_code().replace('\n', '') for p in signature.params]
|
||||
params = [p.description.replace('\n', '') for p in signature.params]
|
||||
try:
|
||||
params[signature.index] = '*%s*' % params[signature.index]
|
||||
# *_*PLACEHOLDER*_* makes something fat. See after/syntax file.
|
||||
params[signature.index] = '*_*%s*_*' % params[signature.index]
|
||||
except (IndexError, TypeError):
|
||||
pass
|
||||
|
||||
@@ -308,58 +421,186 @@ def show_call_signatures(signatures=()):
|
||||
vim_eval('setline(%s, %s)' % (line_to_replace, repr(PythonToVimStr(repl))))
|
||||
|
||||
|
||||
@catch_and_print_exceptions
|
||||
def cmdline_call_signatures(signatures):
|
||||
def get_params(s):
|
||||
return [p.description.replace('\n', '') for p in s.params]
|
||||
|
||||
def escape(string):
|
||||
return string.replace('"', '\\"').replace(r'\n', r'\\n')
|
||||
|
||||
def join():
|
||||
return ', '.join(filter(None, (left, center, right)))
|
||||
|
||||
def too_long():
|
||||
return len(join()) > max_msg_len
|
||||
|
||||
if len(signatures) > 1:
|
||||
params = zip_longest(*map(get_params, signatures), fillvalue='_')
|
||||
params = ['(' + ', '.join(p) + ')' for p in params]
|
||||
else:
|
||||
params = get_params(signatures[0])
|
||||
|
||||
index = next(iter(s.index for s in signatures if s.index is not None), None)
|
||||
|
||||
# Allow 12 characters for showcmd plus 18 for ruler - setting
|
||||
# noruler/noshowcmd here causes incorrect undo history
|
||||
max_msg_len = int(vim_eval('&columns')) - 12
|
||||
if int(vim_eval('&ruler')):
|
||||
max_msg_len -= 18
|
||||
max_msg_len -= len(signatures[0].call_name) + 2 # call name + parentheses
|
||||
|
||||
if max_msg_len < (1 if params else 0):
|
||||
return
|
||||
elif index is None:
|
||||
text = escape(', '.join(params))
|
||||
if params and len(text) > max_msg_len:
|
||||
text = ELLIPSIS
|
||||
elif max_msg_len < len(ELLIPSIS):
|
||||
return
|
||||
else:
|
||||
left = escape(', '.join(params[:index]))
|
||||
center = escape(params[index])
|
||||
right = escape(', '.join(params[index + 1:]))
|
||||
while too_long():
|
||||
if left and left != ELLIPSIS:
|
||||
left = ELLIPSIS
|
||||
continue
|
||||
if right and right != ELLIPSIS:
|
||||
right = ELLIPSIS
|
||||
continue
|
||||
if (left or right) and center != ELLIPSIS:
|
||||
left = right = None
|
||||
center = ELLIPSIS
|
||||
continue
|
||||
if too_long():
|
||||
# Should never reach here
|
||||
return
|
||||
|
||||
max_num_spaces = max_msg_len
|
||||
if index is not None:
|
||||
max_num_spaces -= len(join())
|
||||
_, column = signatures[0].bracket_start
|
||||
spaces = min(int(vim_eval('g:jedi#first_col +'
|
||||
'wincol() - col(".")')) +
|
||||
column - len(signatures[0].call_name),
|
||||
max_num_spaces) * ' '
|
||||
|
||||
if index is not None:
|
||||
vim_command(' echon "%s" | '
|
||||
'echohl Function | echon "%s" | '
|
||||
'echohl None | echon "(" | '
|
||||
'echohl jediFunction | echon "%s" | '
|
||||
'echohl jediFat | echon "%s" | '
|
||||
'echohl jediFunction | echon "%s" | '
|
||||
'echohl None | echon ")"'
|
||||
% (spaces, signatures[0].call_name,
|
||||
left + ', ' if left else '',
|
||||
center, ', ' + right if right else ''))
|
||||
else:
|
||||
vim_command(' echon "%s" | '
|
||||
'echohl Function | echon "%s" | '
|
||||
'echohl None | echon "(%s)"'
|
||||
% (spaces, signatures[0].call_name, text))
|
||||
|
||||
|
||||
@_check_jedi_availability(show_error=True)
|
||||
@catch_and_print_exceptions
|
||||
def rename():
|
||||
if not int(vim.eval('a:0')):
|
||||
_rename_cursor = vim.current.window.cursor
|
||||
|
||||
vim_command('normal A ') # otherwise startinsert doesn't work well
|
||||
vim.current.window.cursor = _rename_cursor
|
||||
|
||||
vim_command('augroup jedi_rename')
|
||||
vim_command('autocmd InsertLeave <buffer> call jedi#rename(1)')
|
||||
vim_command('augroup END')
|
||||
|
||||
vim_command("let s:jedi_replace_orig = expand('<cword>')")
|
||||
vim_command('normal! diw')
|
||||
vim_command(':startinsert')
|
||||
vim_command("let s:jedi_changedtick = b:changedtick")
|
||||
vim_command('startinsert')
|
||||
|
||||
else:
|
||||
window_path = vim.current.buffer.name
|
||||
# reset autocommand
|
||||
# Remove autocommand.
|
||||
vim_command('autocmd! jedi_rename InsertLeave')
|
||||
|
||||
# Get replacement, if there is something on the cursor.
|
||||
# This won't be the case when the user ends insert mode right away,
|
||||
# and `<cword>` would pick up the nearest word instead.
|
||||
if vim_eval('getline(".")[getpos(".")[2]-1]') != ' ':
|
||||
replace = vim_eval("expand('<cword>')")
|
||||
vim_command('normal! u') # undo new word
|
||||
else:
|
||||
replace = None
|
||||
|
||||
cursor = vim.current.window.cursor
|
||||
vim_command('normal! u') # undo the space at the end
|
||||
|
||||
# Undo new word, but only if something was changed, which is not the
|
||||
# case when ending insert mode right away.
|
||||
if vim_eval('b:changedtick != s:jedi_changedtick') == '1':
|
||||
vim_command('normal! u') # Undo new word.
|
||||
vim_command('normal! u') # Undo diw.
|
||||
|
||||
vim.current.window.cursor = cursor
|
||||
|
||||
if replace is None:
|
||||
echo_highlight('No rename possible, if no name is given.')
|
||||
else:
|
||||
temp_rename = goto(is_related_name=True, no_output=True)
|
||||
# sort the whole thing reverse (positions at the end of the line
|
||||
if replace:
|
||||
return do_rename(replace)
|
||||
|
||||
|
||||
def rename_visual():
|
||||
replace = vim.eval('input("Rename to: ")')
|
||||
orig = vim.eval('getline(".")[(getpos("\'<")[2]-1):getpos("\'>")[2]]')
|
||||
do_rename(replace, orig)
|
||||
|
||||
|
||||
def do_rename(replace, orig=None):
|
||||
if not len(replace):
|
||||
echo_highlight('No rename possible without name.')
|
||||
return
|
||||
|
||||
if orig is None:
|
||||
orig = vim_eval('s:jedi_replace_orig')
|
||||
|
||||
# Save original window / tab.
|
||||
saved_tab = int(vim_eval('tabpagenr()'))
|
||||
saved_win = int(vim_eval('winnr()'))
|
||||
|
||||
temp_rename = goto(mode="related_name", no_output=True)
|
||||
# Sort the whole thing reverse (positions at the end of the line
|
||||
# must be first, because they move the stuff before the position).
|
||||
temp_rename = sorted(temp_rename, reverse=True,
|
||||
key=lambda x: (x.module_path, x.start_pos))
|
||||
buffers = set()
|
||||
for r in temp_rename:
|
||||
if r.in_builtin_module():
|
||||
continue
|
||||
|
||||
if vim.current.buffer.name != r.module_path:
|
||||
if os.path.abspath(vim.current.buffer.name) != r.module_path:
|
||||
result = new_buffer(r.module_path)
|
||||
if not result:
|
||||
return
|
||||
echo_highlight("Jedi-vim: failed to create buffer window for {}!".format(r.module_path))
|
||||
continue
|
||||
|
||||
buffers.add(vim.current.buffer.name)
|
||||
|
||||
# Save view.
|
||||
saved_view = vim_eval('string(winsaveview())')
|
||||
|
||||
# Replace original word.
|
||||
vim.current.window.cursor = r.start_pos
|
||||
vim_command('normal! cw%s' % replace)
|
||||
vim_command('normal! c{:d}l{}'.format(len(orig), replace))
|
||||
|
||||
result = new_buffer(window_path)
|
||||
if not result:
|
||||
return
|
||||
vim.current.window.cursor = cursor
|
||||
echo_highlight('Jedi did %s renames!' % len(temp_rename))
|
||||
# Restore view.
|
||||
vim_command('call winrestview(%s)' % saved_view)
|
||||
|
||||
# Restore previous tab and window.
|
||||
vim_command('tabnext {:d}'.format(saved_tab))
|
||||
vim_command('{:d}wincmd w'.format(saved_win))
|
||||
|
||||
if len(buffers) > 1:
|
||||
echo_highlight('Jedi did {:d} renames in {:d} buffers!'.format(
|
||||
len(temp_rename), len(buffers)))
|
||||
else:
|
||||
echo_highlight('Jedi did {:d} renames!'.format(len(temp_rename)))
|
||||
|
||||
|
||||
@_check_jedi_availability(show_error=True)
|
||||
@catch_and_print_exceptions
|
||||
def py_import():
|
||||
# args are the same as for the :edit command
|
||||
@@ -389,13 +630,13 @@ def py_import_completions():
|
||||
comps = []
|
||||
else:
|
||||
text = 'import %s' % argl
|
||||
script=jedi.Script(text, 1, len(text), '')
|
||||
script = jedi.Script(text, 1, len(text), '')
|
||||
comps = ['%s%s' % (argl, c.complete) for c in script.completions()]
|
||||
vim.command("return '%s'" % '\n'.join(comps))
|
||||
|
||||
|
||||
@catch_and_print_exceptions
|
||||
def new_buffer(path, options=''):
|
||||
def new_buffer(path, options='', using_tagstack=False):
|
||||
# options are what you can to edit the edit options
|
||||
if vim_eval('g:jedi#use_tabs_not_buffers') == '1':
|
||||
_tabnew(path, options)
|
||||
@@ -405,12 +646,15 @@ def new_buffer(path, options=''):
|
||||
'top': 'topleft split',
|
||||
'left': 'topleft vsplit',
|
||||
'right': 'botright vsplit',
|
||||
'bottom': 'botright split'
|
||||
'bottom': 'botright split',
|
||||
'winwidth': 'vs'
|
||||
}
|
||||
if user_split_option == 'winwidth' and vim.current.window.width <= 2 * int(vim_eval("&textwidth ? &textwidth : 80")):
|
||||
split_options['winwidth'] = 'sp'
|
||||
if user_split_option not in split_options:
|
||||
print('g:jedi#use_splits_not_buffers value is not correct, valid options are: %s' % ','.join(split_options.keys()))
|
||||
else:
|
||||
vim_command(split_options[user_split_option] + " %s" % path)
|
||||
vim_command(split_options[user_split_option] + " %s" % escape_file_path(path))
|
||||
else:
|
||||
if vim_eval("!&hidden && &modified") == '1':
|
||||
if vim_eval("bufname('%')") is None:
|
||||
@@ -418,6 +662,8 @@ def new_buffer(path, options=''):
|
||||
return False
|
||||
else:
|
||||
vim_command('w')
|
||||
if using_tagstack:
|
||||
return True
|
||||
vim_command('edit %s %s' % (options, escape_file_path(path)))
|
||||
# sometimes syntax is being disabled and the filetype not set.
|
||||
if vim_eval('!exists("g:syntax_on")') == '1':
|
||||
@@ -452,6 +698,8 @@ def _tabnew(path, options=''):
|
||||
if buf_path == path:
|
||||
# tab exists, just switch to that tab
|
||||
vim_command('tabfirst | tabnext %i' % (tab_nr + 1))
|
||||
# Goto the buffer's window.
|
||||
vim_command('exec bufwinnr(%i) . " wincmd w"' % (buf_nr + 1))
|
||||
break
|
||||
else:
|
||||
continue
|
||||
@@ -467,7 +715,3 @@ def escape_file_path(path):
|
||||
|
||||
def print_to_stdout(level, str_out):
|
||||
print(str_out)
|
||||
|
||||
if not hasattr(jedi, '__version__') or jedi.__version__ < (0, 7, 0):
|
||||
echo_highlight('Please update your Jedi version, it is to old.')
|
||||
|
||||
|
||||
@@ -4,16 +4,32 @@
|
||||
" This part of the software is just the vim interface. The really big deal is
|
||||
" the Jedi Python library.
|
||||
|
||||
|
||||
" jedi-vim doesn't work in compatible mode (vim script syntax problems)
|
||||
if &compatible
|
||||
if !exists("g:jedi#auto_vim_configuration") || g:jedi#auto_vim_configuration
|
||||
" jedi-vim doesn't work in compatible mode (vim script syntax problems)
|
||||
if &compatible
|
||||
set nocompatible
|
||||
endif
|
||||
endif
|
||||
|
||||
" jedi-vim really needs, otherwise jedi-vim cannot start.
|
||||
filetype plugin on
|
||||
" jedi-vim really needs, otherwise jedi-vim cannot start.
|
||||
filetype plugin on
|
||||
|
||||
" Change completeopt, but only if it has Vim's default value.
|
||||
let s:save_completeopt=&completeopt
|
||||
set completeopt&
|
||||
let s:default_completeopt=&completeopt
|
||||
let &completeopt=s:save_completeopt
|
||||
if s:default_completeopt == &completeopt
|
||||
set completeopt=menuone,longest,preview
|
||||
endif
|
||||
|
||||
if len(mapcheck('<C-c>', 'i')) == 0
|
||||
inoremap <C-c> <ESC>
|
||||
endif
|
||||
endif
|
||||
|
||||
" Pyimport command
|
||||
command! -nargs=1 -complete=custom,jedi#py_import_completions Pyimport :call jedi#py_import(<q-args>)
|
||||
|
||||
command! -nargs=0 JediDebugInfo call jedi#debug_info()
|
||||
|
||||
" vim: set et ts=4:
|
||||
|
||||
@@ -11,6 +11,17 @@ describe 'completions'
|
||||
bd!
|
||||
end
|
||||
|
||||
it 'smart import'
|
||||
exec "normal ifrom os "
|
||||
Expect getline('.') == 'from os import '
|
||||
end
|
||||
|
||||
it 'no smart import after space'
|
||||
exec "normal! ifrom os "
|
||||
exec "normal a "
|
||||
Expect getline('.') == 'from os '
|
||||
end
|
||||
|
||||
it 'import'
|
||||
" X is the completion command
|
||||
normal oimporX
|
||||
|
||||
@@ -23,7 +23,7 @@ describe 'documentation docstrings'
|
||||
|
||||
it 'no documentation'
|
||||
put = 'x = 2'
|
||||
normal G0K
|
||||
normal o<ESC>GK
|
||||
Expect bufname('%') == ''
|
||||
end
|
||||
end
|
||||
|
||||
107
test/goto.vim
107
test/goto.vim
@@ -48,6 +48,7 @@ end
|
||||
describe 'goto_with_tabs'
|
||||
before
|
||||
set filetype=python
|
||||
let g:jedi#use_tabs_not_buffers = 1
|
||||
end
|
||||
|
||||
after
|
||||
@@ -63,7 +64,7 @@ describe 'goto_with_tabs'
|
||||
Expect col('.') == 8
|
||||
|
||||
silent normal G\d
|
||||
Expect g:current_buffer_is_module('subprocess') == 1
|
||||
Expect CurrentBufferIsModule('subprocess') == 1
|
||||
Expect line('.') == 1
|
||||
Expect col('.') == 1
|
||||
Expect tabpagenr('$') == 2
|
||||
@@ -73,21 +74,24 @@ describe 'goto_with_tabs'
|
||||
end
|
||||
|
||||
it 'multi_definitions'
|
||||
put = ['import tokenize']
|
||||
silent normal G$\d
|
||||
Expect g:current_buffer_is_module('tokenize') == 0
|
||||
Expect g:current_buffer_is_module('token') == 0
|
||||
execute "normal \<CR>"
|
||||
Expect tabpagenr('$') == 2
|
||||
Expect winnr('$') == 1
|
||||
Expect g:current_buffer_is_module('token') == 1
|
||||
" This used to behave differently. Now we don't have any real multi
|
||||
" definitions.
|
||||
|
||||
bd
|
||||
silent normal G$\d
|
||||
execute "normal j\<CR>"
|
||||
Expect tabpagenr('$') == 2
|
||||
Expect winnr('$') == 1
|
||||
Expect g:current_buffer_is_module('tokenize') == 1
|
||||
" put = ['import tokenize']
|
||||
" silent normal G$\d
|
||||
" Expect CurrentBufferIsModule('tokenize') == 1
|
||||
" Expect CurrentBufferIsModule('token') == 0
|
||||
" execute "normal \<CR>"
|
||||
" Expect tabpagenr('$') == 2
|
||||
" Expect winnr('$') == 1
|
||||
" Expect CurrentBufferIsModule('token') == 1
|
||||
|
||||
" bd
|
||||
" silent normal G$\d
|
||||
" execute "normal j\<CR>"
|
||||
" Expect tabpagenr('$') == 2
|
||||
" Expect winnr('$') == 1
|
||||
" Expect CurrentBufferIsModule('tokenize') == 1
|
||||
end
|
||||
end
|
||||
|
||||
@@ -109,12 +113,12 @@ describe 'goto_with_buffers'
|
||||
normal G$
|
||||
call jedi#goto_assignments()
|
||||
python jedi_vim.goto()
|
||||
Expect g:current_buffer_is_module('os') == 0
|
||||
Expect CurrentBufferIsModule('os') == 0
|
||||
" Without hidden, it's not possible to open a new buffer, when the old
|
||||
" one is not saved.
|
||||
set hidden
|
||||
call jedi#goto_assignments()
|
||||
Expect g:current_buffer_is_module('os') == 1
|
||||
Expect CurrentBufferIsModule('os') == 1
|
||||
Expect winnr('$') == 1
|
||||
Expect tabpagenr('$') == 1
|
||||
Expect line('.') == 1
|
||||
@@ -122,22 +126,22 @@ describe 'goto_with_buffers'
|
||||
end
|
||||
|
||||
it 'multi_definitions'
|
||||
set hidden
|
||||
put = ['import tokenize']
|
||||
silent normal G$\d
|
||||
Expect g:current_buffer_is_module('tokenize') == 0
|
||||
Expect g:current_buffer_is_module('token') == 0
|
||||
execute "normal \<CR>"
|
||||
Expect tabpagenr('$') == 1
|
||||
Expect winnr('$') == 1
|
||||
Expect g:current_buffer_is_module('token') == 1
|
||||
" set hidden
|
||||
" put = ['import tokenize']
|
||||
" silent normal G$\d
|
||||
" Expect CurrentBufferIsModule('tokenize') == 0
|
||||
" Expect CurrentBufferIsModule('token') == 0
|
||||
" execute "normal \<CR>"
|
||||
" Expect tabpagenr('$') == 1
|
||||
" Expect winnr('$') == 1
|
||||
" Expect CurrentBufferIsModule('token') == 1
|
||||
|
||||
bd
|
||||
silent normal G$\d
|
||||
execute "normal j\<CR>"
|
||||
Expect tabpagenr('$') == 1
|
||||
Expect winnr('$') == 1
|
||||
Expect g:current_buffer_is_module('tokenize') == 1
|
||||
" bd
|
||||
" silent normal G$\d
|
||||
" execute "normal j\<CR>"
|
||||
" Expect tabpagenr('$') == 1
|
||||
" Expect winnr('$') == 1
|
||||
" Expect CurrentBufferIsModule('tokenize') == 1
|
||||
end
|
||||
end
|
||||
|
||||
@@ -162,7 +166,7 @@ describe 'goto_with_splits'
|
||||
Expect col('.') == 8
|
||||
|
||||
silent normal G\d
|
||||
Expect g:current_buffer_is_module('subprocess') == 1
|
||||
Expect CurrentBufferIsModule('subprocess') == 1
|
||||
Expect line('.') == 1
|
||||
Expect col('.') == 1
|
||||
Expect winnr('$') == 2
|
||||
@@ -173,4 +177,41 @@ describe 'goto_with_splits'
|
||||
end
|
||||
|
||||
|
||||
describe 'goto_wildignore'
|
||||
before
|
||||
set filetype=python
|
||||
set wildignore=*,with\ spaces,*.pyc
|
||||
set hidden
|
||||
let g:jedi#use_tag_stack = 1
|
||||
let g:jedi#use_tabs_not_buffers = 0
|
||||
" Need to use splits for code coverage in new_buffer()
|
||||
let g:jedi#use_splits_not_buffers = 1
|
||||
|
||||
put = ['from subprocess import Popen', 'Popen']
|
||||
Expect CurrentBufferIsModule('subprocess') == 0
|
||||
silent normal G
|
||||
end
|
||||
|
||||
after
|
||||
bd!
|
||||
bd!
|
||||
set wildignore&vim
|
||||
end
|
||||
|
||||
it 'restores_wildignore'
|
||||
let before = &wildignore
|
||||
call jedi#goto()
|
||||
Expect getline('.') =~ 'Popen'
|
||||
Expect &wildignore == before
|
||||
end
|
||||
|
||||
it 'not_using_tagstack'
|
||||
let g:jedi#use_tag_stack = 0
|
||||
call jedi#goto()
|
||||
Expect CurrentBufferIsModule('subprocess') == 1
|
||||
Expect getline('.') =~ 'Popen'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
" vim: et:ts=4:sw=4
|
||||
|
||||
@@ -2,6 +2,10 @@ source plugin/jedi.vim
|
||||
source test/utils.vim
|
||||
|
||||
describe 'pyimport'
|
||||
before
|
||||
let g:jedi#use_tabs_not_buffers = 1
|
||||
end
|
||||
|
||||
after
|
||||
bd!
|
||||
bd!
|
||||
@@ -9,9 +13,9 @@ describe 'pyimport'
|
||||
|
||||
it 'open_tab'
|
||||
Pyimport os
|
||||
Expect g:current_buffer_is_module('os') == 1
|
||||
Expect CurrentBufferIsModule('os') == 1
|
||||
Pyimport subprocess
|
||||
Expect g:current_buffer_is_module('subprocess') == 1
|
||||
Expect CurrentBufferIsModule('subprocess') == 1
|
||||
" the empty tab is sometimes also a tab
|
||||
Expect tabpagenr('$') >= 2
|
||||
end
|
||||
@@ -19,7 +23,7 @@ describe 'pyimport'
|
||||
it 'completion'
|
||||
" don't know how to test this directly
|
||||
"execute "Pyimport subproc\<Tab>"
|
||||
"Expect g:current_buffer_is_module('subprocess') == 1
|
||||
"Expect CurrentBufferIsModule('subprocess') == 1
|
||||
|
||||
Expect jedi#py_import_completions('subproc', 0, 0) == 'subprocess'
|
||||
Expect jedi#py_import_completions('subprocess', 0, 0) == 'subprocess'
|
||||
|
||||
@@ -11,16 +11,40 @@ describe 'signatures'
|
||||
end
|
||||
|
||||
it 'simple'
|
||||
normal ostr(
|
||||
normal oabs(
|
||||
" equals doautocmd CursorMovedI
|
||||
Python jedi_vim.show_call_signatures()
|
||||
|
||||
Expect getline(1) == '≡jedi=0, ≡ (*obj*) ≡jedi≡'
|
||||
Expect getline(1) == '=`=jedi=0, =`= (*_*number*_*) =`=jedi=`='
|
||||
|
||||
doautocmd InsertLeave
|
||||
Expect getline(1) == ''
|
||||
end
|
||||
|
||||
it 'multiple buffers'
|
||||
set hidden
|
||||
new
|
||||
setfiletype python
|
||||
redir => autocmds
|
||||
autocmd jedi_call_signatures * <buffer>
|
||||
redir END
|
||||
Expect autocmds =~# 'jedi_call_signatures'
|
||||
buffer #
|
||||
redir => autocmds
|
||||
autocmd jedi_call_signatures * <buffer>
|
||||
redir END
|
||||
Expect autocmds =~# 'jedi_call_signatures'
|
||||
bd!
|
||||
end
|
||||
|
||||
it 'simple after CursorHoldI with only parenthesis'
|
||||
noautocmd normal o
|
||||
doautocmd CursorHoldI
|
||||
noautocmd normal iabs(
|
||||
doautocmd CursorHoldI
|
||||
Expect getline(1) == '=`=jedi=0, =`= (*_*number*_*) =`=jedi=`='
|
||||
end
|
||||
|
||||
it 'no signature'
|
||||
normal ostr
|
||||
Python jedi_vim.show_call_signatures()
|
||||
@@ -28,12 +52,79 @@ describe 'signatures'
|
||||
end
|
||||
|
||||
it 'signatures disabled'
|
||||
let g:jedi#show_signatures = 0
|
||||
let g:jedi#show_call_signatures = 0
|
||||
|
||||
normal ostr(
|
||||
Python jedi_vim.show_call_signatures()
|
||||
Expect getline(1, '$') == ['', 'str( ']
|
||||
|
||||
let g:jedi#show_signatures = 1
|
||||
let g:jedi#show_call_signatures = 1
|
||||
end
|
||||
|
||||
it 'command line simple'
|
||||
let g:jedi#show_call_signatures = 2
|
||||
call jedi#configure_call_signatures()
|
||||
|
||||
normal oabs(
|
||||
redir => msg
|
||||
Python jedi_vim.show_call_signatures()
|
||||
redir END
|
||||
Expect msg == "\nabs(number)"
|
||||
|
||||
redir => msg
|
||||
doautocmd InsertLeave
|
||||
redir END
|
||||
Expect msg == "\n"
|
||||
|
||||
normal Sdef foo(a, b): pass
|
||||
normal ofoo(a, b, c,
|
||||
redir => msg
|
||||
Python jedi_vim.show_call_signatures()
|
||||
redir END
|
||||
Expect msg == "\nfoo(a, b)"
|
||||
end
|
||||
|
||||
it 'command line truncation'
|
||||
let g:jedi#show_call_signatures = 2
|
||||
call jedi#configure_call_signatures()
|
||||
|
||||
function! Signature()
|
||||
redir => msg
|
||||
Python jedi_vim.show_call_signatures()
|
||||
redir END
|
||||
return msg
|
||||
endfunction
|
||||
|
||||
let funcname = repeat('a', &columns - 30)
|
||||
put = 'def '.funcname.'(arg1, arg2, arg3, a, b, c):'
|
||||
put = ' pass'
|
||||
execute "normal o".funcname."( "
|
||||
Expect Signature() == "\n".funcname."(arg1, …)"
|
||||
|
||||
normal sarg1,
|
||||
Expect Signature() == "\n".funcname."(…, arg2, …)"
|
||||
|
||||
normal sarg2, arg3,
|
||||
Expect Signature() == "\n".funcname."(…, a, b, c)"
|
||||
|
||||
normal sa, b,
|
||||
Expect Signature() == "\n".funcname."(…, c)"
|
||||
|
||||
g/^/d
|
||||
put = 'def '.funcname.'('.repeat('b', 20).', arg2):'
|
||||
put = ' pass'
|
||||
execute "normal o".funcname."( "
|
||||
Expect Signature() == "\n".funcname."(…)"
|
||||
end
|
||||
|
||||
it 'command line no signature'
|
||||
let g:jedi#show_call_signatures = 2
|
||||
call jedi#configure_call_signatures()
|
||||
|
||||
normal ostr
|
||||
redir => msg
|
||||
Python jedi_vim.show_call_signatures()
|
||||
redir END
|
||||
Expect msg == "\n"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
function! g:current_buffer_is_module(module_name)
|
||||
return g:ends_with(bufname('%'), a:module_name.'.py')
|
||||
function! CurrentBufferIsModule(module_name)
|
||||
return EndsWith(bufname('%'), a:module_name.'.py')
|
||||
endfunction
|
||||
|
||||
|
||||
function g:ends_with(string, end)
|
||||
function EndsWith(string, end)
|
||||
let l:should = len(a:string) - strlen(a:end)
|
||||
return l:should == stridx(a:string, a:end, should)
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user