diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index 46cc12a2..ae75ee26 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -206,6 +206,19 @@ function! s:SetUpCompleteopt() endif 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() py ycm_state.OnVimLeave() py extra_conf_store.CallExtraConfVimCloseIfExists() @@ -213,6 +226,11 @@ endfunction function! s:OnBufferVisit() + " We need to do this even when we are not allowed to complete in the current + " file 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:AllowedToCompleteInCurrentFile() return endif @@ -247,7 +265,11 @@ endfunction function! s:OnFileReadyToParse() - py ycm_state.OnFileReadyToParse() + let buffer_changed = b:changedtick != b:ycm_changedtick.file_ready_to_parse + if buffer_changed + py ycm_state.OnFileReadyToParse() + endif + let b:ycm_changedtick.file_ready_to_parse = b:changedtick endfunction