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