mirror of
https://github.com/davidhalter/jedi-vim.git
synced 2025-12-06 18:54:44 +08:00
Compare commits
62 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a1c900a26 | ||
|
|
57757bd334 | ||
|
|
ea52ca5305 | ||
|
|
04ba9a2430 | ||
|
|
dc0fdc55cb | ||
|
|
a76965238a | ||
|
|
6193c9fd95 | ||
|
|
acbb712906 | ||
|
|
48b3e5c0e7 | ||
|
|
74fd73d017 | ||
|
|
6efd966481 | ||
|
|
862fbbc8a9 | ||
|
|
87abaf0781 | ||
|
|
01e6e6bcf7 | ||
|
|
2c157e323e | ||
|
|
6edda9063a | ||
|
|
e23687462b | ||
|
|
104d817f0c | ||
|
|
2949389be4 | ||
|
|
c4fc2cde8c | ||
|
|
5858a999de | ||
|
|
1e9bdc863a | ||
|
|
3a27747773 | ||
|
|
4ca918e830 | ||
|
|
a17b033303 | ||
|
|
a0207fadf9 | ||
|
|
e83112f9aa | ||
|
|
b2e8c65e35 | ||
|
|
686f39ac00 | ||
|
|
055199f2aa | ||
|
|
8d24b83754 | ||
|
|
a3696bee36 | ||
|
|
5d4658f989 | ||
|
|
18b1a519b0 | ||
|
|
acb98fc706 | ||
|
|
e99cfd32de | ||
|
|
41ecaa5c15 | ||
|
|
5dd5631027 | ||
|
|
b689409a2a | ||
|
|
ea4de13344 | ||
|
|
1f7bc2a0fb | ||
|
|
c9bdefca54 | ||
|
|
e8790b1d8f | ||
|
|
e2abec21c5 | ||
|
|
c0ded0baf2 | ||
|
|
7dfc56992a | ||
|
|
2572136fcb | ||
|
|
55120b28e4 | ||
|
|
d57edde2e8 | ||
|
|
fab26f4551 | ||
|
|
4dcc6437e3 | ||
|
|
c80a08d983 | ||
|
|
ac6b2f1e3e | ||
|
|
12e97c7a04 | ||
|
|
08f13af066 | ||
|
|
5880f2de93 | ||
|
|
b4b2f3ef54 | ||
|
|
50abb5e95a | ||
|
|
89c995e7d9 | ||
|
|
4f2499e4f2 | ||
|
|
7665d73eae | ||
|
|
b3d715c5fc |
1
.github/FUNDING.yml
vendored
Normal file
1
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1 @@
|
||||
github: [davidhalter]
|
||||
63
.github/workflows/ci.yml
vendored
Normal file
63
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
name: ci
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
tests:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- name: Setup
|
||||
run: |
|
||||
sudo pip install pytest
|
||||
vim --version
|
||||
|
||||
#- name: Setup tmate session
|
||||
# uses: mxschmitt/action-tmate@v3
|
||||
|
||||
- name: Run tests
|
||||
run: 'make test'
|
||||
|
||||
code-quality:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- name: Run tests
|
||||
run: |
|
||||
vim --version
|
||||
make check
|
||||
|
||||
coverage:
|
||||
runs-on: ubuntu-20.04
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo add-apt-repository ppa:neovim-ppa/stable -y
|
||||
sudo apt-get update -q
|
||||
sudo apt-get install neovim -y
|
||||
|
||||
sudo pip install pynvim pytest-cov
|
||||
sudo pip list
|
||||
nvim --version
|
||||
|
||||
- name: Run tests
|
||||
run: |
|
||||
make --keep-going test_coverage BUILD_VIRTUAL_ENV=$VIRTUAL_ENV
|
||||
|
||||
- name: Upload coverage data
|
||||
run: |
|
||||
coverage xml
|
||||
bash <(curl -s https://codecov.io/bash) -X fix -f coverage.xml -F py${TRAVIS_PYTHON_VERSION//./}
|
||||
15
.travis.yml
15
.travis.yml
@@ -1,15 +1,10 @@
|
||||
dist: xenial
|
||||
dist: bionic
|
||||
language: python
|
||||
python: 3.7
|
||||
python: 3.8
|
||||
env:
|
||||
matrix:
|
||||
- ENV=test
|
||||
- ENV=check
|
||||
- ENV=test_coverage
|
||||
matrix:
|
||||
include:
|
||||
- env: ENV=test_coverage
|
||||
python: 2.7
|
||||
install:
|
||||
- |
|
||||
if [ "$ENV" = "test" ]; then
|
||||
@@ -20,15 +15,17 @@ install:
|
||||
sudo apt-get install neovim -y
|
||||
|
||||
pip install pynvim pytest-cov
|
||||
pip list
|
||||
nvim --version
|
||||
else
|
||||
vim --version
|
||||
fi
|
||||
script:
|
||||
- make --keep-going "$ENV" BUILD_VIRTUAL_ENV=$VIRTUAL_ENV
|
||||
|
||||
after_success:
|
||||
after_script:
|
||||
- |
|
||||
if [ "$ENV" = "test_coverage" ]; then
|
||||
coverage xml
|
||||
bash <(curl -s https://codecov.io/bash) -X gcov -X coveragepy -X fix -X search -X xcode -f coverage.xml -F py${TRAVIS_PYTHON_VERSION//./}
|
||||
travis_retry bash <(curl -s https://codecov.io/bash) -X fix -f coverage.xml -F py${TRAVIS_PYTHON_VERSION//./}
|
||||
fi
|
||||
|
||||
4
Makefile
4
Makefile
@@ -16,10 +16,10 @@ $(BUILD_VIRTUAL_ENV): | $(dir $(BUILD_VIRTUAL_ENV))
|
||||
python -m venv $@
|
||||
|
||||
$(BUILD_VIRTUAL_ENV)/bin/vint: | $(BUILD_VIRTUAL_ENV)
|
||||
$|/bin/python -m pip install vim-vint==0.3.19
|
||||
$|/bin/python -m pip install vim-vint==0.3.21
|
||||
|
||||
$(BUILD_VIRTUAL_ENV)/bin/flake8: | $(BUILD_VIRTUAL_ENV)
|
||||
$|/bin/python -m pip install -q flake8==3.5.0
|
||||
$|/bin/python -m pip install -q flake8==3.7.8
|
||||
|
||||
vint: $(BUILD_VIRTUAL_ENV)/bin/vint
|
||||
$(BUILD_VIRTUAL_ENV)/bin/vint after autoload ftplugin plugin
|
||||
|
||||
17
README.rst
17
README.rst
@@ -58,9 +58,10 @@ generators, there is broad support.
|
||||
Apart from that, jedi-vim supports the following commands
|
||||
|
||||
- Completion ``<C-Space>``
|
||||
- Goto assignments ``<leader>g`` (typical goto function)
|
||||
- Goto definitions ``<leader>d`` (follow identifier as far as possible,
|
||||
- Goto assignment ``<leader>g`` (typical goto function)
|
||||
- Goto definition ``<leader>d`` (follow identifier as far as possible,
|
||||
includes imports and statements)
|
||||
- Goto (typing) stub ``<leader>s``
|
||||
- Show Documentation/Pydoc ``K`` (shows a popup with assignments)
|
||||
- Renaming ``<leader>r``
|
||||
- Usages ``<leader>n`` (shows all the usages of a name)
|
||||
@@ -181,8 +182,10 @@ and usually saves one keypress.
|
||||
|
||||
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
|
||||
buffer (set to 1 by default (with the conceal feature), 2 otherwise),
|
||||
which has the advantage of being easier to refer to (but is a hack with
|
||||
many drawbacks since it changes the buffer's contents),
|
||||
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
|
||||
@@ -198,12 +201,18 @@ get more information. If you set them to ``""``, they are not assigned.
|
||||
|
||||
let g:jedi#goto_command = "<leader>d"
|
||||
let g:jedi#goto_assignments_command = "<leader>g"
|
||||
let g:jedi#goto_stubs_command = "<leader>s"
|
||||
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"
|
||||
|
||||
A few examples of setting up your project:
|
||||
|
||||
.. code-block:: vim
|
||||
|
||||
let g:jedi#environment_path = "<leader>d"
|
||||
|
||||
Finally, if you don't want completion, but all the other features, use:
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ let s:default_settings = {
|
||||
\ 'completions_enabled': 1,
|
||||
\ 'popup_on_dot': 'g:jedi#completions_enabled',
|
||||
\ 'documentation_command': "'K'",
|
||||
\ 'show_call_signatures': 1,
|
||||
\ 'show_call_signatures': has('conceal') ? 1 : 2,
|
||||
\ 'show_call_signatures_delay': 500,
|
||||
\ 'call_signature_escape': "'?!?'",
|
||||
\ 'auto_close_doc': 1,
|
||||
@@ -35,6 +35,8 @@ let s:default_settings = {
|
||||
\ 'popup_select_first': 1,
|
||||
\ 'quickfix_window_height': 10,
|
||||
\ 'force_py_version': "'auto'",
|
||||
\ 'environment_path': "'auto'",
|
||||
\ 'project_path': "'auto'",
|
||||
\ 'smart_auto_mappings': 0,
|
||||
\ 'use_tag_stack': 1
|
||||
\ }
|
||||
@@ -52,41 +54,21 @@ for [s:key, s:val] in items(s:default_settings)
|
||||
endif
|
||||
endfor
|
||||
|
||||
let s:supports_buffer_usages = has('nvim') || exists('*prop_add')
|
||||
|
||||
|
||||
" ------------------------------------------------------------------------
|
||||
" Python initialization
|
||||
" ------------------------------------------------------------------------
|
||||
let s:script_path = fnameescape(expand('<sfile>:p:h:h'))
|
||||
let s:script_path = expand('<sfile>:p:h:h')
|
||||
|
||||
" Initialize Python (PythonJedi command).
|
||||
function! s:init_python() abort
|
||||
" Use g:jedi#force_py_version for loading Jedi, or fall back to using
|
||||
" `has()` - preferring Python 3.
|
||||
let loader_version = get(g:, 'jedi#loader_py_version', g:jedi#force_py_version)
|
||||
if loader_version ==# 'auto'
|
||||
if has('python3')
|
||||
let loader_version = 3
|
||||
elseif has('python')
|
||||
let loader_version = 2
|
||||
else
|
||||
throw 'jedi-vim requires Vim with support for Python 2 or 3.'
|
||||
if !has('python3')
|
||||
throw 'jedi-vim requires Vim with support for Python 3.'
|
||||
endif
|
||||
else
|
||||
if loader_version =~# '^3'
|
||||
let loader_version = 3
|
||||
elseif loader_version =~# '^2'
|
||||
let loader_version = 2
|
||||
else
|
||||
if !exists('g:jedi#squelch_py_warning')
|
||||
echohl WarningMsg
|
||||
echom printf("jedi-vim: could not determine Python loader version from 'g:jedi#loader_py_version/g:jedi#force_py_version' (%s), using 3.",
|
||||
\ loader_version)
|
||||
echohl None
|
||||
endif
|
||||
let loader_version = 3
|
||||
endif
|
||||
endif
|
||||
call jedi#setup_python_imports(loader_version)
|
||||
call jedi#setup_python_imports()
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
@@ -141,33 +123,25 @@ function! jedi#init_python() abort
|
||||
endfunction
|
||||
|
||||
|
||||
let s:python_version = 'null'
|
||||
function! jedi#setup_python_imports(py_version) abort
|
||||
if a:py_version == 2
|
||||
let cmd_exec = 'python'
|
||||
let s:python_version = 2
|
||||
elseif a:py_version == 3
|
||||
let cmd_exec = 'python3'
|
||||
let s:python_version = 3
|
||||
else
|
||||
throw 'jedi#setup_python_imports: invalid py_version: '.a:py_version
|
||||
endif
|
||||
|
||||
execute 'command! -nargs=1 PythonJedi '.cmd_exec.' <args>'
|
||||
|
||||
function! jedi#setup_python_imports() abort
|
||||
let g:_jedi_init_error = 0
|
||||
let init_lines = [
|
||||
\ 'import vim',
|
||||
\ 'def _jedi_handle_exc(exc_info):',
|
||||
\ ' try:',
|
||||
\ ' from jedi_vim_debug import format_exc_info',
|
||||
\ ' vim.vars["_jedi_init_error"] = format_exc_info(exc_info)',
|
||||
\ ' except Exception:',
|
||||
\ ' import traceback',
|
||||
\ ' vim.vars["_jedi_init_error"] = "\\n".join(traceback.format_exception(*exc_info))',
|
||||
\ 'try:',
|
||||
\ ' import jedi_vim',
|
||||
\ ' if hasattr(jedi_vim, "jedi_import_error"):',
|
||||
\ ' from jedi_vim_debug import format_exc_info',
|
||||
\ ' vim.vars["_jedi_init_error"] = format_exc_info(jedi_vim.jedi_import_error)',
|
||||
\ ' _jedi_handle_exc(jedi_vim.jedi_import_error)',
|
||||
\ 'except Exception as exc:',
|
||||
\ ' from jedi_vim_debug import format_exc_info',
|
||||
\ ' vim.vars["_jedi_init_error"] = format_exc_info()',
|
||||
\ ' _jedi_handle_exc(sys.exc_info())',
|
||||
\ ]
|
||||
exe 'PythonJedi exec('''.escape(join(init_lines, '\n'), "'").''')'
|
||||
exe 'python3 exec('''.escape(join(init_lines, '\n'), "'").''')'
|
||||
if g:_jedi_init_error isnot 0
|
||||
throw printf('jedi#setup_python_imports: %s', g:_jedi_init_error)
|
||||
endif
|
||||
@@ -181,33 +155,43 @@ function! jedi#debug_info() abort
|
||||
echohl WarningMsg | echo 'You should run this in a buffer with filetype "python".' | echohl None
|
||||
endif
|
||||
endif
|
||||
let spath = shellescape(s:script_path)
|
||||
echo '#### Jedi-vim debug information'
|
||||
echo "\n"
|
||||
echo '##### jedi-vim version'
|
||||
echo "\n"
|
||||
echo ' - jedi-vim git version: '
|
||||
echon substitute(system('git -C '.s:script_path.' describe --tags --always --dirty'), '\v\n$', '', '')
|
||||
echon substitute(system('git -C '.spath.' describe --tags --always --dirty'), '\v\n$', '', '')
|
||||
echo ' - jedi git submodule status: '
|
||||
echon substitute(system('git -C '.s:script_path.' submodule status pythonx/jedi'), '\v\n$', '', '')
|
||||
echon substitute(system('git -C '.spath.' submodule status pythonx/jedi'), '\v\n$', '', '')
|
||||
echo ' - parso git submodule status: '
|
||||
echon substitute(system('git -C '.s:script_path.' submodule status pythonx/parso'), '\v\n$', '', '')
|
||||
echon substitute(system('git -C '.spath.' submodule status pythonx/parso'), '\v\n$', '', '')
|
||||
echo "\n"
|
||||
echo '##### Global Python'
|
||||
echo "\n"
|
||||
echo 'Using Python version '.s:python_version.' to access Jedi.'
|
||||
let pyeval = s:python_version == 3 ? 'py3eval' : 'pyeval'
|
||||
echo 'Using Python version 3 to access Jedi.'
|
||||
let s:pythonjedi_called = 0
|
||||
PythonJedi import vim; vim.command('let s:pythonjedi_called = 1')
|
||||
try
|
||||
python3 import vim; vim.command('let s:pythonjedi_called = 1')
|
||||
catch
|
||||
echo 'Error when trying to import vim: '.v:exception
|
||||
endtry
|
||||
if !s:pythonjedi_called
|
||||
echohl WarningMsg
|
||||
echom 'PythonJedi failed to run, likely a Python config issue.'
|
||||
echom 'python3 failed to run, likely a Python config issue.'
|
||||
if exists(':checkhealth') == 2
|
||||
echom 'Try :checkhealth for more information.'
|
||||
endif
|
||||
echohl None
|
||||
else
|
||||
PythonJedi from jedi_vim_debug import display_debug_info
|
||||
PythonJedi display_debug_info()
|
||||
try
|
||||
python3 from jedi_vim_debug import display_debug_info
|
||||
python3 display_debug_info()
|
||||
catch
|
||||
echohl WarningMsg
|
||||
echo 'Error when running display_debug_info: '.v:exception
|
||||
echohl None
|
||||
endtry
|
||||
endif
|
||||
echo "\n"
|
||||
echo '##### Settings'
|
||||
@@ -277,71 +261,150 @@ call jedi#init_python() " Might throw an error.
|
||||
" functions that call python code
|
||||
" ------------------------------------------------------------------------
|
||||
function! jedi#goto() abort
|
||||
PythonJedi jedi_vim.goto(mode="goto")
|
||||
python3 jedi_vim.goto(mode="goto")
|
||||
endfunction
|
||||
|
||||
function! jedi#goto_assignments() abort
|
||||
PythonJedi jedi_vim.goto(mode="assignment")
|
||||
python3 jedi_vim.goto(mode="assignment")
|
||||
endfunction
|
||||
|
||||
function! jedi#goto_definitions() abort
|
||||
PythonJedi jedi_vim.goto(mode="definition")
|
||||
python3 jedi_vim.goto(mode="definition")
|
||||
endfunction
|
||||
|
||||
function! jedi#goto_stubs() abort
|
||||
PythonJedi jedi_vim.goto(mode="stubs")
|
||||
python3 jedi_vim.goto(mode="stubs")
|
||||
endfunction
|
||||
|
||||
function! jedi#usages() abort
|
||||
call jedi#remove_usages()
|
||||
PythonJedi jedi_vim.usages()
|
||||
if exists('#jedi_usages#BufWinEnter')
|
||||
call jedi#clear_usages()
|
||||
endif
|
||||
python3 jedi_vim.usages()
|
||||
endfunction
|
||||
|
||||
function! jedi#remove_usages() abort
|
||||
for match in getmatches()
|
||||
if stridx(match['group'], 'jediUsage') == 0
|
||||
call matchdelete(match['id'])
|
||||
if !s:supports_buffer_usages
|
||||
" Hide usages in the current window.
|
||||
" Only handles the current window due to matchdelete() restrictions.
|
||||
function! jedi#_hide_usages_in_win() abort
|
||||
let winnr = winnr()
|
||||
let matchids = getwinvar(winnr, '_jedi_usages_vim_matchids', [])
|
||||
|
||||
for matchid in matchids[1:]
|
||||
call matchdelete(matchid)
|
||||
endfor
|
||||
call setwinvar(winnr, '_jedi_usages_vim_matchids', [])
|
||||
|
||||
" Remove the autocommands that might have triggered this function.
|
||||
augroup jedi_usages
|
||||
exe 'autocmd! * <buffer='.winbufnr(winnr).'>'
|
||||
augroup END
|
||||
unlet! b:_jedi_usages_needs_clear
|
||||
endfunction
|
||||
|
||||
" Show usages for current window (Vim without textprops only).
|
||||
function! jedi#_show_usages_in_win() abort
|
||||
python3 jedi_vim.highlight_usages_for_vim_win()
|
||||
|
||||
if !exists('#jedi_usages#TextChanged#<buffer>')
|
||||
augroup jedi_usages
|
||||
" Unset highlights on any changes to this buffer.
|
||||
" NOTE: Neovim's API handles movement of highlights, but would only
|
||||
" need to clear highlights that are changed inline.
|
||||
autocmd TextChanged <buffer> call jedi#_clear_buffer_usages()
|
||||
|
||||
" Hide usages when the buffer is removed from the window, or when
|
||||
" entering insert mode (but keep them for later).
|
||||
autocmd BufWinLeave,InsertEnter <buffer> call jedi#_hide_usages_in_win()
|
||||
augroup END
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Remove usages for the current buffer (and all its windows).
|
||||
function! jedi#_clear_buffer_usages() abort
|
||||
let bufnr = bufnr('%')
|
||||
let nvim_src_ids = getbufvar(bufnr, '_jedi_usages_src_ids', [])
|
||||
if !empty(nvim_src_ids)
|
||||
for src_id in nvim_src_ids
|
||||
" TODO: could only clear highlights below/after changed line?!
|
||||
call nvim_buf_clear_highlight(bufnr, src_id, 0, -1)
|
||||
endfor
|
||||
else
|
||||
call jedi#_hide_usages_in_win()
|
||||
endif
|
||||
endfunction
|
||||
endif
|
||||
|
||||
" Remove/unset global usages.
|
||||
function! jedi#clear_usages() abort
|
||||
augroup jedi_usages
|
||||
autocmd! BufWinEnter
|
||||
autocmd! WinEnter
|
||||
augroup END
|
||||
|
||||
if !s:supports_buffer_usages
|
||||
" Vim without textprops: clear current window,
|
||||
" autocommands will clean others on demand.
|
||||
call jedi#_hide_usages_in_win()
|
||||
|
||||
" Setup autocommands to clear remaining highlights on WinEnter.
|
||||
augroup jedi_usages
|
||||
for b in range(1, bufnr('$'))
|
||||
if getbufvar(b, '_jedi_usages_needs_clear')
|
||||
exe 'autocmd WinEnter <buffer='.b.'> call jedi#_hide_usages_in_win()'
|
||||
endif
|
||||
endfor
|
||||
augroup END
|
||||
endif
|
||||
|
||||
python3 jedi_vim.clear_usages()
|
||||
endfunction
|
||||
|
||||
function! jedi#rename(...) abort
|
||||
PythonJedi jedi_vim.rename()
|
||||
python3 jedi_vim.rename()
|
||||
endfunction
|
||||
|
||||
function! jedi#rename_visual(...) abort
|
||||
PythonJedi jedi_vim.rename_visual()
|
||||
python3 jedi_vim.rename_visual()
|
||||
endfunction
|
||||
|
||||
function! jedi#completions(findstart, base) abort
|
||||
PythonJedi jedi_vim.completions()
|
||||
python3 jedi_vim.completions()
|
||||
endfunction
|
||||
|
||||
function! jedi#enable_speed_debugging() abort
|
||||
PythonJedi jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout, speed=True, warnings=False, notices=False)
|
||||
python3 jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout, speed=True, warnings=False, notices=False)
|
||||
endfunction
|
||||
|
||||
function! jedi#enable_debugging() abort
|
||||
PythonJedi jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout)
|
||||
python3 jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout)
|
||||
endfunction
|
||||
|
||||
function! jedi#disable_debugging() abort
|
||||
PythonJedi jedi_vim.jedi.set_debug_function(None)
|
||||
python3 jedi_vim.jedi.set_debug_function(None)
|
||||
endfunction
|
||||
|
||||
function! jedi#py_import(args) abort
|
||||
PythonJedi jedi_vim.py_import()
|
||||
python3 jedi_vim.py_import()
|
||||
endfun
|
||||
|
||||
function! jedi#choose_environment(args) abort
|
||||
python3 jedi_vim.choose_environment()
|
||||
endfun
|
||||
|
||||
function! jedi#load_project(args) abort
|
||||
python3 jedi_vim.load_project()
|
||||
endfun
|
||||
|
||||
function! jedi#py_import_completions(argl, cmdl, pos) abort
|
||||
PythonJedi jedi_vim.py_import_completions()
|
||||
python3 jedi_vim.py_import_completions()
|
||||
endfun
|
||||
|
||||
function! jedi#clear_cache(bang) abort
|
||||
if a:bang
|
||||
PythonJedi jedi_vim.jedi.cache.clear_time_caches(True)
|
||||
python3 jedi_vim.jedi.cache.clear_time_caches(True)
|
||||
else
|
||||
PythonJedi jedi_vim.jedi.cache.clear_time_caches(False)
|
||||
python3 jedi_vim.jedi.cache.clear_time_caches(False)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -350,7 +413,7 @@ endfunction
|
||||
" show_documentation
|
||||
" ------------------------------------------------------------------------
|
||||
function! jedi#show_documentation() abort
|
||||
PythonJedi if jedi_vim.show_documentation() is None: vim.command('return')
|
||||
python3 if jedi_vim.show_documentation() is None: vim.command('return')
|
||||
|
||||
let bn = bufnr('__doc__')
|
||||
if bn > 0
|
||||
@@ -392,20 +455,48 @@ endfunction
|
||||
" helper functions
|
||||
" ------------------------------------------------------------------------
|
||||
|
||||
function! jedi#add_goto_window(len) abort
|
||||
set lazyredraw
|
||||
cclose
|
||||
function! jedi#add_goto_window(for_usages, len) abort
|
||||
let height = min([a:len, g:jedi#quickfix_window_height])
|
||||
|
||||
" Use :copen to go to the window always - the user should select an entry.
|
||||
execute 'belowright copen '.height
|
||||
set nolazyredraw
|
||||
|
||||
if &filetype !=# 'qf'
|
||||
echoerr printf('jedi-vim: unexpected ft with current window (%s), please report!', &filetype)
|
||||
endif
|
||||
if g:jedi#use_tabs_not_buffers == 1
|
||||
noremap <buffer> <CR> :call jedi#goto_window_on_enter()<CR>
|
||||
endif
|
||||
|
||||
augroup jedi_goto_window
|
||||
au!
|
||||
au WinLeave <buffer> q " automatically leave, if an option is chosen
|
||||
if a:for_usages
|
||||
autocmd BufWinLeave <buffer> call jedi#clear_usages()
|
||||
else
|
||||
autocmd WinLeave <buffer> q " automatically leave, if an option is chosen
|
||||
endif
|
||||
augroup END
|
||||
redraw!
|
||||
|
||||
if a:for_usages && !has('nvim')
|
||||
if s:supports_buffer_usages
|
||||
" Setup autocommand for pending highlights with Vim's textprops.
|
||||
" (cannot be added to unlisted buffers)
|
||||
augroup jedi_usages
|
||||
autocmd! BufWinEnter * call s:usages_for_pending_buffers()
|
||||
augroup END
|
||||
else
|
||||
" Setup global autocommand to display any usages for a window.
|
||||
" Gets removed when closing the quickfix window that displays them, or
|
||||
" when clearing them (e.g. on TextChanged).
|
||||
augroup jedi_usages
|
||||
autocmd! BufWinEnter,WinEnter * call jedi#_show_usages_in_win()
|
||||
augroup END
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Highlight usages for a buffer if not done so yet (Neovim only).
|
||||
function! s:usages_for_pending_buffers() abort
|
||||
python3 jedi_vim._handle_pending_usages_for_buf()
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -415,7 +506,7 @@ function! jedi#goto_window_on_enter() abort
|
||||
if l:data.bufnr
|
||||
" close goto_window buffer
|
||||
normal! ZQ
|
||||
PythonJedi jedi_vim.new_buffer(vim.eval('bufname(l:data.bufnr)'))
|
||||
python3 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
|
||||
@@ -461,22 +552,23 @@ function! jedi#show_call_signatures() abort
|
||||
|
||||
" 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
|
||||
" Check if the number of special signs 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 no_special = '[^,()=]'
|
||||
if substitute(curline[:col-2], no_special, '', 'g')
|
||||
\ == substitute(prevline[:prevcol-2], no_special, '', 'g')
|
||||
\ && substitute(curline[(col-2):], no_special, '', 'g')
|
||||
\ == substitute(prevline[(prevcol-2):], no_special, '', '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()
|
||||
python3 jedi_vim.show_call_signatures()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -487,7 +579,7 @@ function! jedi#clear_call_signatures() abort
|
||||
endif
|
||||
|
||||
let s:show_call_signatures_last = [0, 0, '']
|
||||
PythonJedi jedi_vim.clear_call_signatures()
|
||||
python3 jedi_vim.clear_call_signatures()
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -632,7 +724,7 @@ function! jedi#setup_completion() abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"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)
|
||||
"python3 jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout, speed=True, warnings=False, notices=False)
|
||||
"python3 jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout)
|
||||
|
||||
" vim: set et ts=4:
|
||||
|
||||
7
codecov.yml
Normal file
7
codecov.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
coverage:
|
||||
status:
|
||||
project: true
|
||||
patch: true
|
||||
changes: true
|
||||
|
||||
comment: off
|
||||
@@ -24,7 +24,7 @@ Contents *jedi-vim-contents*
|
||||
5.1. Start completion |g:jedi#completions_command|
|
||||
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.4 Go to stub |g:jedi#goto_stubs_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|
|
||||
@@ -44,6 +44,7 @@ Contents *jedi-vim-contents*
|
||||
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|
|
||||
6.15. environment_path |g:jedi#environment_path|
|
||||
7. Testing |jedi-vim-testing|
|
||||
8. Contributing |jedi-vim-contributing|
|
||||
9. License |jedi-vim-license|
|
||||
@@ -170,7 +171,7 @@ Python features, among them:
|
||||
- Class decorators (py3k feature, are being ignored at the moment, but are
|
||||
parsed)
|
||||
- Simple/usual `sys.path` modifications
|
||||
- `isinstance` checks for `if`/`while`/`assert` case, that doesn’t work with
|
||||
- `isinstance` checks for `if`/`while`/`assert` case, that doesn't work with
|
||||
Jedi
|
||||
- Stubs
|
||||
- And more...
|
||||
@@ -274,12 +275,11 @@ 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
|
||||
5.4. `g:jedi#goto_stubs_command` *g:jedi#goto_stubs_command*
|
||||
Function: `jedi#goto_stubs()`
|
||||
Default: <leader>s Go to stub
|
||||
|
||||
NOTE: Deprecated. Use |g:jedi#goto_command| / |jedi#goto()| instead, which
|
||||
currently uses this internally.
|
||||
Finds the stub of the function/class under the cursor.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
5.5. `g:jedi#documentation_command` *g:jedi#documentation_command*
|
||||
@@ -507,6 +507,17 @@ definition with arbitrary changes to the |jumplist|.
|
||||
Options: 0 or 1
|
||||
Default: 1 (enabled by default)
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
6.15. `g:jedi#environment_path` *g:jedi#environment_path*
|
||||
|
||||
To use a specific virtualenv or a specific Python version it is possible to
|
||||
set an interpreter.
|
||||
|
||||
Both setting the directory and setting a project is working.
|
||||
|
||||
Examples: "/usr/bin/python3.9", "venv", "../venv", "../venv/bin/python"
|
||||
Default: "auto"
|
||||
|
||||
==============================================================================
|
||||
7. Testing *jedi-vim-testing*
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ if g:jedi#auto_initialization
|
||||
execute 'nnoremap <silent> <buffer>'.g:jedi#documentation_command.' :call jedi#show_documentation()<CR>'
|
||||
endif
|
||||
|
||||
if g:jedi#show_call_signatures > 0 && has('conceal')
|
||||
if g:jedi#show_call_signatures > 0
|
||||
call jedi#configure_call_signatures()
|
||||
endif
|
||||
|
||||
@@ -50,8 +50,4 @@ if g:jedi#auto_initialization
|
||||
autocmd! InsertLeave <buffer> if pumvisible() == 0|pclose|endif
|
||||
augroup END
|
||||
endif
|
||||
augroup jedi_usages
|
||||
autocmd! TextChanged <buffer> call jedi#remove_usages()
|
||||
autocmd! InsertEnter <buffer> call jedi#remove_usages()
|
||||
augroup END
|
||||
endif
|
||||
|
||||
@@ -53,6 +53,10 @@ endif
|
||||
" Pyimport command
|
||||
command! -nargs=1 -complete=custom,jedi#py_import_completions Pyimport :call jedi#py_import(<q-args>)
|
||||
|
||||
command! -nargs=? -complete=file JediChooseEnvironment :call jedi#choose_environment(<q-args>)
|
||||
command! -nargs=? -complete=file JediLoadProject :call jedi#load_project(<q-args>)
|
||||
|
||||
|
||||
function! s:jedi_debug_info()
|
||||
" Ensure the autoload file has been loaded (and ignore any errors, which
|
||||
" will be displayed with the debug info).
|
||||
|
||||
Submodule pythonx/jedi updated: 60415033b4...4b5b2e791b
@@ -67,7 +67,9 @@ class VimError(Exception):
|
||||
self.executing = executing
|
||||
|
||||
def __str__(self):
|
||||
return self.message + '; created by: ' + repr(self.executing)
|
||||
return "{}; created by {!r} (in {})".format(
|
||||
self.message, self.executing, self.throwpoint
|
||||
)
|
||||
|
||||
|
||||
def _catch_exception(string, is_eval):
|
||||
@@ -134,6 +136,58 @@ finally:
|
||||
sys.path.remove(parso_path)
|
||||
|
||||
|
||||
class VimCompat:
|
||||
_eval_cache = {}
|
||||
_func_cache = {}
|
||||
|
||||
@classmethod
|
||||
def has(cls, what):
|
||||
try:
|
||||
return cls._eval_cache[what]
|
||||
except KeyError:
|
||||
ret = cls._eval_cache[what] = cls.call('has', what)
|
||||
return ret
|
||||
|
||||
@classmethod
|
||||
def call(cls, func, *args):
|
||||
try:
|
||||
f = cls._func_cache[func]
|
||||
except KeyError:
|
||||
if IS_NVIM:
|
||||
f = cls._func_cache[func] = getattr(vim.funcs, func)
|
||||
else:
|
||||
f = cls._func_cache[func] = vim.Function(func)
|
||||
return f(*args)
|
||||
|
||||
@classmethod
|
||||
def setqflist(cls, items, title, context):
|
||||
if cls.has('patch-7.4.2200'): # can set qf title.
|
||||
what = {'title': title}
|
||||
if cls.has('patch-8.0.0590'): # can set qf context
|
||||
what['context'] = {'jedi_usages': context}
|
||||
if cls.has('patch-8.0.0657'): # can set items via "what".
|
||||
what['items'] = items
|
||||
cls.call('setqflist', [], ' ', what)
|
||||
else:
|
||||
# Can set title (and maybe context), but needs two calls.
|
||||
cls.call('setqflist', items)
|
||||
cls.call('setqflist', items, 'a', what)
|
||||
else:
|
||||
cls.call('setqflist', items)
|
||||
|
||||
@classmethod
|
||||
def setqflist_title(cls, title):
|
||||
if cls.has('patch-7.4.2200'):
|
||||
cls.call('setqflist', [], 'a', {'title': title})
|
||||
|
||||
@classmethod
|
||||
def can_update_current_qflist_for_context(cls, context):
|
||||
if cls.has('patch-8.0.0590'): # can set qf context
|
||||
return cls.call('getqflist', {'context': 1})['context'] == {
|
||||
'jedi_usages': context,
|
||||
}
|
||||
|
||||
|
||||
def catch_and_print_exceptions(func):
|
||||
def wrapper(*args, **kwargs):
|
||||
try:
|
||||
@@ -157,51 +211,84 @@ def _check_jedi_availability(show_error=False):
|
||||
return func_receiver
|
||||
|
||||
|
||||
current_environment = (None, None)
|
||||
# Tuple of cache key / project
|
||||
_current_project_cache = None, None
|
||||
|
||||
|
||||
def get_environment(use_cache=True):
|
||||
global current_environment
|
||||
def get_project():
|
||||
vim_environment_path = vim_eval("g:jedi#environment_path")
|
||||
vim_project_path = vim_eval("g:jedi#project_path")
|
||||
|
||||
vim_force_python_version = vim_eval("g:jedi#force_py_version")
|
||||
if use_cache and vim_force_python_version == current_environment[0]:
|
||||
return current_environment[1]
|
||||
global _current_project_cache
|
||||
cache_key = dict(project_path=vim_project_path, environment_path=vim_environment_path)
|
||||
if cache_key == _current_project_cache[0]:
|
||||
return _current_project_cache[1]
|
||||
|
||||
environment = None
|
||||
if vim_force_python_version == "auto":
|
||||
environment = jedi.api.environment.get_cached_default_environment()
|
||||
if vim_environment_path in ("auto", "", None):
|
||||
environment_path = None
|
||||
else:
|
||||
force_python_version = vim_force_python_version
|
||||
if '0000' in force_python_version or '9999' in force_python_version:
|
||||
# It's probably a float that wasn't shortened.
|
||||
try:
|
||||
force_python_version = "{:.1f}".format(float(force_python_version))
|
||||
except ValueError:
|
||||
pass
|
||||
elif isinstance(force_python_version, float):
|
||||
force_python_version = "{:.1f}".format(force_python_version)
|
||||
environment_path = vim_environment_path
|
||||
|
||||
try:
|
||||
environment = jedi.get_system_environment(force_python_version)
|
||||
except jedi.InvalidPythonEnvironment as exc:
|
||||
environment = jedi.api.environment.get_cached_default_environment()
|
||||
echo_highlight(
|
||||
"force_python_version=%s is not supported: %s - using %s." % (
|
||||
vim_force_python_version, str(exc), str(environment)))
|
||||
if vim_project_path in ("auto", "", None):
|
||||
project_path = jedi.get_default_project().path
|
||||
else:
|
||||
project_path = vim_project_path
|
||||
|
||||
current_environment = (vim_force_python_version, environment)
|
||||
return environment
|
||||
project = jedi.Project(project_path, environment_path=environment_path)
|
||||
|
||||
|
||||
def get_known_environments():
|
||||
"""Get known Jedi environments."""
|
||||
envs = list(jedi.api.environment.find_virtualenvs())
|
||||
envs.extend(jedi.api.environment.find_system_environments())
|
||||
return envs
|
||||
_current_project_cache = cache_key, project
|
||||
return project
|
||||
|
||||
|
||||
@catch_and_print_exceptions
|
||||
def get_script(source=None, column=None):
|
||||
def choose_environment():
|
||||
args = shsplit(vim.eval('a:args'))
|
||||
|
||||
envs = list(jedi.find_system_environments())
|
||||
envs.extend(jedi.find_virtualenvs(paths=args or None))
|
||||
|
||||
env_paths = [env.executable for env in envs]
|
||||
|
||||
vim_command('belowright new')
|
||||
vim.current.buffer[:] = env_paths
|
||||
vim.current.buffer.name = "Hit Enter to Choose an Environment"
|
||||
vim_command(
|
||||
'setlocal buftype=nofile bufhidden=wipe noswapfile nobuflisted readonly nomodifiable')
|
||||
vim_command('noremap <buffer> <ESC> :bw<CR>')
|
||||
vim_command('noremap <buffer> <CR> :python3 jedi_vim.choose_environment_hit_enter()<CR>')
|
||||
|
||||
|
||||
@catch_and_print_exceptions
|
||||
def choose_environment_hit_enter():
|
||||
vim.vars['jedi#environment_path'] = vim.current.line
|
||||
vim_command('bd')
|
||||
|
||||
|
||||
@catch_and_print_exceptions
|
||||
def load_project():
|
||||
path = vim.eval('a:args')
|
||||
vim.vars['jedi#project_path'] = path
|
||||
env_path = vim_eval("g:jedi#environment_path")
|
||||
if env_path == 'auto':
|
||||
env_path = None
|
||||
if path:
|
||||
try:
|
||||
project = jedi.Project.load(path)
|
||||
except FileNotFoundError:
|
||||
project = jedi.Project(path, environment_path=env_path)
|
||||
project.save()
|
||||
else:
|
||||
project = jedi.get_default_project()
|
||||
path = project.path
|
||||
project.save()
|
||||
|
||||
global _current_project_cache
|
||||
cache_key = dict(project_path=path, environment_path=env_path)
|
||||
_current_project_cache = cache_key, project
|
||||
|
||||
|
||||
@catch_and_print_exceptions
|
||||
def get_script(source=None):
|
||||
jedi.settings.additional_dynamic_modules = [
|
||||
b.name for b in vim.buffers if (
|
||||
b.name is not None and
|
||||
@@ -209,16 +296,19 @@ def get_script(source=None, column=None):
|
||||
b.options['buflisted'])]
|
||||
if source is None:
|
||||
source = '\n'.join(vim.current.buffer)
|
||||
buf_path = vim.current.buffer.name
|
||||
if not buf_path:
|
||||
# If a buffer has no name its name is an empty string.
|
||||
buf_path = None
|
||||
|
||||
return jedi.Script(source, path=buf_path, project=get_project())
|
||||
|
||||
|
||||
def get_pos(column=None):
|
||||
row = vim.current.window.cursor[0]
|
||||
if column is None:
|
||||
column = vim.current.window.cursor[1]
|
||||
buf_path = vim.current.buffer.name
|
||||
|
||||
return jedi.Script(
|
||||
source, row, column, buf_path,
|
||||
encoding=vim_eval('&encoding') or 'latin1',
|
||||
environment=get_environment(),
|
||||
)
|
||||
return row, column
|
||||
|
||||
|
||||
@_check_jedi_availability(show_error=False)
|
||||
@@ -249,20 +339,26 @@ def completions():
|
||||
# here again hacks, because jedi has a different interface than vim
|
||||
column += len(base)
|
||||
try:
|
||||
script = get_script(source=source, column=column)
|
||||
completions = script.completions()
|
||||
signatures = script.call_signatures()
|
||||
script = get_script(source=source)
|
||||
completions = script.complete(*get_pos(column))
|
||||
signatures = script.get_signatures(*get_pos(column))
|
||||
|
||||
add_info = "preview" in vim.eval("&completeopt").split(",")
|
||||
out = []
|
||||
for c in completions:
|
||||
d = dict(word=PythonToVimStr(c.name[:len(base)] + c.complete),
|
||||
abbr=PythonToVimStr(c.name_with_symbols),
|
||||
# stuff directly behind the completion
|
||||
menu=PythonToVimStr(c.description),
|
||||
info=PythonToVimStr(c.docstring()), # docstr
|
||||
icase=1, # case insensitive
|
||||
dup=1 # allow duplicates (maybe later remove this)
|
||||
)
|
||||
if add_info:
|
||||
try:
|
||||
d["info"] = PythonToVimStr(c.docstring())
|
||||
except Exception:
|
||||
print("jedi-vim: error with docstring for %r: %s" % (
|
||||
c, traceback.format_exc()))
|
||||
out.append(d)
|
||||
|
||||
strout = str(out)
|
||||
@@ -294,42 +390,50 @@ def tempfile(content):
|
||||
def goto(mode="goto"):
|
||||
"""
|
||||
:param str mode: "definition", "assignment", "goto"
|
||||
:return: list of definitions/assignments
|
||||
:rtype: list
|
||||
:rtype: list of jedi.api.classes.Name
|
||||
"""
|
||||
script = get_script()
|
||||
pos = get_pos()
|
||||
if mode == "goto":
|
||||
definitions = script.goto_assignments(follow_imports=True)
|
||||
names = script.goto(*pos, follow_imports=True)
|
||||
elif mode == "definition":
|
||||
definitions = script.goto_definitions()
|
||||
names = script.infer(*pos)
|
||||
elif mode == "assignment":
|
||||
definitions = script.goto_assignments()
|
||||
names = script.goto(*pos)
|
||||
elif mode == "stubs":
|
||||
definitions = script.goto_assignments(follow_imports=True, only_stubs=True)
|
||||
names = script.goto(*pos, follow_imports=True, only_stubs=True)
|
||||
|
||||
if not definitions:
|
||||
if not names:
|
||||
echo_highlight("Couldn't find any definitions for this.")
|
||||
elif len(definitions) == 1 and mode != "related_name":
|
||||
d = list(definitions)[0]
|
||||
if d.column is None:
|
||||
if d.is_keyword:
|
||||
elif len(names) == 1 and mode != "related_name":
|
||||
n = list(names)[0]
|
||||
_goto_specific_name(n)
|
||||
else:
|
||||
show_goto_multi_results(names, mode)
|
||||
return names
|
||||
|
||||
|
||||
def _goto_specific_name(n, options=''):
|
||||
if n.column is None:
|
||||
if n.is_keyword:
|
||||
echo_highlight("Cannot get the definition of Python keywords.")
|
||||
else:
|
||||
echo_highlight("Builtin modules cannot be displayed (%s)."
|
||||
% d.desc_with_module)
|
||||
% (n.full_name or n.name))
|
||||
else:
|
||||
using_tagstack = int(vim_eval('g:jedi#use_tag_stack')) == 1
|
||||
if (d.module_path or '') != vim.current.buffer.name:
|
||||
result = new_buffer(d.module_path,
|
||||
module_path = str(n.module_path or '')
|
||||
if module_path != vim.current.buffer.name:
|
||||
result = new_buffer(module_path, options=options,
|
||||
using_tagstack=using_tagstack)
|
||||
if not result:
|
||||
return []
|
||||
if (using_tagstack and d.module_path and
|
||||
os.path.exists(d.module_path)):
|
||||
tagname = d.name
|
||||
if (using_tagstack and module_path and
|
||||
os.path.exists(module_path)):
|
||||
tagname = n.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:
|
||||
tagname, module_path, 'call cursor({0}, {1})'.format(
|
||||
n.line, n.column + 1))) as f:
|
||||
old_tags = vim.eval('&tags')
|
||||
old_wildignore = vim.eval('&wildignore')
|
||||
try:
|
||||
@@ -343,10 +447,7 @@ def goto(mode="goto"):
|
||||
repr(PythonToVimStr(old_tags)))
|
||||
vim.command('let &wildignore = %s' %
|
||||
repr(PythonToVimStr(old_wildignore)))
|
||||
vim.current.window.cursor = d.line, d.column
|
||||
else:
|
||||
show_goto_multi_results(definitions)
|
||||
return definitions
|
||||
vim.current.window.cursor = n.line, n.column
|
||||
|
||||
|
||||
def relpath(path):
|
||||
@@ -357,61 +458,298 @@ def relpath(path):
|
||||
return path
|
||||
|
||||
|
||||
def annotate_description(d):
|
||||
code = d.get_line_code().strip()
|
||||
if d.type == 'statement':
|
||||
def annotate_description(n):
|
||||
code = n.get_line_code().strip()
|
||||
if n.type == 'statement':
|
||||
return code
|
||||
if d.type == 'function':
|
||||
if n.type == 'function':
|
||||
if code.startswith('def'):
|
||||
return code
|
||||
typ = 'def'
|
||||
else:
|
||||
typ = d.type
|
||||
typ = n.type
|
||||
return '[%s] %s' % (typ, code)
|
||||
|
||||
|
||||
def show_goto_multi_results(definitions):
|
||||
"""Create a quickfix list for multiple definitions."""
|
||||
def show_goto_multi_results(names, mode):
|
||||
"""Create (or reuse) a quickfix list for multiple names."""
|
||||
global _current_names
|
||||
|
||||
lst = []
|
||||
for d in definitions:
|
||||
if d.column is None:
|
||||
(row, col) = vim.current.window.cursor
|
||||
current_idx = None
|
||||
current_def = None
|
||||
for n in names:
|
||||
if n.column is None:
|
||||
# Typically a namespace, in the future maybe other things as
|
||||
# well.
|
||||
lst.append(dict(text=PythonToVimStr(d.description)))
|
||||
lst.append(dict(text=PythonToVimStr(n.description)))
|
||||
else:
|
||||
text = annotate_description(d)
|
||||
lst.append(dict(filename=PythonToVimStr(relpath(d.module_path)),
|
||||
lnum=d.line, col=d.column + 1,
|
||||
text = annotate_description(n)
|
||||
lst.append(dict(filename=PythonToVimStr(relpath(str(n.module_path))),
|
||||
lnum=n.line, col=n.column + 1,
|
||||
text=PythonToVimStr(text)))
|
||||
vim_eval('setqflist(%s)' % repr(lst))
|
||||
vim_eval('jedi#add_goto_window(' + str(len(lst)) + ')')
|
||||
|
||||
# Select current/nearest entry via :cc later.
|
||||
if n.line == row and n.column <= col:
|
||||
if (current_idx is None
|
||||
or (abs(lst[current_idx]["col"] - col)
|
||||
> abs(n.column - col))):
|
||||
current_idx = len(lst)
|
||||
current_def = n
|
||||
|
||||
# Build qflist title.
|
||||
qf_title = mode
|
||||
if current_def is not None:
|
||||
if current_def.full_name:
|
||||
qf_title += ": " + current_def.full_name
|
||||
else:
|
||||
qf_title += ": " + str(current_def)
|
||||
select_entry = current_idx
|
||||
else:
|
||||
select_entry = 0
|
||||
|
||||
qf_context = id(names)
|
||||
if (_current_names
|
||||
and VimCompat.can_update_current_qflist_for_context(qf_context)):
|
||||
# Same list, only adjust title/selected entry.
|
||||
VimCompat.setqflist_title(qf_title)
|
||||
vim_command('%dcc' % select_entry)
|
||||
else:
|
||||
VimCompat.setqflist(lst, title=qf_title, context=qf_context)
|
||||
for_usages = mode == "usages"
|
||||
vim_eval('jedi#add_goto_window(%d, %d)' % (for_usages, len(lst)))
|
||||
vim_command('%d' % select_entry)
|
||||
|
||||
|
||||
def _same_names(a, b):
|
||||
"""Compare without _inference_state.
|
||||
|
||||
Ref: https://github.com/davidhalter/jedi-vim/issues/952)
|
||||
"""
|
||||
return all(
|
||||
x._name.start_pos == y._name.start_pos
|
||||
and x.module_path == y.module_path
|
||||
and x.name == y.name
|
||||
for x, y in zip(a, b)
|
||||
)
|
||||
|
||||
|
||||
@catch_and_print_exceptions
|
||||
def usages(visuals=True):
|
||||
script = get_script()
|
||||
definitions = script.usages()
|
||||
if not definitions:
|
||||
names = script.get_references(*get_pos())
|
||||
if not names:
|
||||
echo_highlight("No usages found here.")
|
||||
return definitions
|
||||
return names
|
||||
|
||||
if visuals:
|
||||
highlight_usages(definitions)
|
||||
show_goto_multi_results(definitions)
|
||||
return definitions
|
||||
global _current_names
|
||||
|
||||
if _current_names:
|
||||
if _same_names(_current_names, names):
|
||||
names = _current_names
|
||||
else:
|
||||
clear_usages()
|
||||
assert not _current_names
|
||||
|
||||
show_goto_multi_results(names, "usages")
|
||||
if not _current_names:
|
||||
_current_names = names
|
||||
highlight_usages()
|
||||
else:
|
||||
assert names is _current_names # updated above
|
||||
return names
|
||||
|
||||
|
||||
def highlight_usages(definitions, length=None):
|
||||
for definition in definitions:
|
||||
# Only color the current module/buffer.
|
||||
if (definition.module_path or '') == vim.current.buffer.name:
|
||||
# mathaddpos needs a list of positions where a position is a list
|
||||
# of (line, column, length).
|
||||
# The column starts with 1 and not 0.
|
||||
_current_names = None
|
||||
"""Current definitions to use for highlighting."""
|
||||
_pending_names = {}
|
||||
"""Pending definitions for unloaded buffers."""
|
||||
_placed_names_in_buffers = set()
|
||||
"""Set of buffers for faster cleanup."""
|
||||
|
||||
|
||||
IS_NVIM = hasattr(vim, 'from_nvim')
|
||||
if IS_NVIM:
|
||||
vim_prop_add = None
|
||||
else:
|
||||
vim_prop_type_added = False
|
||||
try:
|
||||
vim_prop_add = vim.Function("prop_add")
|
||||
except ValueError:
|
||||
vim_prop_add = None
|
||||
else:
|
||||
vim_prop_remove = vim.Function("prop_remove")
|
||||
|
||||
|
||||
def clear_usages():
|
||||
"""Clear existing highlights."""
|
||||
global _current_names
|
||||
if _current_names is None:
|
||||
return
|
||||
_current_names = None
|
||||
|
||||
if IS_NVIM:
|
||||
for buf in _placed_names_in_buffers:
|
||||
src_ids = buf.vars.get('_jedi_usages_src_ids')
|
||||
if src_ids is not None:
|
||||
for src_id in src_ids:
|
||||
buf.clear_highlight(src_id)
|
||||
elif vim_prop_add:
|
||||
for buf in _placed_names_in_buffers:
|
||||
vim_prop_remove({
|
||||
'type': 'jediUsage',
|
||||
'all': 1,
|
||||
'bufnr': buf.number,
|
||||
})
|
||||
else:
|
||||
# Unset current window only.
|
||||
assert _current_names is None
|
||||
highlight_usages_for_vim_win()
|
||||
|
||||
_placed_names_in_buffers.clear()
|
||||
|
||||
|
||||
def highlight_usages():
|
||||
"""Set usage names to be highlighted.
|
||||
|
||||
With Neovim it will use the nvim_buf_add_highlight API to highlight all
|
||||
buffers already.
|
||||
|
||||
With Vim without support for text-properties only the current window is
|
||||
highlighted via matchaddpos, and autocommands are setup to highlight other
|
||||
windows on demand. Otherwise Vim's text-properties are used.
|
||||
"""
|
||||
global _current_names, _pending_names
|
||||
|
||||
names = _current_names
|
||||
_pending_names = {}
|
||||
|
||||
if IS_NVIM or vim_prop_add:
|
||||
bufs = {x.name: x for x in vim.buffers}
|
||||
defs_per_buf = {}
|
||||
for name in names:
|
||||
try:
|
||||
buf = bufs[str(name.module_path)]
|
||||
except KeyError:
|
||||
continue
|
||||
defs_per_buf.setdefault(buf, []).append(name)
|
||||
|
||||
if IS_NVIM:
|
||||
# We need to remember highlight ids with Neovim's API.
|
||||
buf_src_ids = {}
|
||||
for buf, names in defs_per_buf.items():
|
||||
buf_src_ids[buf] = []
|
||||
for name in names:
|
||||
src_id = _add_highlighted_name(buf, name)
|
||||
buf_src_ids[buf].append(src_id)
|
||||
for buf, src_ids in buf_src_ids.items():
|
||||
buf.vars['_jedi_usages_src_ids'] = src_ids
|
||||
else:
|
||||
for buf, names in defs_per_buf.items():
|
||||
try:
|
||||
for name in names:
|
||||
_add_highlighted_name(buf, name)
|
||||
except vim.error as exc:
|
||||
if exc.args[0].startswith('Vim:E275:'):
|
||||
# "Cannot add text property to unloaded buffer"
|
||||
_pending_names.setdefault(buf.name, []).extend(
|
||||
names)
|
||||
else:
|
||||
highlight_usages_for_vim_win()
|
||||
|
||||
|
||||
def _handle_pending_usages_for_buf():
|
||||
"""Add (pending) highlights for the current buffer (Vim with textprops)."""
|
||||
buf = vim.current.buffer
|
||||
bufname = buf.name
|
||||
try:
|
||||
buf_names = _pending_names[bufname]
|
||||
except KeyError:
|
||||
return
|
||||
for name in buf_names:
|
||||
_add_highlighted_name(buf, name)
|
||||
del _pending_names[bufname]
|
||||
|
||||
|
||||
def _add_highlighted_name(buf, name):
|
||||
lnum = name.line
|
||||
start_col = name.column
|
||||
|
||||
# Skip highlighting of module definitions that point to the start
|
||||
# of the file.
|
||||
if name.type == 'module' and lnum == 1 and start_col == 0:
|
||||
return
|
||||
|
||||
_placed_names_in_buffers.add(buf)
|
||||
|
||||
# TODO: validate that name.name is at this position?
|
||||
# Would skip the module definitions from above already.
|
||||
|
||||
length = len(name.name)
|
||||
if vim_prop_add:
|
||||
# XXX: needs jediUsage highlight (via after/syntax/python.vim).
|
||||
global vim_prop_type_added
|
||||
if not vim_prop_type_added:
|
||||
vim.eval("prop_type_add('jediUsage', {'highlight': 'jediUsage'})")
|
||||
vim_prop_type_added = True
|
||||
vim_prop_add(lnum, start_col+1, {
|
||||
'type': 'jediUsage',
|
||||
'bufnr': buf.number,
|
||||
'length': length,
|
||||
})
|
||||
return
|
||||
|
||||
assert IS_NVIM
|
||||
end_col = name.column + length
|
||||
src_id = buf.add_highlight('jediUsage', lnum-1, start_col, end_col,
|
||||
src_id=0)
|
||||
return src_id
|
||||
|
||||
|
||||
def highlight_usages_for_vim_win():
|
||||
"""Highlight usages in the current window.
|
||||
|
||||
It stores the matchids in a window-local variable.
|
||||
|
||||
(matchaddpos() only works for the current window.)
|
||||
"""
|
||||
win = vim.current.window
|
||||
|
||||
cur_matchids = win.vars.get('_jedi_usages_vim_matchids')
|
||||
if cur_matchids:
|
||||
if cur_matchids[0] == vim.current.buffer.number:
|
||||
return
|
||||
|
||||
# Need to clear non-matching highlights.
|
||||
for matchid in cur_matchids[1:]:
|
||||
expr = 'matchdelete(%d)' % int(matchid)
|
||||
vim.eval(expr)
|
||||
|
||||
matchids = []
|
||||
if _current_names:
|
||||
buffer_path = vim.current.buffer.name
|
||||
for name in _current_names:
|
||||
if (str(name.module_path) or '') == buffer_path:
|
||||
positions = [
|
||||
[definition.line, definition.column + 1, length or len(definition.name)]
|
||||
[name.line,
|
||||
name.column + 1,
|
||||
len(name.name)]
|
||||
]
|
||||
vim_eval("matchaddpos('jediUsage', %s)" % repr(positions))
|
||||
expr = "matchaddpos('jediUsage', %s)" % repr(positions)
|
||||
matchids.append(int(vim_eval(expr)))
|
||||
|
||||
if matchids:
|
||||
vim.current.window.vars['_jedi_usages_vim_matchids'] = [
|
||||
vim.current.buffer.number] + matchids
|
||||
elif cur_matchids is not None:
|
||||
# Always set it (uses an empty list for "unset", which is not possible
|
||||
# using del).
|
||||
vim.current.window.vars['_jedi_usages_vim_matchids'] = []
|
||||
|
||||
# Remember if clearing is needed for later buffer autocommands.
|
||||
vim.current.buffer.vars['_jedi_usages_needs_clear'] = bool(matchids)
|
||||
|
||||
|
||||
@_check_jedi_availability(show_error=True)
|
||||
@@ -419,19 +757,27 @@ def highlight_usages(definitions, length=None):
|
||||
def show_documentation():
|
||||
script = get_script()
|
||||
try:
|
||||
definitions = script.goto_definitions()
|
||||
names = script.help(*get_pos())
|
||||
except Exception:
|
||||
# print to stdout, will be in :messages
|
||||
definitions = []
|
||||
names = []
|
||||
print("Exception, this shouldn't happen.")
|
||||
print(traceback.format_exc())
|
||||
|
||||
if not definitions:
|
||||
if not names:
|
||||
echo_highlight('No documentation found for that.')
|
||||
vim.command('return')
|
||||
return
|
||||
|
||||
docs = []
|
||||
for n in names:
|
||||
doc = n.docstring()
|
||||
if doc:
|
||||
title = 'Docstring for %s %s' % (n.type, n.full_name or n.name)
|
||||
underline = '=' * len(title)
|
||||
docs.append('%s\n%s\n%s' % (title, underline, doc))
|
||||
else:
|
||||
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]
|
||||
docs.append('|No Docstring for %s|' % n)
|
||||
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')))
|
||||
@@ -470,9 +816,12 @@ def show_call_signatures(signatures=()):
|
||||
if int(vim_eval("has('conceal') && g:jedi#show_call_signatures")) == 0:
|
||||
return
|
||||
|
||||
if signatures == ():
|
||||
signatures = get_script().call_signatures()
|
||||
# We need to clear the signatures before we calculate them again. The
|
||||
# reason for this is that call signatures are unfortunately written to the
|
||||
# buffer.
|
||||
clear_call_signatures()
|
||||
if signatures == ():
|
||||
signatures = get_script().get_signatures(*get_pos())
|
||||
|
||||
if not signatures:
|
||||
return
|
||||
@@ -695,18 +1044,19 @@ def do_rename(replace, orig=None):
|
||||
# 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.line, x.column))
|
||||
key=lambda x: (str(x.module_path), x.line, x.column))
|
||||
buffers = set()
|
||||
for r in temp_rename:
|
||||
if r.in_builtin_module():
|
||||
continue
|
||||
|
||||
if os.path.abspath(vim.current.buffer.name) != r.module_path:
|
||||
assert r.module_path is not None
|
||||
result = new_buffer(r.module_path)
|
||||
module_path = r.module_path
|
||||
if os.path.abspath(vim.current.buffer.name) != str(module_path):
|
||||
assert module_path is not None
|
||||
result = new_buffer(module_path)
|
||||
if not result:
|
||||
echo_highlight('Failed to create buffer window for %s!' % (
|
||||
r.module_path))
|
||||
module_path))
|
||||
continue
|
||||
|
||||
buffers.add(vim.current.buffer.name)
|
||||
@@ -730,35 +1080,25 @@ def do_rename(replace, orig=None):
|
||||
@_check_jedi_availability(show_error=True)
|
||||
@catch_and_print_exceptions
|
||||
def py_import():
|
||||
# args are the same as for the :edit command
|
||||
args = shsplit(vim.eval('a:args'))
|
||||
import_path = args.pop()
|
||||
text = 'import %s' % import_path
|
||||
scr = jedi.Script(text, 1, len(text), '', environment=get_environment())
|
||||
try:
|
||||
completion = scr.goto_assignments()[0]
|
||||
except IndexError:
|
||||
echo_highlight('Cannot find %s in sys.path!' % import_path)
|
||||
else:
|
||||
if completion.column is None: # Python modules always have a line number.
|
||||
echo_highlight('%s is a builtin module.' % import_path)
|
||||
name = next(get_project().search(import_path), None)
|
||||
if name is None:
|
||||
echo_highlight('Cannot find %s in your project or on sys.path!' % import_path)
|
||||
else:
|
||||
cmd_args = ' '.join([a.replace(' ', '\\ ') for a in args])
|
||||
new_buffer(completion.module_path, cmd_args)
|
||||
_goto_specific_name(name, options=cmd_args)
|
||||
|
||||
|
||||
@catch_and_print_exceptions
|
||||
def py_import_completions():
|
||||
argl = vim.eval('a:argl')
|
||||
try:
|
||||
import jedi
|
||||
except ImportError:
|
||||
if jedi is None:
|
||||
print('Pyimport completion requires jedi module: https://github.com/davidhalter/jedi')
|
||||
comps = []
|
||||
else:
|
||||
text = 'import %s' % argl
|
||||
script = jedi.Script(text, 1, len(text), '', environment=get_environment())
|
||||
comps = ['%s%s' % (argl, c.complete) for c in script.completions()]
|
||||
names = get_project().complete_search(argl)
|
||||
comps = [argl + n for n in sorted(set(c.complete for c in names))]
|
||||
vim.command("return '%s'" % '\n'.join(comps))
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import sys
|
||||
|
||||
import vim
|
||||
from jedi_vim import PythonToVimStr
|
||||
from jedi_vim import PythonToVimStr, jedi
|
||||
|
||||
|
||||
def echo(msg):
|
||||
@@ -32,7 +32,15 @@ def format_exc_info(exc_info=None, tb_indent=2):
|
||||
return '{0}'.format(('\n' + indent).join(lines))
|
||||
|
||||
|
||||
def get_known_environments():
|
||||
"""Get known Jedi environments."""
|
||||
envs = list(jedi.find_virtualenvs())
|
||||
envs.extend(jedi.find_system_environments())
|
||||
return envs
|
||||
|
||||
|
||||
def display_debug_info():
|
||||
echo(' - global sys.executable: `{0}`'.format(sys.executable))
|
||||
echo(' - global sys.version: `{0}`'.format(
|
||||
', '.join([x.strip()
|
||||
for x in sys.version.split('\n')])))
|
||||
@@ -57,7 +65,8 @@ def display_debug_info():
|
||||
echo(' - version: {0}'.format(jedi_vim.jedi.__version__))
|
||||
|
||||
try:
|
||||
environment = jedi_vim.get_environment(use_cache=False)
|
||||
project = jedi_vim.get_project()
|
||||
environment = project.get_environment()
|
||||
except AttributeError:
|
||||
script_evaluator = jedi_vim.jedi.Script('')._evaluator
|
||||
try:
|
||||
@@ -80,7 +89,7 @@ def display_debug_info():
|
||||
|
||||
if environment:
|
||||
echo('\n##### Known environments\n\n')
|
||||
for environment in jedi_vim.get_known_environments():
|
||||
for environment in get_known_environments():
|
||||
echo(' - {0} ({1})\n'.format(
|
||||
environment,
|
||||
environment.executable,
|
||||
|
||||
Submodule pythonx/parso updated: c0ace63a69...ef90bba3b3
@@ -9,7 +9,7 @@ import zipfile
|
||||
|
||||
import pytest
|
||||
|
||||
vspec_version = '1.8.1'
|
||||
vspec_version = '1.9.0'
|
||||
|
||||
VSPEC_URL = 'https://github.com/kana/vim-vspec/archive/%s.zip' % vspec_version
|
||||
root = os.path.dirname(os.path.dirname(__file__))
|
||||
@@ -20,7 +20,7 @@ TEST_DIR = os.path.join(root, 'test', 'vspec')
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def install_vspec(request):
|
||||
def install_vspec():
|
||||
if not os.path.isdir(CACHE_FOLDER):
|
||||
os.mkdir(CACHE_FOLDER)
|
||||
|
||||
|
||||
29
test/vspec/choose-venv.vim
Normal file
29
test/vspec/choose-venv.vim
Normal file
@@ -0,0 +1,29 @@
|
||||
source plugin/jedi.vim
|
||||
source test/_utils.vim
|
||||
|
||||
describe 'simple:'
|
||||
before
|
||||
new
|
||||
normal! ifoo
|
||||
end
|
||||
|
||||
after
|
||||
bd!
|
||||
end
|
||||
|
||||
it 'choose'
|
||||
Expect g:jedi#environment_path == 'auto'
|
||||
Expect bufname('%') == ''
|
||||
|
||||
JediChooseEnvironment
|
||||
" A Python executable needs to be a few letters
|
||||
Expect len(getline('.')) > 5
|
||||
Expect bufname('%') == 'Hit Enter to Choose an Environment'
|
||||
|
||||
execute "normal \<CR>"
|
||||
Expect g:jedi#environment_path != 'auto'
|
||||
bd " TODO why is this necessary? There seems to be a random buffer.
|
||||
Expect bufname('%') == ''
|
||||
Expect getline('.') == 'foo'
|
||||
end
|
||||
end
|
||||
@@ -15,7 +15,10 @@ describe 'documentation docstrings'
|
||||
normal GK
|
||||
Expect bufname('%') == "__doc__"
|
||||
Expect &filetype == 'rst'
|
||||
let content = join(getline(1,'$'), "\n")
|
||||
let header = getline(1, 2)
|
||||
Expect header[0] == "Docstring for class builtins.ImportError"
|
||||
Expect header[1] == "========================================"
|
||||
let content = join(getline(3, '$'), "\n")
|
||||
Expect stridx(content, "Import can't find module") > 0
|
||||
normal K
|
||||
Expect bufname('%') == ''
|
||||
|
||||
@@ -73,27 +73,6 @@ describe 'goto with tabs:'
|
||||
Expect tabpagenr('$') == 1
|
||||
Expect bufname('%') == ''
|
||||
end
|
||||
|
||||
" it 'multi definitions'
|
||||
" " This used to behave differently. Now we don't have any real multi
|
||||
" " definitions.
|
||||
"
|
||||
" " put = ['import tokenize']
|
||||
" " 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
|
||||
" " normal G$\d
|
||||
" " execute "normal j\<CR>"
|
||||
" " Expect tabpagenr('$') == 2
|
||||
" " Expect winnr('$') == 1
|
||||
" " Expect CurrentBufferIsModule('tokenize') == 1
|
||||
" end
|
||||
end
|
||||
|
||||
|
||||
@@ -112,7 +91,7 @@ describe 'goto with buffers'
|
||||
put = ['import os']
|
||||
normal G$
|
||||
call jedi#goto_assignments()
|
||||
PythonJedi jedi_vim.goto()
|
||||
python3 jedi_vim.goto()
|
||||
Expect CurrentBufferIsModule('os') == 0
|
||||
" Without hidden, it's not possible to open a new buffer, when the old
|
||||
" one is not saved.
|
||||
@@ -124,25 +103,6 @@ describe 'goto with buffers'
|
||||
Expect line('.') == 1
|
||||
Expect col('.') == 1
|
||||
end
|
||||
|
||||
" it 'multi definitions'
|
||||
" " set hidden
|
||||
" " put = ['import tokenize']
|
||||
" " 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
|
||||
" " normal G$\d
|
||||
" " execute "normal j\<CR>"
|
||||
" " Expect tabpagenr('$') == 1
|
||||
" " Expect winnr('$') == 1
|
||||
" " Expect CurrentBufferIsModule('tokenize') == 1
|
||||
" end
|
||||
end
|
||||
|
||||
|
||||
|
||||
13
test/vspec/jedi_debug_info.vim
Normal file
13
test/vspec/jedi_debug_info.vim
Normal file
@@ -0,0 +1,13 @@
|
||||
source plugin/jedi.vim
|
||||
|
||||
describe 'JediDebugInfo'
|
||||
it 'works'
|
||||
redir @a | JediDebugInfo | redir END
|
||||
let output = split(@a, '\n')
|
||||
Expect output[0] == 'You should run this in a buffer with filetype "python".'
|
||||
Expect output[1] == '#### Jedi-vim debug information'
|
||||
Expect output[-1] == '</details>'
|
||||
end
|
||||
end
|
||||
|
||||
" vim: et:ts=4:sw=4
|
||||
@@ -4,10 +4,12 @@ source test/_utils.vim
|
||||
describe 'pyimport'
|
||||
before
|
||||
let g:jedi#use_tabs_not_buffers = 1
|
||||
let g:jedi#project_path = 'autoload'
|
||||
end
|
||||
|
||||
after
|
||||
try | %bwipeout! | catch | endtry
|
||||
unlet g:jedi#project_path
|
||||
end
|
||||
|
||||
it 'open_tab'
|
||||
@@ -26,10 +28,7 @@ describe 'pyimport'
|
||||
|
||||
Expect jedi#py_import_completions('subproc', 0, 0) == 'subprocess'
|
||||
Expect jedi#py_import_completions('subprocess', 0, 0) == 'subprocess'
|
||||
let g:comp = jedi#py_import_completions('zip', 0, 0)
|
||||
" Sometimes zipapp is in there sometimes not, depends on Python
|
||||
" version.
|
||||
let g:comp = substitute(g:comp, '^zipapp\n', '', '')
|
||||
Expect g:comp == "zipfile\nzipimport"
|
||||
let g:comp = jedi#py_import_completions('sre_', 0, 0)
|
||||
Expect g:comp == "sre_compile\nsre_constants\nsre_parse"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -41,12 +41,29 @@ describe 'signatures'
|
||||
doautocmd CursorHoldI
|
||||
noautocmd normal istaticmethod()
|
||||
doautocmd CursorHoldI
|
||||
Expect getline(1) == '?!?jedi=0, ?!? (*_*f: Callable*_*) ?!?jedi?!?'
|
||||
Expect getline(1) == '?!?jedi=0, ?!? (*_*f: Callable[..., Any]*_*) ?!?jedi?!?'
|
||||
end
|
||||
|
||||
it 'highlights correct argument'
|
||||
noautocmd normal o
|
||||
doautocmd CursorHoldI
|
||||
noautocmd normal iprint(42, sep="X", )
|
||||
" Move to "=" - hightlights "sep=...".
|
||||
noautocmd normal 5h
|
||||
doautocmd CursorHoldI
|
||||
Expect getline(1) =~# '\V\^?!?jedi=0, ?!? (*values: object, *_*sep: Optional[Text]=...*_*'
|
||||
" Move left to "=" - hightlights first argument ("values").
|
||||
" NOTE: it is arguable that maybe "sep=..." should be highlighted
|
||||
" still, but this tests for the cache to be "busted", and that
|
||||
" fresh results are retrieved from Jedi.
|
||||
noautocmd normal h
|
||||
doautocmd CursorHoldI
|
||||
Expect getline(1) =~# '\V\^?!?jedi=0, ?!? (*_**values: object*_*, sep: Optional[Text]=...,'
|
||||
end
|
||||
|
||||
it 'no signature'
|
||||
exe 'normal ostr '
|
||||
Python jedi_vim.show_call_signatures()
|
||||
python3 jedi_vim.show_call_signatures()
|
||||
Expect getline(1, '$') == ['', 'str ']
|
||||
end
|
||||
|
||||
@@ -54,7 +71,7 @@ describe 'signatures'
|
||||
let g:jedi#show_call_signatures = 0
|
||||
|
||||
exe 'normal ostr( '
|
||||
Python jedi_vim.show_call_signatures()
|
||||
python3 jedi_vim.show_call_signatures()
|
||||
Expect getline(1, '$') == ['', 'str( ']
|
||||
|
||||
let g:jedi#show_call_signatures = 1
|
||||
@@ -66,9 +83,9 @@ describe 'signatures'
|
||||
|
||||
exe 'normal ostaticmethod( '
|
||||
redir => msg
|
||||
Python jedi_vim.show_call_signatures()
|
||||
python3 jedi_vim.show_call_signatures()
|
||||
redir END
|
||||
Expect msg == "\nstaticmethod(f: Callable)"
|
||||
Expect msg == "\nstaticmethod(f: Callable[..., Any])"
|
||||
|
||||
redir => msg
|
||||
doautocmd InsertLeave
|
||||
@@ -78,7 +95,7 @@ describe 'signatures'
|
||||
normal Sdef foo(a, b): pass
|
||||
exe 'normal ofoo(a, b, c, '
|
||||
redir => msg
|
||||
Python jedi_vim.show_call_signatures()
|
||||
python3 jedi_vim.show_call_signatures()
|
||||
redir END
|
||||
Expect msg == "\nfoo(a, b)"
|
||||
end
|
||||
@@ -89,7 +106,7 @@ describe 'signatures'
|
||||
|
||||
function! Signature()
|
||||
redir => msg
|
||||
Python jedi_vim.show_call_signatures()
|
||||
python3 jedi_vim.show_call_signatures()
|
||||
redir END
|
||||
return msg
|
||||
endfunction
|
||||
@@ -122,7 +139,7 @@ describe 'signatures'
|
||||
|
||||
exe 'normal ostr '
|
||||
redir => msg
|
||||
Python jedi_vim.show_call_signatures()
|
||||
python3 jedi_vim.show_call_signatures()
|
||||
redir END
|
||||
Expect msg == "\n"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user