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...
This commit is contained in:
Francisco Lopes 2016-01-02 21:44:36 -02:00
parent 6bafb6c272
commit 1b72bc2fbf

View File

@ -27,7 +27,6 @@ let s:defer_omnifunc = 1
let s:old_cursor_position = [] let s:old_cursor_position = []
let s:cursor_moved = 0 let s:cursor_moved = 0
let s:moved_vertically_in_insert_mode = 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 let s:previous_allowed_buffer_number = 0
@ -125,17 +124,16 @@ endfunction
function! youcompleteme#EnableCursorMovedAutocommands() function! youcompleteme#EnableCursorMovedAutocommands()
augroup ycmcompletemecursormove augroup ycmcompletemecursormove
autocmd! autocmd!
autocmd CursorMovedI * call s:OnCursorMovedInsertMode() autocmd CursorMoved * call s:OnCursorMovedNormalMode()
autocmd CursorMoved * call s:OnCursorMovedNormalMode() autocmd TextChangedI * call s:OnTextChangedInsertMode()
augroup END augroup END
endfunction endfunction
function! youcompleteme#DisableCursorMovedAutocommands() function! youcompleteme#DisableCursorMovedAutocommands()
autocmd! ycmcompletemecursormove CursorMoved * autocmd! ycmcompletemecursormove
autocmd! ycmcompletemecursormove CursorMovedI *
endfunction endfunction
@ -533,7 +531,8 @@ function! s:SetOmnicompleteFunc()
endif endif
endfunction endfunction
function! s:OnCursorMovedInsertMode()
function! s:OnTextChangedInsertMode()
if !s:AllowedToCompleteInCurrentBuffer() if !s:AllowedToCompleteInCurrentBuffer()
return return
endif endif
@ -541,17 +540,6 @@ function! s:OnCursorMovedInsertMode()
exec s:python_command "ycm_state.OnCursorMoved()" exec s:python_command "ycm_state.OnCursorMoved()"
call s:UpdateCursorMoved() 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() call s:IdentifierFinishedOperations()
if g:ycm_autoclose_preview_window_after_completion if g:ycm_autoclose_preview_window_after_completion
call s:ClosePreviewWindowIfNeeded() call s:ClosePreviewWindowIfNeeded()
@ -596,8 +584,6 @@ endfunction
function! s:OnInsertEnter() function! s:OnInsertEnter()
let s:previous_num_chars_on_current_line = strlen( getline('.') )
if !s:AllowedToCompleteInCurrentBuffer() if !s:AllowedToCompleteInCurrentBuffer()
return return
endif endif
@ -617,22 +603,6 @@ function! s:UpdateCursorMoved()
endfunction 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() function! s:ClosePreviewWindowIfNeeded()
let current_buffer_name = bufname('') let current_buffer_name = bufname('')