forked from qt-creator/qt-creator
ClangCodeModel: Ignore redundant semantic tokens
This can now happen due to the newly implemented refresh support. Change-Id: If64feede84b044140f7ec04e317289d3f493aa53 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -1065,6 +1065,8 @@ public:
|
||||
// The highlighters are owned by their respective documents.
|
||||
std::unordered_map<TextDocument *, CppEditor::SemanticHighlighter *> highlighters;
|
||||
|
||||
QHash<TextDocument *, QPair<QList<ExpandedSemanticToken>, int>> previousTokens;
|
||||
|
||||
// The ranges of symbols referring to virtual functions, with document version,
|
||||
// as extracted by the highlighting procedure.
|
||||
QHash<TextDocument *, QPair<QList<Range>, int>> virtualRanges;
|
||||
@@ -1385,6 +1387,7 @@ void ClangdClient::handleDocumentClosed(TextDocument *doc)
|
||||
{
|
||||
d->highlighters.erase(doc);
|
||||
d->astCache.remove(doc);
|
||||
d->previousTokens.remove(doc);
|
||||
d->virtualRanges.remove(doc);
|
||||
}
|
||||
|
||||
@@ -2582,6 +2585,17 @@ void ClangdClient::Private::handleSemanticTokens(TextDocument *doc,
|
||||
<< version << q->documentVersion(doc->filePath());
|
||||
return;
|
||||
}
|
||||
const auto previous = previousTokens.find(doc);
|
||||
if (previous != previousTokens.end()) {
|
||||
if (previous->first == tokens && previous->second == version) {
|
||||
qCDebug(clangdLogHighlight) << "tokens and version same as last time; nothing to do";
|
||||
return;
|
||||
}
|
||||
previous->first = tokens;
|
||||
previous->second = version;
|
||||
} else {
|
||||
previousTokens.insert(doc, qMakePair(tokens, version));
|
||||
}
|
||||
for (const ExpandedSemanticToken &t : tokens)
|
||||
qCDebug(clangdLogHighlight()) << '\t' << t.line << t.column << t.length << t.type
|
||||
<< t.modifiers;
|
||||
|
@@ -50,6 +50,11 @@ public:
|
||||
QString type;
|
||||
QStringList modifiers;
|
||||
};
|
||||
inline bool operator==(const ExpandedSemanticToken &t1, const ExpandedSemanticToken &t2)
|
||||
{
|
||||
return t1.line == t2.line && t1.column == t2.column && t1.length == t2.length
|
||||
&& t1.type == t2.type && t1.modifiers == t2.modifiers;
|
||||
}
|
||||
using SemanticTokensHandler = std::function<void(TextEditor::TextDocument *,
|
||||
const QList<ExpandedSemanticToken> &, int)>;
|
||||
|
||||
|
Reference in New Issue
Block a user