Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

With typeshed coming to Jedi, builtin modules should be displayed #915

Merged
merged 9 commits into from
Jun 22, 2019
8 changes: 5 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ Manual installation
You might want to use `pathogen <https://github.com/tpope/vim-pathogen>`_ or
`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
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:

Expand All @@ -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
-----------------------------------
Expand Down
5 changes: 5 additions & 0 deletions autoload/jedi.vim
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ let s:default_settings = {
\ 'goto_command': "'<leader>d'",
\ 'goto_assignments_command': "'<leader>g'",
\ 'goto_definitions_command': "''",
\ 'goto_stubs_command': "'<leader>s'",
\ 'completions_command': "'<C-Space>'",
\ 'call_signatures_command': "'<leader>n'",
\ 'usages_command': "'<leader>n'",
Expand Down Expand Up @@ -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()
Expand Down
23 changes: 6 additions & 17 deletions doc/jedi-vim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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*
Expand Down
3 changes: 3 additions & 0 deletions ftplugin/python/jedi.vim
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ if g:jedi#auto_initialization
if len(g:jedi#goto_definitions_command)
execute 'nnoremap <buffer> '.g:jedi#goto_definitions_command.' :call jedi#goto_definitions()<CR>'
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)
execute 'nnoremap <buffer> '.g:jedi#usages_command.' :call jedi#usages()<CR>'
endif
Expand Down
5 changes: 5 additions & 0 deletions plugin/jedi.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pythonx/jedi
Submodule jedi updated 178 files
10 changes: 5 additions & 5 deletions pythonx/jedi_vim.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,14 @@ 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.")
elif len(definitions) == 1 and mode != "related_name":
d = list(definitions)[0]
if d.in_builtin_module():
if d.column is None:
if d.is_keyword:
echo_highlight("Cannot get the definition of Python keywords.")
else:
Expand Down Expand Up @@ -372,9 +374,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.column is None:
# Typically a namespace, in the future maybe other things as
# well.
lst.append(dict(text=PythonToVimStr(d.description)))
Expand Down Expand Up @@ -740,7 +740,7 @@ def py_import():
except IndexError:
echo_highlight('Cannot find %s in sys.path!' % import_path)
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)
else:
cmd_args = ' '.join([a.replace(' ', '\\ ') for a in args])
Expand Down
4 changes: 2 additions & 2 deletions test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions test/vspec/goto.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/vspec/signatures.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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, ?!? (*_*object*_*) ?!?jedi?!?'
Expect getline(1) == '?!?jedi=0, ?!? (*_*f: Callable*_*) ?!?jedi?!?'
end

it 'no signature'
Expand All @@ -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(object)"
Expect msg == "\nstaticmethod(f: Callable)"

redir => msg
doautocmd InsertLeave
Expand Down