Parse current buffer when server is ready

This commit is contained in:
micbou 2017-05-11 19:08:28 +02:00
parent d44ad0894b
commit 3ac2951c7b
No known key found for this signature in database
GPG Key ID: C7E8FD1F3BDA1E05
2 changed files with 34 additions and 32 deletions

View File

@ -30,6 +30,10 @@ let s:pollers = {
\ 'file_parse_response': { \ 'file_parse_response': {
\ 'id': -1, \ 'id': -1,
\ 'wait_milliseconds': 100 \ 'wait_milliseconds': 100
\ },
\ 'server_ready': {
\ 'id': -1,
\ 'wait_milliseconds': 100
\ } \ }
\ } \ }
@ -101,13 +105,11 @@ function! youcompleteme#Enable()
autocmd CompleteDone * call s:OnCompleteDone() autocmd CompleteDone * call s:OnCompleteDone()
augroup END augroup END
" The FileType event is not triggered for the first loaded file. However, we " The FileType event is not triggered for the first loaded file. We wait until
" don't directly call the s:OnFileTypeSet function because it would send " the server is ready to manually run the s:OnFileTypeSet function.
" requests that can't succeed as the server is not ready yet and would slow let s:pollers.server_ready.id = timer_start(
" down startup. \ s:pollers.server_ready.wait_milliseconds,
if s:AllowedToCompleteInCurrentBuffer() \ function( 's:PollServerReady' ) )
call s:SetCompleteFunc()
endif
endfunction endfunction
@ -457,25 +459,24 @@ function! s:OnBufferUnload()
endfunction endfunction
function! s:PollServerReady( timer_id )
if !s:Pyeval( 'ycm_state.IsServerReady()' )
let s:pollers.server_ready.id = timer_start(
\ s:pollers.server_ready.wait_milliseconds,
\ function( 's:PollServerReady' ) )
return
endif
call s:OnFileTypeSet()
endfunction
function! s:OnFileReadyToParse( ... ) function! s:OnFileReadyToParse( ... )
" Accepts an optional parameter that is either 0 or 1. If 1, send a " Accepts an optional parameter that is either 0 or 1. If 1, send a
" FileReadyToParse event notification, whether the buffer has changed or not; " FileReadyToParse event notification, whether the buffer has changed or not;
" effectively forcing a parse of the buffer. Default is 0. " effectively forcing a parse of the buffer. Default is 0.
let force_parsing = a:0 > 0 && a:1 let force_parsing = a:0 > 0 && a:1
if s:Pyeval( 'ycm_state.ServerBecomesReady()' )
" Server was not ready until now and could not parse previous requests for
" the current buffer. We need to send them again.
exec s:python_command "ycm_state.OnBufferVisit()"
exec s:python_command "ycm_state.OnFileReadyToParse()"
" Setting the omnifunc requires us to ask the server if it has a native
" semantic completer for the current buffer's filetype. Since we only set it
" when entering a buffer or changing the filetype, we try to set it again
" now that the server is ready.
call s:SetOmnicompleteFunc()
return
endif
" We only want to send a new FileReadyToParse event notification if the buffer " We only want to send a new FileReadyToParse event notification if the buffer
" has changed since the last time we sent one, or if forced. " has changed since the last time we sent one, or if forced.
if force_parsing || b:changedtick != get( b:, 'ycm_changedtick', -1 ) if force_parsing || b:changedtick != get( b:, 'ycm_changedtick', -1 )
@ -589,8 +590,6 @@ function! s:OnInsertEnter()
endif endif
let s:old_cursor_position = [] let s:old_cursor_position = []
call s:OnFileReadyToParse()
endfunction endfunction
@ -756,6 +755,10 @@ endfunction
function! s:RestartServer() function! s:RestartServer()
exec s:python_command "ycm_state.RestartServer()" exec s:python_command "ycm_state.RestartServer()"
call timer_stop( s:pollers.server_ready.id )
let s:pollers.server_ready.id = timer_start(
\ s:pollers.server_ready.wait_milliseconds,
\ function( 's:PollServerReady' ) )
endfunction endfunction

View File

@ -223,6 +223,14 @@ class YouCompleteMe( object ):
return return_code is None return return_code is None
def IsServerReady( self ):
if not self._server_is_ready_with_cache and self.IsServerAlive():
with HandleServerException( display = False ):
self._server_is_ready_with_cache = BaseRequest.GetDataFromHandler(
'ready' )
return self._server_is_ready_with_cache
def _NotifyUserIfServerCrashed( self ): def _NotifyUserIfServerCrashed( self ):
if self._user_notified_about_crash or self.IsServerAlive(): if self._user_notified_about_crash or self.IsServerAlive():
return return
@ -346,15 +354,6 @@ class YouCompleteMe( object ):
self.NativeFiletypeCompletionAvailable() ) self.NativeFiletypeCompletionAvailable() )
def ServerBecomesReady( self ):
if not self._server_is_ready_with_cache:
with HandleServerException( display = False ):
self._server_is_ready_with_cache = BaseRequest.GetDataFromHandler(
'ready' )
return self._server_is_ready_with_cache
return False
def OnFileReadyToParse( self ): def OnFileReadyToParse( self ):
if not self.IsServerAlive(): if not self.IsServerAlive():
self._NotifyUserIfServerCrashed() self._NotifyUserIfServerCrashed()
@ -766,7 +765,7 @@ class YouCompleteMe( object ):
if filetype in self._filetypes_with_keywords_loaded: if filetype in self._filetypes_with_keywords_loaded:
return return
if self._server_is_ready_with_cache: if self.IsServerReady():
self._filetypes_with_keywords_loaded.add( filetype ) self._filetypes_with_keywords_loaded.add( filetype )
extra_data[ 'syntax_keywords' ] = list( extra_data[ 'syntax_keywords' ] = list(
syntax_parse.SyntaxKeywordsForCurrentBuffer() ) syntax_parse.SyntaxKeywordsForCurrentBuffer() )