Removed current buffer caching approach.
This commit is contained in:
parent
e5b0565d1a
commit
a70755aa40
@ -105,9 +105,6 @@ function! youcompleteme#Enable()
|
||||
autocmd CompleteDone * call s:OnCompleteDone()
|
||||
augroup END
|
||||
|
||||
" The BufEnter event is not triggered for the first loaded file.
|
||||
exec s:python_command "ycm_state.SetCurrentBuffer()"
|
||||
|
||||
" The FileType event is not triggered for the first loaded file. We wait until
|
||||
" the server is ready to manually run the s:OnFileTypeSet function.
|
||||
let s:pollers.server_ready.id = timer_start(
|
||||
@ -420,8 +417,6 @@ endfunction
|
||||
|
||||
|
||||
function! s:OnFileTypeSet()
|
||||
exec s:python_command "ycm_state.SetCurrentBuffer()"
|
||||
|
||||
if !s:AllowedToCompleteInCurrentBuffer()
|
||||
return
|
||||
endif
|
||||
@ -436,8 +431,6 @@ endfunction
|
||||
|
||||
|
||||
function! s:OnBufferEnter()
|
||||
exec s:python_command "ycm_state.SetCurrentBuffer()"
|
||||
|
||||
if !s:VisitedBufferRequiresReparse()
|
||||
return
|
||||
endif
|
||||
|
@ -193,10 +193,9 @@ class DiagnosticInterface( object ):
|
||||
for diag in self._diagnostics:
|
||||
location = diag[ 'location' ]
|
||||
bufnr = vimsupport.GetBufferNumberForFilename( location[ 'filepath' ] )
|
||||
if bufnr != self._bufnr:
|
||||
continue
|
||||
line_number = location[ 'line_num' ]
|
||||
self._line_to_diags[ line_number ].append( diag )
|
||||
if bufnr == self._bufnr:
|
||||
line_number = location[ 'line_num' ]
|
||||
self._line_to_diags[ line_number ].append( diag )
|
||||
|
||||
for diags in itervalues( self._line_to_diags ):
|
||||
# We also want errors to be listed before warnings so that errors aren't
|
||||
|
@ -59,7 +59,7 @@ def UnplaceSign_Call( sign_id, buffer_num ):
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def MockArbitraryBuffer( filetype, ycm ):
|
||||
def MockArbitraryBuffer( filetype ):
|
||||
"""Used via the with statement, set up a single buffer with an arbitrary name
|
||||
and no contents. Its filetype is set to the supplied filetype."""
|
||||
|
||||
@ -68,7 +68,7 @@ def MockArbitraryBuffer( filetype, ycm ):
|
||||
window = 1,
|
||||
filetype = filetype )
|
||||
|
||||
with MockVimBuffers( [ current_buffer ], current_buffer, ycm_state = ycm ):
|
||||
with MockVimBuffers( [ current_buffer ], current_buffer ):
|
||||
yield
|
||||
|
||||
|
||||
@ -124,7 +124,7 @@ def EventNotification_FileReadyToParse_NonDiagnostic_Error_test(
|
||||
def ErrorResponse( *args ):
|
||||
raise ServerError( ERROR_TEXT )
|
||||
|
||||
with MockArbitraryBuffer( 'javascript', ycm ):
|
||||
with MockArbitraryBuffer( 'javascript' ):
|
||||
with MockEventNotification( ErrorResponse ):
|
||||
ycm.OnFileReadyToParse()
|
||||
ok_( ycm.FileParseRequestReady() )
|
||||
@ -156,7 +156,7 @@ def EventNotification_FileReadyToParse_NonDiagnostic_Error_test(
|
||||
def EventNotification_FileReadyToParse_NonDiagnostic_Error_NonNative_test(
|
||||
ycm, vim_command ):
|
||||
|
||||
with MockArbitraryBuffer( 'javascript', ycm ):
|
||||
with MockArbitraryBuffer( 'javascript' ):
|
||||
with MockEventNotification( None, False ):
|
||||
ycm.OnFileReadyToParse()
|
||||
ycm.HandleFileParseRequest()
|
||||
@ -182,7 +182,7 @@ def EventNotification_FileReadyToParse_NonDiagnostic_ConfirmExtraConf_test(
|
||||
def UnknownExtraConfResponse( *args ):
|
||||
raise UnknownExtraConf( FILE_NAME )
|
||||
|
||||
with MockArbitraryBuffer( 'javascript', ycm ):
|
||||
with MockArbitraryBuffer( 'javascript' ):
|
||||
with MockEventNotification( UnknownExtraConfResponse ):
|
||||
|
||||
# When the user accepts the extra conf, we load it
|
||||
@ -282,7 +282,7 @@ def _Check_FileReadyToParse_Diagnostic_Error( ycm, vim_command ):
|
||||
diagnostic = Diagnostic( [], start, extent, 'expected ;', 'ERROR' )
|
||||
return [ BuildDiagnosticData( diagnostic ) ]
|
||||
|
||||
with MockArbitraryBuffer( 'cpp', ycm ):
|
||||
with MockArbitraryBuffer( 'cpp' ):
|
||||
with MockEventNotification( DiagnosticResponse ):
|
||||
ycm.OnFileReadyToParse()
|
||||
ok_( ycm.FileParseRequestReady() )
|
||||
@ -314,7 +314,7 @@ def _Check_FileReadyToParse_Diagnostic_Warning( ycm, vim_command ):
|
||||
diagnostic = Diagnostic( [], start, extent, 'cast', 'WARNING' )
|
||||
return [ BuildDiagnosticData( diagnostic ) ]
|
||||
|
||||
with MockArbitraryBuffer( 'cpp', ycm ):
|
||||
with MockArbitraryBuffer( 'cpp' ):
|
||||
with MockEventNotification( DiagnosticResponse ):
|
||||
ycm.OnFileReadyToParse()
|
||||
ok_( ycm.FileParseRequestReady() )
|
||||
@ -340,7 +340,7 @@ def _Check_FileReadyToParse_Diagnostic_Clean( ycm, vim_command ):
|
||||
# Tests Vim sign unplacement and error/warning count python API
|
||||
# when there are no errors/warnings left.
|
||||
# Should be called after _Check_FileReadyToParse_Diagnostic_Warning
|
||||
with MockArbitraryBuffer( 'cpp', ycm ):
|
||||
with MockArbitraryBuffer( 'cpp' ):
|
||||
with MockEventNotification( MagicMock( return_value = [] ) ):
|
||||
ycm.OnFileReadyToParse()
|
||||
ycm.HandleFileParseRequest()
|
||||
@ -366,7 +366,7 @@ def EventNotification_FileReadyToParse_TagFiles_UnicodeWorkingDirectory_test(
|
||||
with patch( 'ycm.client.event_notification.EventNotification.'
|
||||
'PostDataToHandlerAsync' ) as post_data_to_handler_async:
|
||||
with CurrentWorkingDirectory( unicode_dir ):
|
||||
with MockVimBuffers( [ current_buffer ], current_buffer, ( 6, 5 ), ycm ):
|
||||
with MockVimBuffers( [ current_buffer ], current_buffer, ( 6, 5 ) ):
|
||||
ycm.OnFileReadyToParse()
|
||||
|
||||
assert_that(
|
||||
@ -509,7 +509,7 @@ def EventNotification_FileReadyToParse_SyntaxKeywords_SeedWithCache_test(
|
||||
|
||||
with patch( 'ycm.client.event_notification.EventNotification.'
|
||||
'PostDataToHandlerAsync' ) as post_data_to_handler_async:
|
||||
with MockVimBuffers( [ current_buffer ], current_buffer, ycm_state = ycm ):
|
||||
with MockVimBuffers( [ current_buffer ], current_buffer ):
|
||||
ycm.OnFileReadyToParse()
|
||||
assert_that(
|
||||
# Positional arguments passed to PostDataToHandlerAsync.
|
||||
@ -545,7 +545,7 @@ def EventNotification_FileReadyToParse_SyntaxKeywords_ClearCacheIfRestart_test(
|
||||
|
||||
with patch( 'ycm.client.event_notification.EventNotification.'
|
||||
'PostDataToHandlerAsync' ) as post_data_to_handler_async:
|
||||
with MockVimBuffers( [ current_buffer ], current_buffer, ycm_state = ycm ):
|
||||
with MockVimBuffers( [ current_buffer ], current_buffer ):
|
||||
ycm.OnFileReadyToParse()
|
||||
assert_that(
|
||||
# Positional arguments passed to PostDataToHandlerAsync.
|
||||
|
@ -280,8 +280,7 @@ class VimMatch( object ):
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def MockVimBuffers( buffers, current_buffer, cursor_position = ( 1, 1 ),
|
||||
ycm_state = None):
|
||||
def MockVimBuffers( buffers, current_buffer, cursor_position = ( 1, 1 ) ):
|
||||
"""Simulates the Vim buffers list |buffers| where |current_buffer| is the
|
||||
buffer displayed in the current window and |cursor_position| is the current
|
||||
cursor position. All buffers are represented by a VimBuffer object."""
|
||||
@ -291,8 +290,6 @@ def MockVimBuffers( buffers, current_buffer, cursor_position = ( 1, 1 ),
|
||||
with patch( 'vim.buffers', buffers ):
|
||||
with patch( 'vim.current.buffer', current_buffer ):
|
||||
with patch( 'vim.current.window.cursor', cursor_position ):
|
||||
if ycm_state is not None:
|
||||
ycm_state.SetCurrentBuffer()
|
||||
yield
|
||||
|
||||
|
||||
|
@ -330,7 +330,7 @@ def YouCompleteMe_ShowDiagnostics_NoDiagnosticsDetected_test(
|
||||
ycm, set_location_list, post_vim_message, *args ):
|
||||
|
||||
current_buffer = VimBuffer( 'buffer', filetype = 'cpp' )
|
||||
with MockVimBuffers( [ current_buffer ], current_buffer, ycm_state = ycm ):
|
||||
with MockVimBuffers( [ current_buffer ], current_buffer ):
|
||||
with patch( 'ycm.client.event_notification.EventNotification.Response',
|
||||
return_value = {} ):
|
||||
ycm.ShowDiagnostics()
|
||||
@ -367,7 +367,7 @@ def YouCompleteMe_ShowDiagnostics_DiagnosticsFound_DoNotOpenLocationList_test(
|
||||
}
|
||||
|
||||
current_buffer = VimBuffer( 'buffer', filetype = 'cpp', number = 3 )
|
||||
with MockVimBuffers( [ current_buffer ], current_buffer, ycm_state = ycm ):
|
||||
with MockVimBuffers( [ current_buffer ], current_buffer ):
|
||||
with patch( 'ycm.client.event_notification.EventNotification.Response',
|
||||
return_value = [ diagnostic ] ):
|
||||
ycm.ShowDiagnostics()
|
||||
@ -409,7 +409,7 @@ def YouCompleteMe_ShowDiagnostics_DiagnosticsFound_OpenLocationList_test(
|
||||
}
|
||||
|
||||
current_buffer = VimBuffer( 'buffer', filetype = 'cpp', number = 3 )
|
||||
with MockVimBuffers( [ current_buffer ], current_buffer, ycm_state = ycm ):
|
||||
with MockVimBuffers( [ current_buffer ], current_buffer ):
|
||||
with patch( 'ycm.client.event_notification.EventNotification.Response',
|
||||
return_value = [ diagnostic ] ):
|
||||
ycm.ShowDiagnostics()
|
||||
@ -514,7 +514,7 @@ def YouCompleteMe_UpdateDiagnosticInterface_PrioritizeErrorsOverWarnings_test(
|
||||
|
||||
test_utils.VIM_MATCHES = []
|
||||
|
||||
with MockVimBuffers( [ current_buffer ], current_buffer, ( 3, 1 ), ycm ):
|
||||
with MockVimBuffers( [ current_buffer ], current_buffer, ( 3, 1 ) ):
|
||||
with patch( 'ycm.client.event_notification.EventNotification.Response',
|
||||
return_value = diagnostics ):
|
||||
ycm.OnFileReadyToParse()
|
||||
|
@ -115,7 +115,6 @@ class YouCompleteMe( object ):
|
||||
self._user_notified_about_crash = False
|
||||
self._omnicomp = OmniCompleter( user_options )
|
||||
self._buffers = BufferDict( user_options )
|
||||
self._current_buffer = None
|
||||
self._latest_completion_request = None
|
||||
self._logger = logging.getLogger( 'ycm' )
|
||||
self._client_logfile = None
|
||||
@ -357,7 +356,7 @@ class YouCompleteMe( object ):
|
||||
|
||||
|
||||
def NeedsReparse( self ):
|
||||
return self._current_buffer.NeedsReparse()
|
||||
return self.CurrentBuffer().NeedsReparse()
|
||||
|
||||
|
||||
def OnFileReadyToParse( self ):
|
||||
@ -375,7 +374,7 @@ class YouCompleteMe( object ):
|
||||
self._AddSyntaxDataIfNeeded( extra_data )
|
||||
self._AddExtraConfDataIfNeeded( extra_data )
|
||||
|
||||
self._current_buffer.SendParseRequest( extra_data )
|
||||
self.CurrentBuffer().SendParseRequest( extra_data )
|
||||
|
||||
|
||||
def OnBufferUnload( self, deleted_buffer_file ):
|
||||
@ -388,8 +387,8 @@ class YouCompleteMe( object ):
|
||||
SendEventNotificationAsync( 'BufferVisit', extra_data = extra_data )
|
||||
|
||||
|
||||
def SetCurrentBuffer( self ):
|
||||
self._current_buffer = self._buffers[ vimsupport.GetCurrentBufferNumber() ]
|
||||
def CurrentBuffer( self ):
|
||||
return self._buffers[ vimsupport.GetCurrentBufferNumber() ]
|
||||
|
||||
|
||||
def OnInsertLeave( self ):
|
||||
@ -397,7 +396,7 @@ class YouCompleteMe( object ):
|
||||
|
||||
|
||||
def OnCursorMoved( self ):
|
||||
self._current_buffer.OnCursorMoved()
|
||||
self.CurrentBuffer().OnCursorMoved()
|
||||
|
||||
|
||||
def _CleanLogfile( self ):
|
||||
@ -524,11 +523,11 @@ class YouCompleteMe( object ):
|
||||
|
||||
|
||||
def GetErrorCount( self ):
|
||||
return self._current_buffer.GetErrorCount()
|
||||
return self.CurrentBuffer().GetErrorCount()
|
||||
|
||||
|
||||
def GetWarningCount( self ):
|
||||
return self._current_buffer.GetWarningCount()
|
||||
return self.CurrentBuffer().GetWarningCount()
|
||||
|
||||
|
||||
def DiagnosticUiSupportedForCurrentFiletype( self ):
|
||||
@ -542,20 +541,20 @@ class YouCompleteMe( object ):
|
||||
|
||||
|
||||
def _PopulateLocationListWithLatestDiagnostics( self ):
|
||||
return self._current_buffer.PopulateLocationList()
|
||||
return self.CurrentBuffer().PopulateLocationList()
|
||||
|
||||
|
||||
def FileParseRequestReady( self ):
|
||||
# Return True if server is not ready yet, to stop repeating check timer.
|
||||
return ( not self.IsServerReady() or
|
||||
self._current_buffer.FileParseRequestReady() )
|
||||
self.CurrentBuffer().FileParseRequestReady() )
|
||||
|
||||
|
||||
def HandleFileParseRequest( self, block = False ):
|
||||
if not self.IsServerReady():
|
||||
return
|
||||
|
||||
current_buffer = self._current_buffer
|
||||
current_buffer = self.CurrentBuffer()
|
||||
# Order is important here:
|
||||
# FileParseRequestReady has a low cost, while
|
||||
# NativeFiletypeCompletionUsable is a blocking server request
|
||||
|
Loading…
Reference in New Issue
Block a user