Implementing the new GoToImprecise command
Same as GoTo, but trades correctness for speed. See the docs for details.
This commit is contained in:
parent
9cf566bd8f
commit
90e097efa4
13
README.md
13
README.md
@ -627,6 +627,19 @@ the current translation unit, jumps to the symbol's declaration.
|
|||||||
|
|
||||||
Supported in filetypes: `c, cpp, objc, objcpp, python, cs`
|
Supported in filetypes: `c, cpp, objc, objcpp, python, cs`
|
||||||
|
|
||||||
|
### The `GoToImprecise` subcommand
|
||||||
|
|
||||||
|
WARNING: This command trades correctness for speed!
|
||||||
|
|
||||||
|
Same as the `GoTo` command except that it doesn't recompile the file with
|
||||||
|
libclang before looking up nodes in the AST. This can be very useful when you're
|
||||||
|
editing files that take long to compile but you know that you haven't made any
|
||||||
|
changes since the last parse that would lead to incorrect jumps. When you're
|
||||||
|
just browsing around your codebase, this command can spare you quite a bit of
|
||||||
|
latency.
|
||||||
|
|
||||||
|
Supported in filetypes: `c, cpp, objc, objcpp`
|
||||||
|
|
||||||
### The `ClearCompilationFlagCache` subcommand
|
### The `ClearCompilationFlagCache` subcommand
|
||||||
|
|
||||||
YCM caches the flags it gets from the `FlagsForFile` function in your
|
YCM caches the flags it gets from the `FlagsForFile` function in your
|
||||||
|
@ -133,7 +133,8 @@ Location ClangCompleter::GetDeclarationLocation(
|
|||||||
int line,
|
int line,
|
||||||
int column,
|
int column,
|
||||||
const std::vector< UnsavedFile > &unsaved_files,
|
const std::vector< UnsavedFile > &unsaved_files,
|
||||||
const std::vector< std::string > &flags ) {
|
const std::vector< std::string > &flags,
|
||||||
|
bool reparse ) {
|
||||||
ReleaseGil unlock;
|
ReleaseGil unlock;
|
||||||
shared_ptr< TranslationUnit > unit =
|
shared_ptr< TranslationUnit > unit =
|
||||||
translation_unit_store_.GetOrCreate( filename, unsaved_files, flags );
|
translation_unit_store_.GetOrCreate( filename, unsaved_files, flags );
|
||||||
@ -142,7 +143,7 @@ Location ClangCompleter::GetDeclarationLocation(
|
|||||||
return Location();
|
return Location();
|
||||||
}
|
}
|
||||||
|
|
||||||
return unit->GetDeclarationLocation( line, column, unsaved_files );
|
return unit->GetDeclarationLocation( line, column, unsaved_files, reparse );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -151,7 +152,8 @@ Location ClangCompleter::GetDefinitionLocation(
|
|||||||
int line,
|
int line,
|
||||||
int column,
|
int column,
|
||||||
const std::vector< UnsavedFile > &unsaved_files,
|
const std::vector< UnsavedFile > &unsaved_files,
|
||||||
const std::vector< std::string > &flags ) {
|
const std::vector< std::string > &flags,
|
||||||
|
bool reparse ) {
|
||||||
ReleaseGil unlock;
|
ReleaseGil unlock;
|
||||||
shared_ptr< TranslationUnit > unit =
|
shared_ptr< TranslationUnit > unit =
|
||||||
translation_unit_store_.GetOrCreate( filename, unsaved_files, flags );
|
translation_unit_store_.GetOrCreate( filename, unsaved_files, flags );
|
||||||
@ -160,7 +162,7 @@ Location ClangCompleter::GetDefinitionLocation(
|
|||||||
return Location();
|
return Location();
|
||||||
}
|
}
|
||||||
|
|
||||||
return unit->GetDefinitionLocation( line, column, unsaved_files );
|
return unit->GetDefinitionLocation( line, column, unsaved_files, reparse );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,14 +62,16 @@ public:
|
|||||||
int line,
|
int line,
|
||||||
int column,
|
int column,
|
||||||
const std::vector< UnsavedFile > &unsaved_files,
|
const std::vector< UnsavedFile > &unsaved_files,
|
||||||
const std::vector< std::string > &flags );
|
const std::vector< std::string > &flags,
|
||||||
|
bool reparse = true );
|
||||||
|
|
||||||
Location GetDefinitionLocation(
|
Location GetDefinitionLocation(
|
||||||
const std::string &filename,
|
const std::string &filename,
|
||||||
int line,
|
int line,
|
||||||
int column,
|
int column,
|
||||||
const std::vector< UnsavedFile > &unsaved_files,
|
const std::vector< UnsavedFile > &unsaved_files,
|
||||||
const std::vector< std::string > &flags );
|
const std::vector< std::string > &flags,
|
||||||
|
bool reparse = true );
|
||||||
|
|
||||||
void DeleteCachesForFile( const std::string &filename );
|
void DeleteCachesForFile( const std::string &filename );
|
||||||
|
|
||||||
|
@ -177,8 +177,10 @@ std::vector< CompletionData > TranslationUnit::CandidatesForLocation(
|
|||||||
Location TranslationUnit::GetDeclarationLocation(
|
Location TranslationUnit::GetDeclarationLocation(
|
||||||
int line,
|
int line,
|
||||||
int column,
|
int column,
|
||||||
const std::vector< UnsavedFile > &unsaved_files ) {
|
const std::vector< UnsavedFile > &unsaved_files,
|
||||||
ReparseForIndexing( unsaved_files );
|
bool reparse ) {
|
||||||
|
if (reparse)
|
||||||
|
ReparseForIndexing( unsaved_files );
|
||||||
unique_lock< mutex > lock( clang_access_mutex_ );
|
unique_lock< mutex > lock( clang_access_mutex_ );
|
||||||
|
|
||||||
if ( !clang_translation_unit_ )
|
if ( !clang_translation_unit_ )
|
||||||
@ -200,8 +202,10 @@ Location TranslationUnit::GetDeclarationLocation(
|
|||||||
Location TranslationUnit::GetDefinitionLocation(
|
Location TranslationUnit::GetDefinitionLocation(
|
||||||
int line,
|
int line,
|
||||||
int column,
|
int column,
|
||||||
const std::vector< UnsavedFile > &unsaved_files ) {
|
const std::vector< UnsavedFile > &unsaved_files,
|
||||||
ReparseForIndexing( unsaved_files );
|
bool reparse ) {
|
||||||
|
if (reparse)
|
||||||
|
ReparseForIndexing( unsaved_files );
|
||||||
unique_lock< mutex > lock( clang_access_mutex_ );
|
unique_lock< mutex > lock( clang_access_mutex_ );
|
||||||
|
|
||||||
if ( !clang_translation_unit_ )
|
if ( !clang_translation_unit_ )
|
||||||
|
@ -69,12 +69,14 @@ public:
|
|||||||
Location GetDeclarationLocation(
|
Location GetDeclarationLocation(
|
||||||
int line,
|
int line,
|
||||||
int column,
|
int column,
|
||||||
const std::vector< UnsavedFile > &unsaved_files );
|
const std::vector< UnsavedFile > &unsaved_files,
|
||||||
|
bool reparse = true );
|
||||||
|
|
||||||
Location GetDefinitionLocation(
|
Location GetDefinitionLocation(
|
||||||
int line,
|
int line,
|
||||||
int column,
|
int column,
|
||||||
const std::vector< UnsavedFile > &unsaved_files );
|
const std::vector< UnsavedFile > &unsaved_files,
|
||||||
|
bool reparse = true );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Reparse( std::vector< CXUnsavedFile > &unsaved_files );
|
void Reparse( std::vector< CXUnsavedFile > &unsaved_files );
|
||||||
|
@ -20,7 +20,7 @@ namespace YouCompleteMe {
|
|||||||
int YcmCoreVersion() {
|
int YcmCoreVersion() {
|
||||||
// We increment this every time when we want to force users to recompile
|
// We increment this every time when we want to force users to recompile
|
||||||
// ycm_core.
|
// ycm_core.
|
||||||
return 8;
|
return 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace YouCompleteMe
|
} // namespace YouCompleteMe
|
||||||
|
@ -188,7 +188,7 @@ def OverlapLength( left_string, right_string ):
|
|||||||
length += 1
|
length += 1
|
||||||
|
|
||||||
|
|
||||||
COMPATIBLE_WITH_CORE_VERSION = 8
|
COMPATIBLE_WITH_CORE_VERSION = 9
|
||||||
|
|
||||||
def CompatibleWithYcmCore():
|
def CompatibleWithYcmCore():
|
||||||
try:
|
try:
|
||||||
|
@ -104,6 +104,7 @@ class ClangCompleter( Completer ):
|
|||||||
return [ 'GoToDefinition',
|
return [ 'GoToDefinition',
|
||||||
'GoToDeclaration',
|
'GoToDeclaration',
|
||||||
'GoTo',
|
'GoTo',
|
||||||
|
'GoToImprecise',
|
||||||
'ClearCompilationFlagCache']
|
'ClearCompilationFlagCache']
|
||||||
|
|
||||||
|
|
||||||
@ -118,12 +119,14 @@ class ClangCompleter( Completer ):
|
|||||||
return self._GoToDeclaration( request_data )
|
return self._GoToDeclaration( request_data )
|
||||||
elif command == 'GoTo':
|
elif command == 'GoTo':
|
||||||
return self._GoTo( request_data )
|
return self._GoTo( request_data )
|
||||||
|
elif command == 'GoToImprecise':
|
||||||
|
return self._GoToImprecise( request_data )
|
||||||
elif command == 'ClearCompilationFlagCache':
|
elif command == 'ClearCompilationFlagCache':
|
||||||
return self._ClearCompilationFlagCache()
|
return self._ClearCompilationFlagCache()
|
||||||
raise ValueError( self.UserCommandsHelpMessage() )
|
raise ValueError( self.UserCommandsHelpMessage() )
|
||||||
|
|
||||||
|
|
||||||
def _LocationForGoTo( self, goto_function, request_data ):
|
def _LocationForGoTo( self, goto_function, request_data, reparse = True ):
|
||||||
filename = request_data[ 'filepath' ]
|
filename = request_data[ 'filepath' ]
|
||||||
if not filename:
|
if not filename:
|
||||||
raise ValueError( INVALID_FILE_MESSAGE )
|
raise ValueError( INVALID_FILE_MESSAGE )
|
||||||
@ -140,27 +143,22 @@ class ClangCompleter( Completer ):
|
|||||||
line,
|
line,
|
||||||
column,
|
column,
|
||||||
files,
|
files,
|
||||||
flags )
|
flags,
|
||||||
|
reparse )
|
||||||
|
|
||||||
|
|
||||||
def _GoToDefinition( self, request_data ):
|
def _GoToDefinition( self, request_data ):
|
||||||
location = self._LocationForGoTo( 'GetDefinitionLocation', request_data )
|
location = self._LocationForGoTo( 'GetDefinitionLocation', request_data )
|
||||||
if not location or not location.IsValid():
|
if not location or not location.IsValid():
|
||||||
raise RuntimeError( 'Can\'t jump to definition.' )
|
raise RuntimeError( 'Can\'t jump to definition.' )
|
||||||
|
return _ResponseForLocation( location )
|
||||||
return responses.BuildGoToResponse( location.filename_,
|
|
||||||
location.line_number_ - 1,
|
|
||||||
location.column_number_ - 1)
|
|
||||||
|
|
||||||
|
|
||||||
def _GoToDeclaration( self, request_data ):
|
def _GoToDeclaration( self, request_data ):
|
||||||
location = self._LocationForGoTo( 'GetDeclarationLocation', request_data )
|
location = self._LocationForGoTo( 'GetDeclarationLocation', request_data )
|
||||||
if not location or not location.IsValid():
|
if not location or not location.IsValid():
|
||||||
raise RuntimeError( 'Can\'t jump to declaration.' )
|
raise RuntimeError( 'Can\'t jump to declaration.' )
|
||||||
|
return _ResponseForLocation( location )
|
||||||
return responses.BuildGoToResponse( location.filename_,
|
|
||||||
location.line_number_ - 1,
|
|
||||||
location.column_number_ - 1)
|
|
||||||
|
|
||||||
|
|
||||||
def _GoTo( self, request_data ):
|
def _GoTo( self, request_data ):
|
||||||
@ -169,11 +167,20 @@ class ClangCompleter( Completer ):
|
|||||||
location = self._LocationForGoTo( 'GetDeclarationLocation', request_data )
|
location = self._LocationForGoTo( 'GetDeclarationLocation', request_data )
|
||||||
if not location or not location.IsValid():
|
if not location or not location.IsValid():
|
||||||
raise RuntimeError( 'Can\'t jump to definition or declaration.' )
|
raise RuntimeError( 'Can\'t jump to definition or declaration.' )
|
||||||
|
return _ResponseForLocation( location )
|
||||||
|
|
||||||
return responses.BuildGoToResponse( location.filename_,
|
|
||||||
location.line_number_ - 1,
|
|
||||||
location.column_number_ - 1)
|
|
||||||
|
|
||||||
|
def _GoToImprecise( self, request_data ):
|
||||||
|
location = self._LocationForGoTo( 'GetDefinitionLocation',
|
||||||
|
request_data,
|
||||||
|
reparse = False )
|
||||||
|
if not location or not location.IsValid():
|
||||||
|
location = self._LocationForGoTo( 'GetDeclarationLocation',
|
||||||
|
request_data,
|
||||||
|
reparse = False )
|
||||||
|
if not location or not location.IsValid():
|
||||||
|
raise RuntimeError( 'Can\'t jump to definition or declaration.' )
|
||||||
|
return _ResponseForLocation( location )
|
||||||
|
|
||||||
|
|
||||||
def _ClearCompilationFlagCache( self ):
|
def _ClearCompilationFlagCache( self ):
|
||||||
@ -295,3 +302,9 @@ def _FilterDiagnostics( diagnostics ):
|
|||||||
x.text_ != TOO_MANY_ERRORS_DIAG_TEXT_TO_IGNORE ]
|
x.text_ != TOO_MANY_ERRORS_DIAG_TEXT_TO_IGNORE ]
|
||||||
|
|
||||||
|
|
||||||
|
def _ResponseForLocation( location ):
|
||||||
|
return responses.BuildGoToResponse( location.filename_,
|
||||||
|
location.line_number_ - 1,
|
||||||
|
location.column_number_ - 1)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user