Merge pull request #915 from davidhalter/typeshed

With typeshed coming to Jedi, builtin modules should be displayed
This commit is contained in:
Dave Halter
2019-06-23 01:13:14 +02:00
committed by GitHub
11 changed files with 39 additions and 35 deletions

View File

@@ -82,9 +82,8 @@ Manual installation
You might want to use `pathogen <https://github.com/tpope/vim-pathogen>`_ or You might want to use `pathogen <https://github.com/tpope/vim-pathogen>`_ or
`Vundle <https://github.com/gmarik/vundle>`_ to install jedi-vim. `Vundle <https://github.com/gmarik/vundle>`_ to install jedi-vim.
The first thing you need after that is an up-to-date version of Jedi. You can The first thing you need after that is an up-to-date version of Jedi. Install
either install it via ``pip install jedi`` or with ``git submodule update --init --recursive`` in your jedi-vim repository.
``git submodule update --init`` in your jedi-vim repository.
Example installation command using Pathogen: Example installation command using Pathogen:
@@ -100,6 +99,9 @@ Add the following line in your `~/.vimrc`
Plugin 'davidhalter/jedi-vim' 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 Installation with your distribution
----------------------------------- -----------------------------------

View File

@@ -19,6 +19,7 @@ let s:default_settings = {
\ 'goto_command': "'<leader>d'", \ 'goto_command': "'<leader>d'",
\ 'goto_assignments_command': "'<leader>g'", \ 'goto_assignments_command': "'<leader>g'",
\ 'goto_definitions_command': "''", \ 'goto_definitions_command': "''",
\ 'goto_stubs_command': "'<leader>s'",
\ 'completions_command': "'<C-Space>'", \ 'completions_command': "'<C-Space>'",
\ 'call_signatures_command': "'<leader>n'", \ 'call_signatures_command': "'<leader>n'",
\ 'usages_command': "'<leader>n'", \ 'usages_command': "'<leader>n'",
@@ -287,6 +288,10 @@ function! jedi#goto_definitions() abort
PythonJedi jedi_vim.goto(mode="definition") PythonJedi jedi_vim.goto(mode="definition")
endfunction endfunction
function! jedi#goto_stubs() abort
PythonJedi jedi_vim.goto(mode="stubs")
endfunction
function! jedi#usages() abort function! jedi#usages() abort
call jedi#remove_usages() call jedi#remove_usages()
PythonJedi jedi_vim.usages() PythonJedi jedi_vim.usages()

View File

@@ -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. 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 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 older versions, you will probably not see the parameter recommendation list
for functions after typing the open bracket. Some platforms (including OS X 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* 2.1. Installing manually *jedi-vim-installation-manually*
1a. Get the latest repository from Github: > 1. If you want to install jedi as a submodule instead, issue this command: >
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: >
git clone --recursive http://github.com/davidhalter/jedi-vim 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* 3. Supported Python features *jedi-vim-support*
The Jedi library does all the hard work behind the scenes. It supports The Jedi library does all the hard work behind the scenes. It understands most
completion of a large number of Python features, among them: Python features, among them:
- Builtins - Builtins
- Multiple `return`s or `yield`s - 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 - Simple/usual `sys.path` modifications
- `isinstance` checks for `if`/`while`/`assert` case, that doesnt work with - `isinstance` checks for `if`/`while`/`assert` case, that doesnt work with
Jedi Jedi
- Stubs
- And more... - And more...
Note: This list is not necessarily up to date. For a complete list of 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* 4. Usage *jedi-vim-usage*

View File

@@ -16,6 +16,9 @@ if g:jedi#auto_initialization
if len(g:jedi#goto_definitions_command) if len(g:jedi#goto_definitions_command)
execute 'nnoremap <buffer> '.g:jedi#goto_definitions_command.' :call jedi#goto_definitions()<CR>' execute 'nnoremap <buffer> '.g:jedi#goto_definitions_command.' :call jedi#goto_definitions()<CR>'
endif endif
if len(g:jedi#goto_stubs_command)
execute 'nnoremap <buffer> '.g:jedi#goto_stubs_command.' :call jedi#goto_stubs()<CR>'
endif
if len(g:jedi#usages_command) if len(g:jedi#usages_command)
execute 'nnoremap <buffer> '.g:jedi#usages_command.' :call jedi#usages()<CR>' execute 'nnoremap <buffer> '.g:jedi#usages_command.' :call jedi#usages()<CR>'
endif endif

View File

@@ -15,6 +15,11 @@ if get(g:, 'jedi#auto_vim_configuration', 1)
" jedi-vim really needs, otherwise jedi-vim cannot start. " jedi-vim really needs, otherwise jedi-vim cannot start.
filetype plugin on 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. " Change completeopt, but only if it was not set already.
" This gets done on VimEnter, since otherwise Vim fails to restore the " This gets done on VimEnter, since otherwise Vim fails to restore the
" screen. Neovim is not affected, this is likely caused by using " screen. Neovim is not affected, this is likely caused by using

View File

@@ -304,12 +304,14 @@ def goto(mode="goto"):
definitions = script.goto_definitions() definitions = script.goto_definitions()
elif mode == "assignment": elif mode == "assignment":
definitions = script.goto_assignments() definitions = script.goto_assignments()
elif mode == "stubs":
definitions = script.goto_assignments(follow_imports=True, only_stubs=True)
if not definitions: if not definitions:
echo_highlight("Couldn't find any definitions for this.") echo_highlight("Couldn't find any definitions for this.")
elif len(definitions) == 1 and mode != "related_name": elif len(definitions) == 1 and mode != "related_name":
d = list(definitions)[0] d = list(definitions)[0]
if d.in_builtin_module(): if d.column is None:
if d.is_keyword: if d.is_keyword:
echo_highlight("Cannot get the definition of Python keywords.") echo_highlight("Cannot get the definition of Python keywords.")
else: else:
@@ -372,9 +374,7 @@ def show_goto_multi_results(definitions):
"""Create a quickfix list for multiple definitions.""" """Create a quickfix list for multiple definitions."""
lst = [] lst = []
for d in definitions: for d in definitions:
if d.in_builtin_module(): if d.column is None:
lst.append(dict(text=PythonToVimStr('Builtin ' + d.description)))
elif d.module_path is None:
# Typically a namespace, in the future maybe other things as # Typically a namespace, in the future maybe other things as
# well. # well.
lst.append(dict(text=PythonToVimStr(d.description))) lst.append(dict(text=PythonToVimStr(d.description)))
@@ -740,7 +740,7 @@ def py_import():
except IndexError: except IndexError:
echo_highlight('Cannot find %s in sys.path!' % import_path) echo_highlight('Cannot find %s in sys.path!' % import_path)
else: else:
if completion.in_builtin_module(): if completion.column is None: # Python modules always have a line number.
echo_highlight('%s is a builtin module.' % import_path) echo_highlight('%s is a builtin module.' % import_path)
else: else:
cmd_args = ' '.join([a.replace(' ', '\\ ') for a in args]) cmd_args = ' '.join([a.replace(' ', '\\ ') for a in args])

View File

@@ -56,10 +56,10 @@ def test_integration(install_vspec, path):
if (line.startswith(b'not ok') or if (line.startswith(b'not ok') or
line.startswith(b'Error') or line.startswith(b'Error') or
line.startswith(b'Bail out!')): 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) path, output.decode('utf-8')), pytrace=False)
if not had_ok and line.startswith(b'ok'): if not had_ok and line.startswith(b'ok'):
had_ok = True had_ok = True
if not had_ok: 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) path, output.decode('utf-8')), pytrace=False)

