Clang: Use follow symbol result from clang when global fails

When built-in code model fails to follow symbol under cursor
fall back to the clang result even if it only follows
to the decalration.

Change-Id: I22d8c5fee6ab7594b1d1b7ce8104414db28383c7
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
Ivan Donchevskii
2018-06-01 10:46:20 +02:00
parent 52bd5173fb
commit 4e4bd4909a
14 changed files with 122 additions and 37 deletions

View File

@@ -146,10 +146,10 @@ static int getTokenIndex(CXTranslationUnit tu, const Tokens &tokens, uint line,
return tokenIndex;
}
SourceRangeContainer FollowSymbol::followSymbol(CXTranslationUnit tu,
const Cursor &fullCursor,
uint line,
uint column)
FollowSymbolResult FollowSymbol::followSymbol(CXTranslationUnit tu,
const Cursor &fullCursor,
uint line,
uint column)
{
std::unique_ptr<Tokens> tokens(new Tokens(fullCursor));
@@ -175,7 +175,7 @@ SourceRangeContainer FollowSymbol::followSymbol(CXTranslationUnit tu,
CXFile file = clang_getIncludedFile(cursors[tokenIndex]);
const ClangString filename(clang_getFileName(file));
const SourceLocation loc(tu, filename, 1, 1);
return SourceRange(loc, loc);
return SourceRangeContainer(SourceRange(loc, loc));
}
// For definitions we can always find a declaration in current TU
@@ -185,12 +185,16 @@ SourceRangeContainer FollowSymbol::followSymbol(CXTranslationUnit tu,
if (!cursor.isDeclaration()) {
// This is the symbol usage
// We want to return definition
FollowSymbolResult result;
cursor = cursor.referenced();
if (cursor.isNull() || !cursor.isDefinition()) {
// We can't find definition in this TU
if (cursor.isNull())
return SourceRangeContainer();
if (!cursor.isDefinition()) {
// We can't find definition in this TU
result.isPureDeclarationForUsage = true;
}
return extractMatchingTokenRange(cursor, tokenSpelling);
result.range = extractMatchingTokenRange(cursor, tokenSpelling);
return result;
}
cursor = cursor.definition();