CppEditor: Fix missing editor defines on session load

The CppSourceProcessor initially expects the "<per-editor-defines>"
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 <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2022-09-19 14:28:14 +02:00
parent 8cfbaa1da9
commit a8397c129f

View File

@@ -51,7 +51,7 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &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<void> &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<void> &futur
if (invalidateSnapshot) {
state.snapshot = Snapshot();
if (!baseState.editorDefines.isEmpty()) {
workingCopy.insert(CppModelManager::editorConfigurationFileName(),
baseState.editorDefines);
}
} else {
// Remove changed files from the snapshot
QSet<Utils::FilePath> toRemove;
@@ -161,13 +164,6 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &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<void> &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;