Using b:changedtick for change detection

For now, doing it just for detecting whether a change was made on move in insert
mode.

Using b:changedtick instead of our homebrew way of detecting the changed should
be both faster and more robust.
This commit is contained in:
Strahinja Val Markovic 2013-08-03 15:05:25 -07:00
parent cb89c3f477
commit edae6fd0a2

View File

@ -28,8 +28,6 @@ let s:omnifunc_mode = 0
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:previous_num_chars_on_current_line = -1
function! youcompleteme#Enable() function! youcompleteme#Enable()
" When vim is in diff mode, don't run " When vim is in diff mode, don't run
@ -206,6 +204,20 @@ function! s:SetUpCompleteopt()
endif endif
endfunction endfunction
" For various functions/use-cases, we want to keep track of whether the buffer
" has changed since the last time they were invoked. We keep the state of
" b:changedtick of the last time the specific function was called in
" b:ycm_changedtick.
function! s:SetUpYcmChangedTick()
let b:ycm_changedtick =
\ get( b:, 'ycm_changedtick', {
\ 'insert_mode_move' : -1,
\ 'file_ready_to_parse' : -1,
\ } )
endfunction
function! s:OnVimLeave() function! s:OnVimLeave()
py ycm_state.OnVimLeave() py ycm_state.OnVimLeave()
py extra_conf_store.CallExtraConfVimCloseIfExists() py extra_conf_store.CallExtraConfVimCloseIfExists()
@ -217,6 +229,7 @@ function! s:OnBufferVisit()
return return
endif endif
call s:SetUpYcmChangedTick()
call s:SetUpCompleteopt() call s:SetUpCompleteopt()
call s:SetCompleteFunc() call s:SetCompleteFunc()
py ycm_state.OnBufferVisit() py ycm_state.OnBufferVisit()
@ -340,23 +353,9 @@ endfunction
function! s:BufferTextChangedSinceLastMoveInInsertMode() function! s:BufferTextChangedSinceLastMoveInInsertMode()
if s:moved_vertically_in_insert_mode let buffer_changed = b:changedtick != b:ycm_changedtick.insert_mode_move
let s:previous_num_chars_on_current_line = -1 let b:ycm_changedtick.insert_mode_move = b:changedtick
return 0 return buffer_changed
endif
let num_chars_in_current_cursor_line = strlen( getline('.') )
if s:previous_num_chars_on_current_line == -1
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 endfunction