From 1b72bc2fbf927eea4b4ff69a74ca4418172d53e5 Mon Sep 17 00:00:00 2001 From: Francisco Lopes Date: Sat, 2 Jan 2016 21:44:36 -0200 Subject: [PATCH] Use native TextChangedI instead of an emulation. Long and personal experience, when TextChangedI gets used, YCM seems to perform better, diagnostics will trigger much less frequently at inappropriate occasions, even less with whitespace agnostic triggers, if I recall correctly... --- autoload/youcompleteme.vim | 46 +++++++------------------------------- 1 file changed, 8 insertions(+), 38 deletions(-) diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index 4caa7fad..13696ffa 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -27,7 +27,6 @@ let s:defer_omnifunc = 1 let s:old_cursor_position = [] let s:cursor_moved = 0 let s:moved_vertically_in_insert_mode = 0 -let s:previous_num_chars_on_current_line = strlen( getline('.') ) let s:previous_allowed_buffer_number = 0 @@ -125,17 +124,16 @@ endfunction function! youcompleteme#EnableCursorMovedAutocommands() - augroup ycmcompletemecursormove - autocmd! - autocmd CursorMovedI * call s:OnCursorMovedInsertMode() - autocmd CursorMoved * call s:OnCursorMovedNormalMode() - augroup END + augroup ycmcompletemecursormove + autocmd! + autocmd CursorMoved * call s:OnCursorMovedNormalMode() + autocmd TextChangedI * call s:OnTextChangedInsertMode() + augroup END endfunction function! youcompleteme#DisableCursorMovedAutocommands() - autocmd! ycmcompletemecursormove CursorMoved * - autocmd! ycmcompletemecursormove CursorMovedI * + autocmd! ycmcompletemecursormove endfunction @@ -533,7 +531,8 @@ function! s:SetOmnicompleteFunc() endif endfunction -function! s:OnCursorMovedInsertMode() + +function! s:OnTextChangedInsertMode() if !s:AllowedToCompleteInCurrentBuffer() return endif @@ -541,17 +540,6 @@ function! s:OnCursorMovedInsertMode() exec s:python_command "ycm_state.OnCursorMoved()" call s:UpdateCursorMoved() - " Basically, we need to only trigger the completion menu when the user has - " inserted or deleted a character, NOT just when the user moves in insert mode - " (with, say, the arrow keys). If we trigger the menu even on pure moves, then - " it's impossible to move in insert mode since the up/down arrows start moving - " the selected completion in the completion menu. Yeah, people shouldn't be - " moving in insert mode at all (that's what normal mode is for) but explain - " that to the users who complain... - if !s:BufferTextChangedSinceLastMoveInInsertMode() - return - endif - call s:IdentifierFinishedOperations() if g:ycm_autoclose_preview_window_after_completion call s:ClosePreviewWindowIfNeeded() @@ -596,8 +584,6 @@ endfunction function! s:OnInsertEnter() - let s:previous_num_chars_on_current_line = strlen( getline('.') ) - if !s:AllowedToCompleteInCurrentBuffer() return endif @@ -617,22 +603,6 @@ function! s:UpdateCursorMoved() endfunction -function! s:BufferTextChangedSinceLastMoveInInsertMode() - let num_chars_in_current_cursor_line = strlen( getline('.') ) - - if s:moved_vertically_in_insert_mode - let s:previous_num_chars_on_current_line = num_chars_in_current_cursor_line - return 0 - endif - - let changed_text_on_current_line = num_chars_in_current_cursor_line != - \ s:previous_num_chars_on_current_line - let s:previous_num_chars_on_current_line = num_chars_in_current_cursor_line - - return changed_text_on_current_line -endfunction - - function! s:ClosePreviewWindowIfNeeded() let current_buffer_name = bufname('')