From b6a766669751ec71cfdb026ad3dbd3b8d8be1c4e Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Thu, 13 Oct 2022 10:35:36 +0200 Subject: [PATCH] ClangCodeModel: Do not needlessly update the configuration ... of a document. This fixes the indexing progress bar appearing when opening a source file (unless it has editor defines set). Change-Id: Ia99b226abdb1d5a98a92b23eb4d7311611940b0a Reviewed-by: Qt CI Bot Reviewed-by: Reviewed-by: Christian Stenger --- src/plugins/clangcodemodel/clangdclient.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index 5c249fa2290..b6693adf689 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -736,6 +736,8 @@ void ClangdClient::updateParserConfig(const Utils::FilePath &filePath, const CppEditor::BaseEditorDocumentParser::Configuration &config) { // TODO: Also handle usePrecompiledHeaders? + // TODO: Should we write the editor defines into the json file? It seems strange + // that they should affect the index only while the file is open in the editor. const auto projectPart = !config.preferredProjectPartId.isEmpty() ? CppEditor::CppModelManager::instance()->projectPartForId( config.preferredProjectPartId) @@ -745,10 +747,15 @@ void ClangdClient::updateParserConfig(const Utils::FilePath &filePath, CppEditor::BaseEditorDocumentParser::Configuration fullConfig = config; fullConfig.preferredProjectPartId = projectPart->id(); - CppEditor::BaseEditorDocumentParser::Configuration &cachedConfig = d->parserConfigs[filePath]; - if (cachedConfig == fullConfig) + auto cachedConfig = d->parserConfigs.find(filePath); + if (cachedConfig == d->parserConfigs.end()) { + cachedConfig = d->parserConfigs.insert(filePath, fullConfig); + if (config.preferredProjectPartId.isEmpty() && config.editorDefines.isEmpty()) + return; + } else if (cachedConfig.value() == fullConfig) { return; - cachedConfig = fullConfig; + } + cachedConfig.value() = fullConfig; QJsonObject cdbChanges; const Utils::FilePath includeDir = CppEditor::ClangdSettings(d->settings).clangdIncludePath();