Auto merge of #2801 - micbou:no-completefunc-call-if-no-candidates, r=bstaletic
[READY] Only call completion function if needed Currently, YCM calls the `completefunc` at each key press even if there are no candidates. This has the side effect of always keeping the user in completion mode while typing in insert mode, which causes the following issues: - the `<C-U>`, `<C-N>`, `<C-P>`, and `<C-E>` keys are not working as expected in insert mode when the completion menu is not visible; - automatic comment formatting is broken in some situations. See issue https://github.com/Valloric/YouCompleteMe/issues/2552. This is solved by only calling the `completefunc` if suggestions are available (or if the start column is not after the current column) and by closing the completion menu otherwise. Updates the `<C-U>` entry in the FAQ. Fixes https://github.com/Valloric/YouCompleteMe/issues/2552. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2801) <!-- Reviewable:end -->
This commit is contained in:
commit
daa0175fa6
@ -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
|
||||
|
||||
|
@ -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,25 +756,26 @@ endfunction
|
||||
|
||||
|
||||
function! s:Complete()
|
||||
" <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
|
||||
" 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>" )
|
||||
" 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
|
||||
" 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
|
||||
|
||||
|
||||
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
|
||||
|
@ -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*
|
||||
|
Loading…
Reference in New Issue
Block a user