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
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
mode and Vim disables `<C-U>` in completion mode as a "feature." Sadly there's
nothing I can do about this.
YCM uses `completefunc` completion mode to show suggestions and Vim disables
`<C-U>` in that mode as a "feature." Sadly there's nothing I can do about this.
### YCM conflicts with UltiSnips TAB key usage

View File

@ -546,14 +546,19 @@ function! s:SendKeys( keys )
endfunction
function! s:OnInsertChar()
call timer_stop( s:pollers.completion.id )
function! s:CloseCompletionMenu()
if pumvisible()
call s:SendKeys( "\<C-e>" )
endif
endfunction
function! s:OnInsertChar()
call timer_stop( s:pollers.completion.id )
call s:CloseCompletionMenu()
endfunction
function! s:OnDeleteChar( key )
call timer_stop( s:pollers.completion.id )
if pumvisible()
@ -751,6 +756,12 @@ endfunction
function! s:Complete()
" Do not call user's completion function if the start column is after the
" current column or if there are no candidates. Close the completion menu
" instead. This avoids keeping the user in completion mode.
if s:completion.start_column > col( '.' ) || empty( s:completion.candidates )
call s:CloseCompletionMenu()
else
" <c-x><c-u> invokes the user's completion function (which we have set to
" youcompleteme#CompleteFunc), and <c-p> tells Vim to select the previous
" completion candidate. This is necessary because by default, Vim selects the
@ -759,17 +770,12 @@ function! s:Complete()
" 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
function! youcompleteme#CompleteFunc( findstart, base )
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
endif
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|
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|
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|
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|
@ -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.
-------------------------------------------------------------------------------
*youcompleteme-ctrl-u-in-insert-mode-does-not-work*
'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 while the completion menu is visible ~
YCM keeps you in a 'completefunc' completion mode when you're typing in insert
mode and Vim disables '<C-U>' in completion mode as a "feature." Sadly there's
nothing I can do about this.
YCM uses 'completefunc' completion mode to show suggestions and Vim disables
'<C-U>' in that mode as a "feature." Sadly there's nothing I can do about this.
-------------------------------------------------------------------------------
*youcompleteme-ycm-conflicts-with-ultisnips-tab-key-usage*