From 8c7161f4e9b0cd689152a23bf3fdc606c65f34f9 Mon Sep 17 00:00:00 2001 From: Konfekt Date: Thu, 10 Nov 2022 15:55:13 +0100 Subject: [PATCH 1/3] prefer popup over preview window --- doc/jedi-vim.txt | 9 ++++++--- ftplugin/python/jedi.vim | 9 +++++++-- plugin/jedi.vim | 7 ++++++- pythonx/jedi_vim.py | 2 +- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/doc/jedi-vim.txt b/doc/jedi-vim.txt index 3b94a6d..fa3d0c5 100644 --- a/doc/jedi-vim.txt +++ b/doc/jedi-vim.txt @@ -349,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 to in insert mode. @@ -388,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) diff --git a/ftplugin/python/jedi.vim b/ftplugin/python/jedi.vim index 5b97b9c..ac74a75 100644 --- a/ftplugin/python/jedi.vim +++ b/ftplugin/python/jedi.vim @@ -44,10 +44,15 @@ if g:jedi#auto_initialization inoremap =jedi#smart_auto_mappings() end - if g:jedi#auto_close_doc + if g:jedi#auto_close_doc && (&g:completeopt =~# '\' && &g:completeopt !~# '\') " close preview if its still open after insert augroup jedi_preview - autocmd! InsertLeave if pumvisible() == 0|pclose|endif + if v:version > 704 + autocmd CompleteDone * pclose + else + autocmd InsertLeave * if pumvisible() == 0|pclose|endif + autocmd CursorMovedI * if pumvisible() == 0|pclose|endif + endif augroup END endif endif diff --git a/plugin/jedi.vim b/plugin/jedi.vim index d409240..6297e4e 100644 --- a/plugin/jedi.vim +++ b/plugin/jedi.vim @@ -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') diff --git a/pythonx/jedi_vim.py b/pythonx/jedi_vim.py index b140668..7281dd1 100644 --- a/pythonx/jedi_vim.py +++ b/pythonx/jedi_vim.py @@ -360,7 +360,7 @@ 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), From 40c7f6d09d10ed5f7710d0fc4b729b00ba6ca571 Mon Sep 17 00:00:00 2001 From: Konfekt Date: Fri, 11 Nov 2022 10:19:14 +0100 Subject: [PATCH 2/3] split code line to pass check for line length --- pythonx/jedi_vim.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pythonx/jedi_vim.py b/pythonx/jedi_vim.py index 7281dd1..503d6a4 100644 --- a/pythonx/jedi_vim.py +++ b/pythonx/jedi_vim.py @@ -360,7 +360,9 @@ def completions(): completions = script.complete(*get_pos(column)) signatures = script.get_signatures(*get_pos(column)) - add_info = any(option in vim.eval("&completeopt").split(",") for option in ("preview", "popup")) + 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), From df261c0a3e411d299f4c8b5bf8fce508637d1111 Mon Sep 17 00:00:00 2001 From: Konfekt Date: Sat, 12 Nov 2022 10:32:44 +0100 Subject: [PATCH 3/3] remove slash to pass check for code quality --- pythonx/jedi_vim.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pythonx/jedi_vim.py b/pythonx/jedi_vim.py index 503d6a4..20b371d 100644 --- a/pythonx/jedi_vim.py +++ b/pythonx/jedi_vim.py @@ -361,7 +361,7 @@ def completions(): signatures = script.get_signatures(*get_pos(column)) add_info = \ - any(option in vim.eval("&completeopt").split(",") \ + any(option in vim.eval("&completeopt").split(",") for option in ("preview", "popup")) out = [] for c in completions: