36 Commits

Author SHA1 Message Date
Dave Halter
28a6765ecc Merge pull request #1093 from Konfekt/popup
prefer popup over preview window
2022-11-21 22:50:46 +00:00
Konfekt
df261c0a3e remove slash to pass check for code quality 2022-11-12 10:32:44 +01:00
Konfekt
40c7f6d09d split code line to pass check for line length 2022-11-11 10:29:45 +01:00
Konfekt
8c7161f4e9 prefer popup over preview window 2022-11-10 15:55:13 +01:00
Dave Halter
e82d07faa1 Merge pull request #1082 from jamescherti/buffer_jedi_added_sys_path
Add the buffer-local option 'b:jedi_added_sys_path'
2022-04-08 15:07:48 +02:00
James Cherti
50dfac448a Add 'g:jedi#added_sys_path' and 'b:jedi_added_sys_path' to the cache (cache_key). 2022-04-05 15:59:09 -04:00
James Cherti
0a27795d76 Add the buffer-local option 'b:jedi_added_sys_path' (to add additional sys_path). 2022-04-05 13:04:19 -04:00
Dave Halter
32d05f7742 Merge pull request #1076 from jamescherti/case-insensitive
Add option to enable/disable case insensitive completion
2022-01-30 12:33:41 +01:00
James Cherti
873ee9325d Add an option to enable/disable case insensitive completion.
Options:
- Global option: g:jedi#case_insensitive_completion
- Buffer-local option: b:jedi_case_insensitive_completion

