diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index f7a55a099a5..0f9acb58c1c 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -1065,6 +1065,8 @@ public: // The highlighters are owned by their respective documents. std::unordered_map highlighters; + QHash, int>> previousTokens; + // The ranges of symbols referring to virtual functions, with document version, // as extracted by the highlighting procedure. QHash, 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; diff --git a/src/plugins/languageclient/semantichighlightsupport.h b/src/plugins/languageclient/semantichighlightsupport.h index 084b3c1058a..110b14f23b0 100644 --- a/src/plugins/languageclient/semantichighlightsupport.h +++ b/src/plugins/languageclient/semantichighlightsupport.h @@ -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 &, int)>;