From 23c14f68263db51b16247e00885dc931092a770c Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sat, 9 Mar 2019 13:35:54 +0100 Subject: [PATCH 1/9] With typeshed coming to Jedi, builtin modules should be displayed (If there's a module_path (which most will have)). This change is still backwards compatible and can be used with older Jedi versions (<0.14.0). --- pythonx/jedi_vim.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pythonx/jedi_vim.py b/pythonx/jedi_vim.py index 4419b48e..71dbf204 100644 --- a/pythonx/jedi_vim.py +++ b/pythonx/jedi_vim.py @@ -309,7 +309,7 @@ def goto(mode="goto"): echo_highlight("Couldn't find any definitions for this.") elif len(definitions) == 1 and mode != "related_name": d = list(definitions)[0] - if d.in_builtin_module(): + if d.module_path is None: if d.is_keyword: echo_highlight("Cannot get the definition of Python keywords.") else: @@ -372,9 +372,7 @@ def show_goto_multi_results(definitions): """Create a quickfix list for multiple definitions.""" lst = [] for d in definitions: - if d.in_builtin_module(): - lst.append(dict(text=PythonToVimStr('Builtin ' + d.description))) - elif d.module_path is None: + if d.module_path is None: # Typically a namespace, in the future maybe other things as # well. lst.append(dict(text=PythonToVimStr(d.description))) @@ -740,7 +738,7 @@ def py_import(): except IndexError: echo_highlight('Cannot find %s in sys.path!' % import_path) else: - if completion.in_builtin_module(): + if completion.module_path is None: echo_highlight('%s is a builtin module.' % import_path) else: cmd_args = ' '.join([a.replace(' ', '\\ ') for a in args]) From 9c9a513aafcc563f8e9e930a3ea99ed4ad21f31b Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sun, 16 Jun 2019 09:39:50 +0200 Subject: [PATCH 2/9] Add a goto_stubs command --- autoload/jedi.vim | 5 +++++ ftplugin/python/jedi.vim | 3 +++ plugin/jedi.vim | 5 +++++ pythonx/jedi_vim.py | 2 ++ 4 files changed, 15 insertions(+) diff --git a/autoload/jedi.vim b/autoload/jedi.vim index dd6d7cc8..4432d1ab 100644 --- a/autoload/jedi.vim +++ b/autoload/jedi.vim @@ -19,6 +19,7 @@ let s:default_settings = { \ 'goto_command': "'d'", \ 'goto_assignments_command': "'g'", \ 'goto_definitions_command': "''", + \ 'goto_stubs_command': "'s'", \ 'completions_command': "''", \ 'call_signatures_command': "'n'", \ 'usages_command': "'n'", @@ -287,6 +288,10 @@ function! jedi#goto_definitions() abort PythonJedi jedi_vim.goto(mode="definition") endfunction +function! jedi#goto_stubs() abort + PythonJedi jedi_vim.goto(mode="stubs") +endfunction + function! jedi#usages() abort call jedi#remove_usages() PythonJedi jedi_vim.usages() diff --git a/ftplugin/python/jedi.vim b/ftplugin/python/jedi.vim index 0708a5b2..7156844d 100644 --- a/ftplugin/python/jedi.vim +++ b/ftplugin/python/jedi.vim @@ -16,6 +16,9 @@ if g:jedi#auto_initialization if len(g:jedi#goto_definitions_command) execute 'nnoremap '.g:jedi#goto_definitions_command.' :call jedi#goto_definitions()' endif + if len(g:jedi#goto_stubs_command) + execute 'nnoremap '.g:jedi#goto_stubs_command.' :call jedi#goto_stubs()' + endif if len(g:jedi#usages_command) execute 'nnoremap '.g:jedi#usages_command.' :call jedi#usages()' endif diff --git a/plugin/jedi.vim b/plugin/jedi.vim index 9245bba5..2f8e1246 100644 --- a/plugin/jedi.vim +++ b/plugin/jedi.vim @@ -15,6 +15,11 @@ if get(g:, 'jedi#auto_vim_configuration', 1) " jedi-vim really needs, otherwise jedi-vim cannot start. filetype plugin on + augroup jedi_pyi + au! + autocmd BufNewFile,BufRead *.pyi set filetype=python + augroup END + " Change completeopt, but only if it was not set already. " This gets done on VimEnter, since otherwise Vim fails to restore the " screen. Neovim is not affected, this is likely caused by using diff --git a/pythonx/jedi_vim.py b/pythonx/jedi_vim.py index 71dbf204..382d5c90 100644 --- a/pythonx/jedi_vim.py +++ b/pythonx/jedi_vim.py @@ -304,6 +304,8 @@ def goto(mode="goto"): definitions = script.goto_definitions() elif mode == "assignment": definitions = script.goto_assignments() + elif mode == "stubs": + definitions = script.goto_assignments(follow_imports=True, only_stubs=True) if not definitions: echo_highlight("Couldn't find any definitions for this.") From 717446dd71ba7286b5f2f0e3a05966201dfb879e Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Mon, 17 Jun 2019 20:52:31 +0200 Subject: [PATCH 3/9] For whatever reason tabs were used as indentation --- plugin/jedi.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin/jedi.vim b/plugin/jedi.vim index 2f8e1246..f8fe4b21 100644 --- a/plugin/jedi.vim +++ b/plugin/jedi.vim @@ -15,10 +15,10 @@ if get(g:, 'jedi#auto_vim_configuration', 1) " jedi-vim really needs, otherwise jedi-vim cannot start. filetype plugin on - augroup jedi_pyi - au! - autocmd BufNewFile,BufRead *.pyi set filetype=python - augroup END + augroup jedi_pyi + au! + autocmd BufNewFile,BufRead *.pyi set filetype=python + augroup END " Change completeopt, but only if it was not set already. " This gets done on VimEnter, since otherwise Vim fails to restore the From d32962f3b2e314688c629a692a126186cd684c49 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Thu, 20 Jun 2019 22:38:57 +0200 Subject: [PATCH 4/9] Upgrade Jedi to 0.14.0 and parso to 0.5.0 --- pythonx/jedi | 2 +- pythonx/parso | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pythonx/jedi b/pythonx/jedi index 0bf8a690..454447d4 160000 --- a/pythonx/jedi +++ b/pythonx/jedi @@ -1 +1 @@ -Subproject commit 0bf8a69024aff8599bd1f323c4feba2703ef3d59 +Subproject commit 454447d422c9d832db03dff118bafc21174ecb55 diff --git a/pythonx/parso b/pythonx/parso index acccb4f2..59df3fab 160000 --- a/pythonx/parso +++ b/pythonx/parso @@ -1 +1 @@ -Subproject commit acccb4f28d6d57f4ad4c882f3408136ee8f50ff5 +Subproject commit 59df3fab4358d5889556c2450c2d1deb36facdb7 From 636ad08d32075548c33f520f52dce1db8f7753fc Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Thu, 20 Jun 2019 23:15:07 +0200 Subject: [PATCH 5/9] Get rid of documentation about pip install jedi pip install jedi doesn't work with properly with virtualenvs, if jedi-vim is used. --- README.rst | 8 +++++--- doc/jedi-vim.txt | 23 ++++++----------------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/README.rst b/README.rst index ec8188d6..bb16b4aa 100644 --- a/README.rst +++ b/README.rst @@ -82,9 +82,8 @@ Manual installation You might want to use `pathogen `_ or `Vundle `_ to install jedi-vim. -The first thing you need after that is an up-to-date version of Jedi. You can -either install it via ``pip install jedi`` or with -``git submodule update --init`` in your jedi-vim repository. +The first thing you need after that is an up-to-date version of Jedi. Install +``git submodule update --init --recursive`` in your jedi-vim repository. Example installation command using Pathogen: @@ -100,6 +99,9 @@ Add the following line in your `~/.vimrc` Plugin 'davidhalter/jedi-vim' +For installing Jedi, ``pip install jedi`` will also work, but you might run +into issues when working in virtual environments. Please use git submodules. + Installation with your distribution ----------------------------------- diff --git a/doc/jedi-vim.txt b/doc/jedi-vim.txt index 9c5d83a0..d13d86f5 100644 --- a/doc/jedi-vim.txt +++ b/doc/jedi-vim.txt @@ -78,15 +78,6 @@ By leveraging this library, jedi-vim adds the following capabilities to Vim: First of all, jedi-vim requires Vim to be compiled with the `+python` option. -The jedi library has to be installed for jedi-vim to work properly. You can -install it first, by using e.g. your distribution's package manager, or by -using pip: > - - pip install jedi - -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 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 @@ -107,11 +98,7 @@ feature (such as MacVim on OS X, which also contains a console binary). ------------------------------------------------------------------------------ 2.1. Installing manually *jedi-vim-installation-manually* -1a. Get the latest repository from Github: > - - git clone http://github.com/davidhalter/jedi-vim path/to/bundles/jedi-vim - -1b. If you want to install jedi as a submodule instead, issue this command: > +1. If you want to install jedi as a submodule instead, issue this command: > git clone --recursive http://github.com/davidhalter/jedi-vim @@ -161,8 +148,8 @@ repositories. On Arch Linux, install vim-jedi. On Debian (8+) or Ubuntu ============================================================================== 3. Supported Python features *jedi-vim-support* -The Jedi library does all the hard work behind the scenes. It supports -completion of a large number of Python features, among them: +The Jedi library does all the hard work behind the scenes. It understands most +Python features, among them: - Builtins - Multiple `return`s or `yield`s @@ -185,10 +172,12 @@ completion of a large number of Python features, among them: - Simple/usual `sys.path` modifications - `isinstance` checks for `if`/`while`/`assert` case, that doesn’t work with Jedi +- Stubs - And more... Note: This list is not necessarily up to date. For a complete list of -features, please refer to the Jedi documentation at http://jedi.jedidjah.ch. +features, please refer to the Jedi documentation at +http://jedi.readthedocs.io. ============================================================================== 4. Usage *jedi-vim-usage* From 1a053d2a23cca2b25e04442308d5357e8f7d1351 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Thu, 20 Jun 2019 23:37:43 +0200 Subject: [PATCH 6/9] Fix some call signature tests --- test/vspec/goto.vim | 4 ++-- test/vspec/signatures.vim | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/vspec/goto.vim b/test/vspec/goto.vim index e5c14b54..002f7939 100644 --- a/test/vspec/goto.vim +++ b/test/vspec/goto.vim @@ -2,7 +2,7 @@ let mapleader = '\' source plugin/jedi.vim source test/_utils.vim -describe 'goto simple' +describe 'goto simple:' before new set filetype=python @@ -45,7 +45,7 @@ describe 'goto simple' end -describe 'goto with tabs' +describe 'goto with tabs:' before set filetype=python let g:jedi#use_tabs_not_buffers = 1 diff --git a/test/vspec/signatures.vim b/test/vspec/signatures.vim index 06533f27..db98208b 100644 --- a/test/vspec/signatures.vim +++ b/test/vspec/signatures.vim @@ -41,7 +41,7 @@ describe 'signatures' doautocmd CursorHoldI noautocmd normal istr() doautocmd CursorHoldI - Expect getline(1) == '?!?jedi=0, ?!? (*_*object*_*) ?!?jedi?!?' + Expect getline(1) == '?!?jedi=0, ?!? (*_*o: bytes*_*, encoding: str = ..., errors: str = ...) ?!?jedi?!?' end it 'no signature' @@ -68,7 +68,7 @@ describe 'signatures' redir => msg Python jedi_vim.show_call_signatures() redir END - Expect msg == "\nstr(object)" + Expect msg == "\nstr((o: bytes, o: object = ...), …)" redir => msg doautocmd InsertLeave From 73289427ba6cef74090678b1e365cb0399bfd4fa Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Thu, 20 Jun 2019 23:46:34 +0200 Subject: [PATCH 7/9] Modules should be accessible if column is not None --- pythonx/jedi_vim.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pythonx/jedi_vim.py b/pythonx/jedi_vim.py index 382d5c90..c759d335 100644 --- a/pythonx/jedi_vim.py +++ b/pythonx/jedi_vim.py @@ -311,7 +311,7 @@ def goto(mode="goto"): echo_highlight("Couldn't find any definitions for this.") elif len(definitions) == 1 and mode != "related_name": d = list(definitions)[0] - if d.module_path is None: + if d.column is None: if d.is_keyword: echo_highlight("Cannot get the definition of Python keywords.") else: @@ -374,7 +374,7 @@ def show_goto_multi_results(definitions): """Create a quickfix list for multiple definitions.""" lst = [] for d in definitions: - if d.module_path is None: + if d.column is None: # Typically a namespace, in the future maybe other things as # well. lst.append(dict(text=PythonToVimStr(d.description))) @@ -740,7 +740,7 @@ def py_import(): except IndexError: echo_highlight('Cannot find %s in sys.path!' % import_path) else: - if completion.module_path is None: + if completion.column is None: # Python modules always have a line number. echo_highlight('%s is a builtin module.' % import_path) else: cmd_args = ' '.join([a.replace(' ', '\\ ') for a in args]) From 6c6b4dcf920b451bda6df53fbc294b3073786da4 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Thu, 20 Jun 2019 23:56:46 +0200 Subject: [PATCH 8/9] Make sure that formatting happens on unicode --- test/test_integration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_integration.py b/test/test_integration.py index ae39307d..8d53c515 100644 --- a/test/test_integration.py +++ b/test/test_integration.py @@ -56,10 +56,10 @@ def test_integration(install_vspec, path): if (line.startswith(b'not ok') or line.startswith(b'Error') or line.startswith(b'Bail out!')): - pytest.fail("{0} failed:\n{1}".format( + pytest.fail(u"{0} failed:\n{1}".format( path, output.decode('utf-8')), pytrace=False) if not had_ok and line.startswith(b'ok'): had_ok = True if not had_ok: - pytest.fail("{0} failed: no 'ok' found:\n{1}".format( + pytest.fail(u"{0} failed: no 'ok' found:\n{1}".format( path, output.decode('utf-8')), pytrace=False) From e736eea9346514284878c03d2878e0b7c233ae35 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 21 Jun 2019 00:28:18 +0200 Subject: [PATCH 9/9] Use staticmethod for call signature tests instead of str str has different signatures for Python 2 and 3 and is therefore annoying to test. --- test/vspec/signatures.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/vspec/signatures.vim b/test/vspec/signatures.vim index db98208b..ca4248eb 100644 --- a/test/vspec/signatures.vim +++ b/test/vspec/signatures.vim @@ -39,9 +39,9 @@ describe 'signatures' it 'simple after CursorHoldI with only parenthesis' noautocmd normal o doautocmd CursorHoldI - noautocmd normal istr() + noautocmd normal istaticmethod() doautocmd CursorHoldI - Expect getline(1) == '?!?jedi=0, ?!? (*_*o: bytes*_*, encoding: str = ..., errors: str = ...) ?!?jedi?!?' + Expect getline(1) == '?!?jedi=0, ?!? (*_*f: Callable*_*) ?!?jedi?!?' end it 'no signature' @@ -64,11 +64,11 @@ describe 'signatures' let g:jedi#show_call_signatures = 2 call jedi#configure_call_signatures() - exe 'normal ostr( ' + exe 'normal ostaticmethod( ' redir => msg Python jedi_vim.show_call_signatures() redir END - Expect msg == "\nstr((o: bytes, o: object = ...), …)" + Expect msg == "\nstaticmethod(f: Callable)" redir => msg doautocmd InsertLeave