Values:
- 0 to disable case insensitive completion.
- 1 to enable case insensitive completion (default).
2022-01-29 17:54:33 -05:00
Dave Halter
08ad42efed Merge pull request #1074 from blueyed/bump-parso
Update parso submodule to 0.8.3 (from 0.8.2)
2022-01-17 19:26:34 +01:00
Dave Halter
f5aad68bec Merge pull request #1073 from blueyed/fixup-1059
get_project: simplify getting b:jedi_environment_path override
2022-01-17 19:22:23 +01:00
Daniel Hahler
2c99d7377f Update submodule pythonx/parso 5edab04...ee5edaf
* pythonx/parso 5edab04...ee5edaf (13):
      > Prepare Release 0.8.3
      > Add a Python 3.12 grammar, because that is probably going to be needed in a year from now
      > Merge pull request #199 from sobolevn/patch-1
      > Merge pull request #195 from sturmianseq/fix
      > Jedi still has an import dependency on search_ancestor
      > Merge pull request #194 from mgorny/python310
      > Merge pull request #188 from davidhalter/line-ending
      > Fix flaky test_cache_last_used_update again (#189)
      > Add `NodeOrLeaf.dump()` and `NodeOrLeaf.search_ancestor()` (#187)
      > Add a grammar for Python 3.11 (just copied 3.10), so the core devs can work with it
      > Relax a test regex to match new enum repr in Python 3.10.0a7+ (#186)
      > Merge pull request #185 from davidhalter/switch-to-github-actions
      > Merge pull request #184 from davidhalter/remove-nocond-39
2022-01-17 17:21:36 +01:00
Daniel Hahler
7d2fc14f4f get_project: simplify getting b:jedi_environment_path override
- the common case is having an exception here (with no buffer setting),
  which results in the exception handler always
- vim_eval has overhead, especially with Neovim, so the less calls the
  better

This patch changes it to query the `b:` dict, using the (always
set/initialized) global setting as the default.
2022-01-17 14:56:29 +01:00
Dave Halter
e1afc904e4 Merge pull request #1072 from ThomasBlauth/default_setting
Fix added_sys_path default setting
2022-01-17 09:23:57 +01:00
Thomas Blauth
64c92771be Fix added_sys_path default setting
This commit removes the inner string quotation of the default value for the
added_sys_path setting. The inner quotes cause the value of the resulting
variable g:jedi#added_sys_path to be the sting "[]" instead of an empty list.
2022-01-17 08:40:54 +01:00
Dave Halter
030211555d Merge pull request #1068 from jgb/master
Update jedi to v0.18.1 and parso to v0.8.2
2021-11-17 22:33:56 +01:00
Jan Geboers
ab2550ef29 Update jedi to v0.18.1 and parso to v0.8.2 2021-11-17 15:45:26 +01:00
Volodymyr Kozachynskyi
7ac81cb880 doc: Add hint about python 2 support (#1060)
* doc: Add hint about python 2 support

* Update README.rst

Co-authored-by: Dave Halter <davidhalter88@gmail.com>
2021-06-22 22:45:23 +02:00
Dave Halter
6812ce11b7 Merge pull request #1059 from jamescherti/buffer_jedi_environment_path
The buffer-local variable `b:jedi_environment_path`
2021-06-22 21:34:08 +02:00
James Cherti
81002ed6e7 This commit fixes the exception: jedi_vim.VimError: Vim(let):E121: Undefined variable: b:jedi_environment_path; created by 'b:jedi_environment_path' 2021-06-22 13:42:11 -04:00
James Cherti
81e1e9ca34 The buffer-local variable b:jedi_environment_path was added to override the global variable g:jedi#environment_path. 2021-06-21 14:58:57 -04:00
Dave Halter
8763462331 Merge pull request #1049 from SeungChan92/master
Add missing item in manual index
2021-03-17 23:32:13 +01:00
Seung-Chan Ahn
760120240f Add missing item in manual index 2021-03-17 09:59:43 +09:00
Dave Halter
6e6738758f Merge pull request #1048 from SeungChan92/master
Support adding extra sys_path
2021-03-16 23:38:49 +01:00
Seung-Chan Ahn
ff9a0afbda Support adding extra sys_path 2021-03-15 14:36:20 +09:00
Dave Halter
088469a8ee Merge pull request #1045 from Konstantin-Glukhov/master
Use helper function relpath() instead of os.path.relpath()
2021-02-26 11:18:52 +01:00
Konstantin-Glukhov
8730095b89 Use helper function relpath() instead of os.path.relpath() to address
issue #1044 ("path is on mount %r, start on mount %r" exception thrown
on Windows if Python and jedi-vim are installed on different drives)
2021-02-16 04:25:02 +09:00
Dave Halter
5d4615707f Fix a refactoring error, fixes #1041 2021-01-30 15:38:01 +01:00
Dave Halter
960eaa8053 Typo
Co-authored-by: Daniel Hahler <git@thequod.de>
2021-01-03 03:06:44 +01:00
Dave Halter
acd9182131 Fix some comments in signature test 2021-01-03 03:06:44 +01:00
Dave Halter
04c708cbfc Useful examples for environment_path 2021-01-03 03:06:44 +01:00
Dave Halter
91312f1755 Run CI on pull requests 2021-01-03 03:06:44 +01:00
Dave Halter
e02fa9dc10 Upgrade Jedi to 8ef2ce232cebf6f30b41b28b2677d84666a97d55 2021-01-03 03:06:44 +01:00
Dave Halter
d7be014c54 Namespaces cannot be shown properly, fixes #815
This only works with Jedi commit 2ec3d72151d1072fa22861aef07ba6fc170e3781
Once using that commit, namespaces will be used properly.
2021-01-02 12:15:25 +01:00
Dave Halter
e96eba9f53 Use relative paths when accessing a buffer 2021-01-02 04:05:46 +01:00
Dave Halter
e4daf7a74c Fix a test around signatures that was failing sometimes 2021-01-02 04:05:24 +01:00
11 changed files with 137 additions and 49 deletions

View File

@@ -1,5 +1,5 @@
name: ci
on: push
on: [push, pull_request]
jobs:
tests:

View File

@@ -53,5 +53,9 @@ Tommy Allen (@tweekmonster)
Mingliang (@Aulddays)
Brian Mego (@brianmego)
Stevan Milic (@stevanmilic) <stevan.milic@yahoo.com>
Konstantin Glukhov (@Konstantin-Glukhov)
Seungchan An (@SeungChan92) <dev.issea1015@gmail.com>
Thomas Blauth (@ThomasBlauth) <thomas.blauth@protonmail.com>
James Cherti (@jamescherti)
@something are github user names.

View File

@@ -208,11 +208,18 @@ get more information. If you set them to ``""``, they are not assigned.
let g:jedi#completions_command = "<C-Space>"
let g:jedi#rename_command = "<leader>r"
A few examples of setting up your project:
An example for setting up your project:
.. code-block:: vim
let g:jedi#environment_path = "<leader>d"
let g:jedi#environment_path = "/usr/bin/python3.9"
jedi-vim tries its best to guess your virtual env. If you want to work with a
specific virtual environment however, you can point jedi-vim towards it:
.. code-block:: vim
let g:jedi#environment_path = "venv"
Finally, if you don't want completion, but all the other features, use:
@@ -223,6 +230,12 @@ Finally, if you don't want completion, but all the other features, use:
FAQ
===
I want to use Jedi with a Python 2 Environment, but it's not listed under "Known environments"
----------------------------------------------------------------------------------------------
Starting with version 0.18.0 Jedi dropped support for Python 2.
I don't want the docstring window to popup during completion
------------------------------------------------------------

View File

@@ -36,8 +36,10 @@ let s:default_settings = {
\ 'quickfix_window_height': 10,
\ 'force_py_version': "'auto'",
\ 'environment_path': "'auto'",
\ 'added_sys_path': '[]',
\ 'project_path': "'auto'",
\ 'smart_auto_mappings': 0,
\ 'case_insensitive_completion': 1,
\ 'use_tag_stack': 1
\ }
@@ -506,7 +508,7 @@ function! jedi#goto_window_on_enter() abort
if l:data.bufnr
" close goto_window buffer
normal! ZQ
python3 jedi_vim.new_buffer(vim.eval('bufname(l:data.bufnr)'))
python3 jedi_vim.set_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

View File

@@ -45,6 +45,11 @@ Contents *jedi-vim-contents*
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|
|b:jedi_environment_path|
6.16. added_sys_path |g:jedi#added_sys_path|
|b:jedi_added_sys_path|
6.17. case_insensitive_completion |g:jedi#case_insensitive_completion|
|b:jedi_case_insensitive_completion|
7. Testing |jedi-vim-testing|
8. Contributing |jedi-vim-contributing|
9. License |jedi-vim-license|
@@ -344,7 +349,8 @@ Default: 1 (Perform automatic initialization)
------------------------------------------------------------------------------
6.2. `g:jedi#auto_vim_configuration` *g:jedi#auto_vim_configuration*
Jedi-vim sets 'completeopt' to `menuone,longest,preview` by default, if
Jedi-vim sets 'completeopt' to `menuone,longest` and `popup` (for Vim version
numbers higher than 8.1.1882) respectively `preview` by default, if
'completeopt' is not changed from Vim's default.
It also remaps <Ctrl-C> to <Esc> in insert mode.
@@ -383,13 +389,15 @@ Default: 1 (Automatically select first completion entry)
------------------------------------------------------------------------------
6.5. `g:jedi#auto_close_doc` *g:jedi#auto_close_doc*
When doing completion, jedi-vim shows the docstring of the currently selected
item in a preview window. By default, this window is being closed after
When doing completion and jedi-vim shows the docstring of the currently selected
item in a preview (not a popup) window, this window is being closed after
insertion of a completion item.
Set this to 0 to leave the preview window open even after leaving insert mode.
This could be useful if you want to browse longer docstrings.
This setting is ignored if a popup instead of a preview window is used.
Options: 0 or 1
Default: 1 (Automatically close preview window upon leaving insert mode)
@@ -509,6 +517,7 @@ Default: 1 (enabled by default)
------------------------------------------------------------------------------
6.15. `g:jedi#environment_path` *g:jedi#environment_path*
*b:jedi_environment_path*
To use a specific virtualenv or a specific Python version it is possible to
set an interpreter.
@@ -516,8 +525,36 @@ set an interpreter.
Both setting the directory and setting a project is working.
Examples: "/usr/bin/python3.9", "venv", "../venv", "../venv/bin/python"
The buffer-local variable `b:jedi_environment_path` can be used to override the
global variable `g:jedi#environment_path`.
Default: "auto"
------------------------------------------------------------------------------
6.16. `g:jedi#added_sys_path` *g:jedi#added_sys_path*
*b:jedi_added_sys_path*
To add extra sys_path.
The buffer-local variable `b:jedi_added_sys_path` can be used to add
additional extra sys_path.
Examples: ["../site-packages"]
Default: []
------------------------------------------------------------------------------
6.17. `g:jedi#case_insensitive_completion` *g:jedi#case_insensitive_completion*
*b:jedi_case_insensitive_completion*
0 to disable case insensitive completion.
1 to enable case insensitive completion (default).
The buffer-local variable `b:jedi_case_insensitive_completion` can be used to
override the global variable `g:jedi#case_insensitive_completion`.
Default: 1
==============================================================================
7. Testing *jedi-vim-testing*

View File

@@ -44,10 +44,15 @@ if g:jedi#auto_initialization
inoremap <silent> <buffer> <space> <C-R>=jedi#smart_auto_mappings()<CR>
end
if g:jedi#auto_close_doc
if g:jedi#auto_close_doc && (&g:completeopt =~# '\<preview\>' && &g:completeopt !~# '\<popup\>')
" close preview if its still open after insert
augroup jedi_preview
autocmd! InsertLeave <buffer> if pumvisible() == 0|pclose|endif
if v:version > 704
autocmd CompleteDone <buffer> * pclose
else
autocmd InsertLeave <buffer> * if pumvisible() == 0|pclose|endif
autocmd CursorMovedI <buffer> * if pumvisible() == 0|pclose|endif
endif
augroup END
endif
endif

View File

@@ -33,7 +33,12 @@ if get(g:, 'jedi#auto_vim_configuration', 1)
redir END
endif
if len(split(completeopt, '\n')) == 1
set completeopt=menuone,longest,preview
set completeopt=menuone,longest
if v:version > 801 || (v:version == 801 && has('patch-8.1.1882'))
set completeopt+=popup
else
set completeopt+=preview
endif
endif
endfunction
if has('nvim')

View File

@@ -4,12 +4,14 @@ The Python parts of the Jedi library for VIM. It is mostly about communicating
with VIM.
"""
from typing import Optional
import traceback # for exception output
import re
import os
import sys
from shlex import split as shsplit
from contextlib import contextmanager
from pathlib import Path
try:
from itertools import zip_longest
except ImportError:
@@ -216,11 +218,18 @@ _current_project_cache = None, None
def get_project():
vim_environment_path = vim_eval("g:jedi#environment_path")
vim_environment_path = vim_eval(
"get(b:, 'jedi_environment_path', g:jedi#environment_path)"
)
vim_project_path = vim_eval("g:jedi#project_path")
vim_added_sys_path = vim_eval("get(g:, 'jedi#added_sys_path', [])")
vim_added_sys_path += vim_eval("get(b:, 'jedi_added_sys_path', [])")
global _current_project_cache
cache_key = dict(project_path=vim_project_path, environment_path=vim_environment_path)
cache_key = dict(project_path=vim_project_path,
environment_path=vim_environment_path,
added_sys_path=vim_added_sys_path)
if cache_key == _current_project_cache[0]:
return _current_project_cache[1]
@@ -234,7 +243,9 @@ def get_project():
else:
project_path = vim_project_path
project = jedi.Project(project_path, environment_path=environment_path)
project = jedi.Project(project_path,
environment_path=environment_path,
added_sys_path=vim_added_sys_path)
_current_project_cache = cache_key, project
return project
@@ -283,7 +294,9 @@ def load_project():
project.save()
global _current_project_cache
cache_key = dict(project_path=path, environment_path=env_path)
cache_key = dict(project_path=path,
environment_path=env_path,
added_sys_path=[])
_current_project_cache = cache_key, project
@@ -314,6 +327,10 @@ def get_pos(column=None):
@_check_jedi_availability(show_error=False)
@catch_and_print_exceptions
def completions():
jedi.settings.case_insensitive_completion = \
bool(int(vim_eval("get(b:, 'jedi_case_insensitive_completion', "
"g:jedi#case_insensitive_completion)")))
row, column = vim.current.window.cursor
# Clear call signatures in the buffer so they aren't seen by the completer.
# Call signatures in the command line can stay.
@@ -343,7 +360,9 @@ def completions():
completions = script.complete(*get_pos(column))
signatures = script.get_signatures(*get_pos(column))
add_info = "preview" in vim.eval("&completeopt").split(",")
add_info = \
any(option in vim.eval("&completeopt").split(",")
for option in ("preview", "popup"))
out = []
for c in completions:
d = dict(word=PythonToVimStr(c.name[:len(base)] + c.complete),
@@ -418,21 +437,22 @@ def _goto_specific_name(n, options=''):
if n.is_keyword:
echo_highlight("Cannot get the definition of Python keywords.")
else:
echo_highlight("Builtin modules cannot be displayed (%s)."
% (n.full_name or n.name))
name = 'Namespaces' if n.type == 'namespace' else 'Builtin modules'
echo_highlight(
"%s cannot be displayed (%s)."
% (name, n.full_name or n.name)
)
else:
using_tagstack = int(vim_eval('g:jedi#use_tag_stack')) == 1
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 module_path and
os.path.exists(module_path)):
result = set_buffer(n.module_path, options=options,
using_tagstack=using_tagstack)
if not result:
return []
if (using_tagstack and n.module_path and
n.module_path.exists()):
tagname = n.name
with tempfile('{0}\t{1}\t{2}'.format(
tagname, module_path, 'call cursor({0}, {1})'.format(
tagname, n.module_path, 'call cursor({0}, {1})'.format(
n.line, n.column + 1))) as f:
old_tags = vim.eval('&tags')
old_wildignore = vim.eval('&wildignore')
@@ -1050,14 +1070,10 @@ def do_rename(replace, orig=None):
if r.in_builtin_module():
continue
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!' % (
module_path))
continue
result = set_buffer(r.module_path)
if not result:
echo_highlight('Failed to create buffer window for %s!' % (r.module_path))
continue
buffers.add(vim.current.buffer.name)
@@ -1103,7 +1119,17 @@ def py_import_completions():
@catch_and_print_exceptions
def new_buffer(path, options='', using_tagstack=False):
def set_buffer(path: Optional[Path], options='', using_tagstack=False):
"""
Opens a new buffer if we have to or does nothing. Returns True in case of
success.
"""
path = str(path or '')
# Check both, because it might be an empty string
if path in (vim.current.buffer.name, os.path.abspath(vim.current.buffer.name)):
return True
path = relpath(path)
# options are what you can to edit the edit options
if int(vim_eval('g:jedi#use_tabs_not_buffers')) == 1:
_tabnew(path, options)
@@ -1151,7 +1177,6 @@ def _tabnew(path, options=''):
:param options: `:tabnew` options, read vim help.
"""
path = os.path.abspath(path)
if int(vim_eval('has("gui")')) == 1:
vim_command('tab drop %s %s' % (options, escape_file_path(path)))
return
@@ -1166,7 +1191,7 @@ def _tabnew(path, options=''):
# don't know why this happens :-)
pass
else:
if buf_path == path:
if os.path.abspath(buf_path) == os.path.abspath(path):
# tab exists, just switch to that tab
vim_command('tabfirst | tabnext %i' % (tab_nr + 1))
# Goto the buffer's window.

View File

@@ -47,18 +47,15 @@ describe 'signatures'
it 'highlights correct argument'
noautocmd normal o
doautocmd CursorHoldI
noautocmd normal iprint(42, sep="X", )
" Move to "=" - hightlights "sep=...".
noautocmd normal 5h
noautocmd normal iformat(42, "x")
" Move to x - highlights "x".
noautocmd normal 2h
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
Expect getline(1) == '?!?jedi=0, ?!? (value: object, *_*format_spec: str=...*_*) ?!?jedi?!?'
" Move left to 42 - hightlights first argument ("value").
noautocmd normal 4h
doautocmd CursorHoldI
Expect getline(1) =~# '\V\^?!?jedi=0, ?!? (*_**values: object*_*, sep: Optional[Text]=...,'
Expect getline(1) == '?!?jedi=0, ?!? (*_*value: object*_*, format_spec: str=...) ?!?jedi?!?'
end
it 'no signature'