From a8397c129fd70a85a80518947e69897f2ec26ca8 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Mon, 19 Sep 2022 14:28:14 +0200 Subject: [PATCH] CppEditor: Fix missing editor defines on session load The CppSourceProcessor initially expects the "" pseudo-file in the working copy and then puts the resulting document into the snapshot. Therefore, if we reset the snapshot, we must put the data back into the working copy. Fixes: QTCREATORBUG-22584 Change-Id: I4e3fd0647cc35327a2e72547c81c4edc16a670b2 Reviewed-by: Qt CI Bot Reviewed-by: Reviewed-by: Christian Stenger --- .../cppeditor/builtineditordocumentparser.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/plugins/cppeditor/builtineditordocumentparser.cpp b/src/plugins/cppeditor/builtineditordocumentparser.cpp index 10c4ab5d4e4..d06806a2037 100644 --- a/src/plugins/cppeditor/builtineditordocumentparser.cpp +++ b/src/plugins/cppeditor/builtineditordocumentparser.cpp @@ -51,7 +51,7 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface &futur ExtraState state = extraState(); WorkingCopy workingCopy = updateParams.workingCopy; - bool invalidateSnapshot = false, invalidateConfig = false, editorDefinesChanged_ = false; + bool invalidateSnapshot = false, invalidateConfig = false; CppModelManager *modelManager = CppModelManager::instance(); QByteArray configFile = modelManager->codeModelConfiguration(); @@ -97,7 +97,6 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface &futur if (baseConfig.editorDefines != baseState.editorDefines) { baseState.editorDefines = baseConfig.editorDefines; invalidateSnapshot = true; - editorDefinesChanged_ = true; } if (headerPaths != state.headerPaths) { @@ -130,6 +129,10 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface &futur if (invalidateSnapshot) { state.snapshot = Snapshot(); + if (!baseState.editorDefines.isEmpty()) { + workingCopy.insert(CppModelManager::editorConfigurationFileName(), + baseState.editorDefines); + } } else { // Remove changed files from the snapshot QSet toRemove; @@ -161,13 +164,6 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface &futur workingCopy.insert(configurationFileName, state.configFile); state.snapshot.remove(filePath()); - static const QString editorDefinesFileName - = CppModelManager::editorConfigurationFileName(); - if (editorDefinesChanged_) { - state.snapshot.remove(editorDefinesFileName); - workingCopy.insert(editorDefinesFileName, baseState.editorDefines); - } - Internal::CppSourceProcessor sourceProcessor(state.snapshot, [&](const Document::Ptr &doc) { const QString fileName = doc->fileName(); const bool isInEditor = fileName == filePath(); @@ -197,7 +193,7 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface &futur sourceProcessor.run(precompiledHeader); } if (!baseState.editorDefines.isEmpty()) - sourceProcessor.run(editorDefinesFileName); + sourceProcessor.run(CppModelManager::editorConfigurationFileName()); QStringList includedFiles = state.includedFiles; if (baseConfig.usePrecompiledHeaders) includedFiles << state.precompiledHeaders;