Skip to content

Commit

Permalink
prefer popup over preview window
Browse files Browse the repository at this point in the history
  • Loading branch information
Konfekt committed Nov 10, 2022
1 parent e82d07f commit 8c7161f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
9 changes: 6 additions & 3 deletions doc/jedi-vim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Ctrl-C> to <Esc> in insert mode.

Expand Down Expand Up @@ -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)

Expand Down
9 changes: 7 additions & 2 deletions ftplugin/python/jedi.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion plugin/jedi.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion pythonx/jedi_vim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 8c7161f

Please sign in to comment.