diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index 7d034f7aac3..40f726f90ce 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -1072,7 +1072,7 @@ public: const QString &type = {}); void handleSemanticTokens(TextDocument *doc, const QList &tokens, - int version); + int version, bool force); enum class AstCallbackMode { SyncIfPossible, AlwaysAsync }; using TextDocOrFile = const Utils::variant; @@ -1270,8 +1270,8 @@ ClangdClient::ClangdClient(Project *project, const Utils::FilePath &jsonDbDir) setDiagnosticsHandlers(textMarkCreator, hideDiagsHandler); setSymbolStringifier(displayNameFromDocumentSymbol); setSemanticTokensHandler([this](TextDocument *doc, const QList &tokens, - int version) { - d->handleSemanticTokens(doc, tokens, version); + int version, bool force) { + d->handleSemanticTokens(doc, tokens, version, force); }); hoverHandler()->setHelpItemProvider([this](const HoverRequest::Response &response, const DocumentUri &uri) { @@ -2630,7 +2630,7 @@ static void semanticHighlighter(QFutureInterface &future, // in the semantic tokens nor in the AST. void ClangdClient::Private::handleSemanticTokens(TextDocument *doc, const QList &tokens, - int version) + int version, bool force) { SubtaskTimer t(highlightingTimer); qCDebug(clangdLog) << "handling LSP tokens" << doc->filePath() << tokens.size(); @@ -2641,7 +2641,7 @@ void ClangdClient::Private::handleSemanticTokens(TextDocument *doc, } const auto previous = previousTokens.find(doc); if (previous != previousTokens.end()) { - if (previous->first == tokens && previous->second == version) { + if (!force && previous->first == tokens && previous->second == version) { qCDebug(clangdLogHighlight) << "tokens and version same as last time; nothing to do"; return; } diff --git a/src/plugins/languageclient/semantichighlightsupport.cpp b/src/plugins/languageclient/semantichighlightsupport.cpp index 4bab1e6fcf3..260cabd7e49 100644 --- a/src/plugins/languageclient/semantichighlightsupport.cpp +++ b/src/plugins/languageclient/semantichighlightsupport.cpp @@ -261,7 +261,7 @@ void SemanticTokenSupport::updateSemanticTokens(TextDocument *textDocument) void SemanticTokenSupport::rehighlight() { for (const Utils::FilePath &filePath : m_tokens.keys()) - highlight(filePath); + highlight(filePath, true); } void addModifiers(int key, @@ -474,7 +474,7 @@ void SemanticTokenSupport::handleSemanticTokensDelta( highlight(filePath); } -void SemanticTokenSupport::highlight(const Utils::FilePath &filePath) +void SemanticTokenSupport::highlight(const Utils::FilePath &filePath, bool force) { TextDocument *doc = TextDocument::textDocumentForFilePath(filePath); if (!doc || LanguageClientManager::clientForDocument(doc) != m_client) @@ -517,7 +517,7 @@ void SemanticTokenSupport::highlight(const Utils::FilePath &filePath) } } - m_tokensHandler(doc, expandedTokens, versionedTokens.version); + m_tokensHandler(doc, expandedTokens, versionedTokens.version, force); return; } int line = 1; diff --git a/src/plugins/languageclient/semantichighlightsupport.h b/src/plugins/languageclient/semantichighlightsupport.h index 110b14f23b0..1f205fe7813 100644 --- a/src/plugins/languageclient/semantichighlightsupport.h +++ b/src/plugins/languageclient/semantichighlightsupport.h @@ -56,7 +56,7 @@ inline bool operator==(const ExpandedSemanticToken &t1, const ExpandedSemanticTo && t1.type == t2.type && t1.modifiers == t2.modifiers; } using SemanticTokensHandler = std::function &, int)>; + const QList &, int, bool)>; namespace SemanticHighligtingSupport { @@ -99,7 +99,7 @@ private: void handleSemanticTokensDelta(const Utils::FilePath &filePath, const LanguageServerProtocol::SemanticTokensDeltaResult &result, int documentVersion); - void highlight(const Utils::FilePath &filePath); + void highlight(const Utils::FilePath &filePath, bool force = false); void updateFormatHash(); void currentEditorChanged(); void onCurrentEditorChanged(Core::IEditor *editor);