forked from VimPlug/jedi-vim
Refactor completeopt handling
Temporarily set &completeopt before triggering automatic completion, instead of handling different settings afterwards. `g:jedi#popup_select_first` is used to use `noinsert` instead of `noselect`. Fixes https://github.com/davidhalter/jedi-vim/issues/516. Fixes https://github.com/davidhalter/jedi-vim/issues/706.
This commit is contained in:
@@ -582,31 +582,36 @@ function! s:save_first_col() abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
function! jedi#complete_string(is_popup_on_dot) abort
|
function! jedi#complete_string(autocomplete) abort
|
||||||
if a:is_popup_on_dot && !(g:jedi#popup_on_dot && jedi#do_popup_on_dot_in_highlight())
|
if a:autocomplete
|
||||||
return ''
|
if !(g:jedi#popup_on_dot && jedi#do_popup_on_dot_in_highlight())
|
||||||
endif
|
return ''
|
||||||
if pumvisible() && !a:is_popup_on_dot
|
endif
|
||||||
|
|
||||||
|
let s:saved_completeopt = &completeopt
|
||||||
|
set completeopt-=longest
|
||||||
|
set completeopt+=menuone
|
||||||
|
set completeopt-=menu
|
||||||
|
if &completeopt !~# 'noinsert\|noselect'
|
||||||
|
if g:jedi#popup_select_first
|
||||||
|
set completeopt+=noinsert
|
||||||
|
else
|
||||||
|
set completeopt+=noselect
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
elseif pumvisible()
|
||||||
return "\<C-n>"
|
return "\<C-n>"
|
||||||
else
|
|
||||||
return "\<C-x>\<C-o>\<C-r>=jedi#complete_opened(".a:is_popup_on_dot.")\<CR>"
|
|
||||||
endif
|
endif
|
||||||
|
return "\<C-x>\<C-o>\<C-r>=jedi#complete_opened(".a:autocomplete.")\<CR>"
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
function! jedi#complete_opened(is_popup_on_dot) abort
|
function! jedi#complete_opened(autocomplete) abort
|
||||||
if pumvisible()
|
if a:autocomplete
|
||||||
" Only go down if it is visible, user-enabled and the longest
|
let &completeopt = s:saved_completeopt
|
||||||
" option is set.
|
unlet s:saved_completeopt
|
||||||
if g:jedi#popup_select_first && stridx(&completeopt, 'longest') > -1
|
elseif pumvisible() && g:jedi#popup_select_first && stridx(&completeopt, 'longest') > -1
|
||||||
return "\<Down>"
|
return "\<Down>"
|
||||||
endif
|
|
||||||
if a:is_popup_on_dot
|
|
||||||
if &completeopt !~# '\(noinsert\|noselect\)'
|
|
||||||
" Prevent completion of the first entry with dot completion.
|
|
||||||
return "\<C-p>"
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
return ''
|
return ''
|
||||||
endfunction
|
endfunction
|
||||||
@@ -616,7 +621,7 @@ function! jedi#smart_auto_mappings() abort
|
|||||||
" Auto put import statement after from module.name<space> and complete
|
" Auto put import statement after from module.name<space> and complete
|
||||||
if search('\m^\s*from\s\+[A-Za-z0-9._]\{1,50}\%#\s*$', 'bcn', line('.'))
|
if search('\m^\s*from\s\+[A-Za-z0-9._]\{1,50}\%#\s*$', 'bcn', line('.'))
|
||||||
" Enter character and start completion.
|
" Enter character and start completion.
|
||||||
return "\<space>import \<C-x>\<C-o>\<C-r>=jedi#complete_opened(1)\<CR>"
|
return "\<space>import \<C-r>=jedi#complete_string(1)\<CR>"
|
||||||
endif
|
endif
|
||||||
return "\<space>"
|
return "\<space>"
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
Reference in New Issue
Block a user