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();

View File

@@ -33,17 +33,18 @@ class Utf8String;
namespace ClangBackEnd {
class Cursor;
class SourceRangeContainer;
class CommandLineArguments;
class Cursor;
class FollowSymbolResult;
class SourceRangeContainer;
class FollowSymbol
{
public:
static SourceRangeContainer followSymbol(CXTranslationUnit tu,
const Cursor &fullCursor,
uint line,
uint column);
static FollowSymbolResult followSymbol(CXTranslationUnit tu,
const Cursor &fullCursor,
uint line,
uint column);
};
} // namespace ClangBackEnd

View File

@@ -27,14 +27,15 @@
#include "clangdocumentjob.h"
#include <clangsupport/followsymbolmessage.h>
#include <clangsupport/sourcerangecontainer.h>
namespace ClangBackEnd {
class FollowSymbolJob : public DocumentJob<SourceRangeContainer>
class FollowSymbolJob : public DocumentJob<FollowSymbolResult>
{
public:
using AsyncResult = SourceRangeContainer;
using AsyncResult = FollowSymbolResult;
AsyncPrepareResult prepareAsyncRun() override;
void finalizeAsyncRun() override;

View File

@@ -269,7 +269,7 @@ void TranslationUnit::extractDiagnostics(DiagnosticContainer &firstHeaderErrorDi
}
}
SourceRangeContainer TranslationUnit::followSymbol(uint line, uint column) const
FollowSymbolResult TranslationUnit::followSymbol(uint line, uint column) const
{
return FollowSymbol::followSymbol(m_cxTranslationUnit, cursorAt(line, column), line, column);
}

View File

@@ -37,6 +37,7 @@ namespace ClangBackEnd {
class Cursor;
class DiagnosticContainer;
class DiagnosticSet;
class FollowSymbolResult;
class ReferencesResult;
class SkippedSourceRanges;
class SourceLocation;
@@ -108,7 +109,7 @@ public:
TokenProcessor<FullTokenInfo> fullTokenInfosInRange(const SourceRange &range) const;
SkippedSourceRanges skippedSourceRanges() const;
SourceRangeContainer followSymbol(uint line, uint column) const;
FollowSymbolResult followSymbol(uint line, uint column) const;
private:
const Utf8String m_id;