View File

@@ -2,7 +2,7 @@ let mapleader = '\'
source plugin/jedi.vim source plugin/jedi.vim
source test/_utils.vim source test/_utils.vim
describe 'goto simple' describe 'goto simple:'
before before
new new
set filetype=python set filetype=python
@@ -45,7 +45,7 @@ describe 'goto simple'
end end
describe 'goto with tabs' describe 'goto with tabs:'
before before
set filetype=python set filetype=python
let g:jedi#use_tabs_not_buffers = 1 let g:jedi#use_tabs_not_buffers = 1

View File

@@ -39,9 +39,9 @@ describe 'signatures'
it 'simple after CursorHoldI with only parenthesis' it 'simple after CursorHoldI with only parenthesis'
noautocmd normal o noautocmd normal o
doautocmd CursorHoldI doautocmd CursorHoldI
noautocmd normal istr() noautocmd normal istaticmethod()
doautocmd CursorHoldI doautocmd CursorHoldI
Expect getline(1) == '?!?jedi=0, ?!? (*_*object*_*) ?!?jedi?!?' Expect getline(1) == '?!?jedi=0, ?!? (*_*f: Callable*_*) ?!?jedi?!?'
end end
it 'no signature' it 'no signature'
@@ -64,11 +64,11 @@ describe 'signatures'
let g:jedi#show_call_signatures = 2 let g:jedi#show_call_signatures = 2
call jedi#configure_call_signatures() call jedi#configure_call_signatures()
exe 'normal ostr( ' exe 'normal ostaticmethod( '
redir => msg redir => msg
Python jedi_vim.show_call_signatures() Python jedi_vim.show_call_signatures()
redir END redir END
Expect msg == "\nstr(object)" Expect msg == "\nstaticmethod(f: Callable)"
redir => msg redir => msg
doautocmd InsertLeave doautocmd InsertLeave