Refactor b:ycm_changedtick variable

This commit is contained in:
micbou 2017-03-06 07:32:03 +01:00
parent afd4071d03
commit 8af0f5183e
No known key found for this signature in database
GPG Key ID: C7E8FD1F3BDA1E05

View File

@ -404,18 +404,6 @@ function! s:SetUpCompleteopt()
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', {
\ 'file_ready_to_parse' : -1,
\ } )
endfunction
function! s:OnVimLeave()
exec s:python_command "ycm_state.OnVimLeave()"
endfunction
@ -427,11 +415,6 @@ endfunction
function! s:OnBufferRead()
" We need to do this even when we are not allowed to complete in the current
" buffer because we might be allowed to complete in the future! The canonical
" example is creating a new buffer with :enew and then setting a filetype.
call s:SetUpYcmChangedTick()
if !s:AllowedToCompleteInCurrentBuffer()
return
endif
@ -496,21 +479,18 @@ function! s:OnFileReadyToParse()
return
endif
" We need to call this just in case there is no b:ycm_changetick; this can
" happen for special buffers.
call s:SetUpYcmChangedTick()
" Order is important here; we need to extract any information before
" reparsing the file again. If we sent the new parse request first, then
" the response would always be pending when we called
" HandleFileParseRequest.
exec s:python_command "ycm_state.HandleFileParseRequest()"
let buffer_changed = b:changedtick != b:ycm_changedtick.file_ready_to_parse
if buffer_changed
" We only want to send a new FileReadyToParse event notification if the buffer
" has changed since the last time we sent one.
if b:changedtick != get( b:, 'ycm_changedtick', -1 )
exec s:python_command "ycm_state.OnFileReadyToParse()"
let b:ycm_changedtick = b:changedtick
endif
let b:ycm_changedtick.file_ready_to_parse = b:changedtick
endfunction