Only call completefunc if needed

Do not call user's completion function if the start column is after the current
column or if there are no candidates. This avoids keeping the user in
completion mode even if there is no completion menu.
This commit is contained in:
micbou 2017-10-07 01:44:13 +02:00
parent bade99f5e9
commit 7e2e1e7d34
No known key found for this signature in database
GPG Key ID: C7E8FD1F3BDA1E05
3 changed files with 30 additions and 26 deletions

View File

@ -2825,11 +2825,10 @@ details. If you want to see which tag files YCM will read for a given buffer,
run `:echo tagfiles()` with the relevant buffer active. Note that that function run `:echo tagfiles()` with the relevant buffer active. Note that that function
will only list tag files that already exist. will only list tag files that already exist.
### `CTRL-U` in insert mode does not work ### `CTRL-U` in insert mode does not work while the completion menu is visible
YCM keeps you in a `completefunc` completion mode when you're typing in insert YCM uses `completefunc` completion mode to show suggestions and Vim disables
mode and Vim disables `<C-U>` in completion mode as a "feature." Sadly there's `<C-U>` in that mode as a "feature." Sadly there's nothing I can do about this.
nothing I can do about this.
### YCM conflicts with UltiSnips TAB key usage ### YCM conflicts with UltiSnips TAB key usage

View File

@ -546,14 +546,19 @@ function! s:SendKeys( keys )
endfunction endfunction
function! s:OnInsertChar() function! s:CloseCompletionMenu()
call timer_stop( s:pollers.completion.id )
if pumvisible() if pumvisible()
call s:SendKeys( "\<C-e>" ) call s:SendKeys( "\<C-e>" )
endif endif
endfunction endfunction
function! s:OnInsertChar()
call timer_stop( s:pollers.completion.id )
call s:CloseCompletionMenu()
endfunction
function! s:OnDeleteChar( key ) function! s:OnDeleteChar( key )
call timer_stop( s:pollers.completion.id ) call timer_stop( s:pollers.completion.id )
if pumvisible() if pumvisible()
@ -751,25 +756,26 @@ endfunction
function! s:Complete() function! s:Complete()
" <c-x><c-u> invokes the user's completion function (which we have set to " Do not call user's completion function if the start column is after the
" youcompleteme#CompleteFunc), and <c-p> tells Vim to select the previous " current column or if there are no candidates. Close the completion menu
" completion candidate. This is necessary because by default, Vim selects the " instead. This avoids keeping the user in completion mode.
" first candidate when completion is invoked, and selecting a candidate if s:completion.start_column > col( '.' ) || empty( s:completion.candidates )
" automatically replaces the current text with it. Calling <c-p> forces Vim to call s:CloseCompletionMenu()
" deselect the first candidate and in turn preserve the user's current text else
" until he explicitly chooses to replace it with a completion. " <c-x><c-u> invokes the user's completion function (which we have set to
call s:SendKeys( "\<C-X>\<C-U>\<C-P>" ) " youcompleteme#CompleteFunc), and <c-p> tells Vim to select the previous
" completion candidate. This is necessary because by default, Vim selects the
" first candidate when completion is invoked, and selecting a candidate
" automatically replaces the current text with it. Calling <c-p> forces Vim to
" deselect the first candidate and in turn preserve the user's current text
" until he explicitly chooses to replace it with a completion.
call s:SendKeys( "\<C-X>\<C-U>\<C-P>" )
endif
endfunction endfunction
function! youcompleteme#CompleteFunc( findstart, base ) function! youcompleteme#CompleteFunc( findstart, base )
if a:findstart if a:findstart
if s:completion.start_column > col( '.' ) ||
\ empty( s:completion.candidates )
" For vim, -2 means not found but don't trigger an error message.
" See :h complete-functions.
return -2
endif
return s:completion.start_column - 1 return s:completion.start_column - 1
endif endif
return s:completion.candidates return s:completion.candidates

View File

@ -148,7 +148,7 @@ Contents ~
15. I get 'Fatal Python error: PyThreadState_Get: no current thread' on startup |youcompleteme-i-get-fatal-python-error-pythreadstate_get-no-current-thread-on-startup| 15. I get 'Fatal Python error: PyThreadState_Get: no current thread' on startup |youcompleteme-i-get-fatal-python-error-pythreadstate_get-no-current-thread-on-startup|
16. 'install.py' says python must be compiled with '--enable-framework'. Wat? |youcompleteme-install.py-says-python-must-be-compiled-with-enable-framework-.-wat| 16. 'install.py' says python must be compiled with '--enable-framework'. Wat? |youcompleteme-install.py-says-python-must-be-compiled-with-enable-framework-.-wat|
17. YCM does not read identifiers from my tags files |youcompleteme-ycm-does-not-read-identifiers-from-my-tags-files| 17. YCM does not read identifiers from my tags files |youcompleteme-ycm-does-not-read-identifiers-from-my-tags-files|
18. 'CTRL-U' in insert mode does not work |youcompleteme-ctrl-u-in-insert-mode-does-not-work| 18. 'CTRL-U' in insert mode does not work while the completion menu is visible |youcompleteme-ctrl-u-in-insert-mode-does-not-work-while-completion-menu-is-visible|
19. YCM conflicts with UltiSnips TAB key usage |youcompleteme-ycm-conflicts-with-ultisnips-tab-key-usage| 19. YCM conflicts with UltiSnips TAB key usage |youcompleteme-ycm-conflicts-with-ultisnips-tab-key-usage|
20. Snippets added with ':UltiSnipsAddFiletypes' do not appear in the popup menu |youcompleteme-snippets-added-with-ultisnipsaddfiletypes-do-not-appear-in-popup-menu| 20. Snippets added with ':UltiSnipsAddFiletypes' do not appear in the popup menu |youcompleteme-snippets-added-with-ultisnipsaddfiletypes-do-not-appear-in-popup-menu|
21. Why isn't YCM just written in plain VimScript, FFS? |youcompleteme-why-isnt-ycm-just-written-in-plain-vimscript-ffs| 21. Why isn't YCM just written in plain VimScript, FFS? |youcompleteme-why-isnt-ycm-just-written-in-plain-vimscript-ffs|
@ -3087,12 +3087,11 @@ buffer, run ':echo tagfiles()' with the relevant buffer active. Note that that
function will only list tag files that already exist. function will only list tag files that already exist.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
*youcompleteme-ctrl-u-in-insert-mode-does-not-work* *youcompleteme-ctrl-u-in-insert-mode-does-not-work-while-completion-menu-is-visible*
'CTRL-U' in insert mode does not work ~ 'CTRL-U' in insert mode does not work while the completion menu is visible ~
YCM keeps you in a 'completefunc' completion mode when you're typing in insert YCM uses 'completefunc' completion mode to show suggestions and Vim disables
mode and Vim disables '<C-U>' in completion mode as a "feature." Sadly there's '<C-U>' in that mode as a "feature." Sadly there's nothing I can do about this.
nothing I can do about this.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
*youcompleteme-ycm-conflicts-with-ultisnips-tab-key-usage* *youcompleteme-ycm-conflicts-with-ultisnips-tab-key-usage*