diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2024-03-04 10:52:15 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2024-03-04 12:47:13 +0000 |
commit | fbe244fd4684121ae4b60519f0b2fcd37646e584 (patch) | |
tree | af8e6631a5f62680d9ca649444963d0ea03beb6b /src/plugins/cppeditor | |
parent | f56fd04c8dbbfead7800a1612fb0d1fd05ceeca6 (diff) |
Cpp Editor: Fix serializing clangd settings
A "store with default operation" makes no sense on the level of the map
itself, as it does not have knowledge about the current on-disk
settings.
This reverts commit a4fbc5f00dddde39871c25bca652de7842baa1dd.
Change-Id: I008b0b5c24428c71182dac5d1f151d25cf4f7467
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/plugins/cppeditor')
-rw-r--r-- | src/plugins/cppeditor/cppcodemodelsettings.cpp | 99 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppcodemodelsettings.h | 29 |
2 files changed, 42 insertions, 86 deletions
diff --git a/src/plugins/cppeditor/cppcodemodelsettings.cpp b/src/plugins/cppeditor/cppcodemodelsettings.cpp index 29516c6218..82cca5752b 100644 --- a/src/plugins/cppeditor/cppcodemodelsettings.cpp +++ b/src/plugins/cppeditor/cppcodemodelsettings.cpp @@ -445,7 +445,11 @@ void ClangdSettings::loadSettings() void ClangdSettings::saveSettings() { const auto settings = Core::ICore::settings(); - Utils::storeToSettings(clangdSettingsKey(), settings, m_data.toMap()); + const ClangdSettings::Data defaultData; + Utils::storeToSettingsWithDefault(clangdSettingsKey(), + settings, + m_data.toMap(), + defaultData.toMap()); settings->beginGroup(Constants::CPPEDITOR_SETTINGSGROUP); diagnosticConfigsToSettings(settings, m_data.customDiagnosticConfigs); settings->endGroup(); @@ -546,81 +550,44 @@ void ClangdProjectSettings::saveSettings() Store ClangdSettings::Data::toMap() const { Store map; - - map.insertValueWithDefault(useClangdKey(), useClangd, DefaultUseClangd); - - const QString clangdPath = executableFilePath != fallbackClangdFilePath() - ? executableFilePath.toString() - : QString(); - - map.insertValueWithDefault(clangdPathKey(), clangdPath); - - map.insertValueWithDefault(clangdIndexingKey(), indexingPriority != IndexingPriority::Off, true); - map.insertValueWithDefault(clangdIndexingPriorityKey(), - int(indexingPriority), - int(DefaultIndexingPriority)); - - map.insertValueWithDefault(clangdHeaderSourceSwitchModeKey(), - int(headerSourceSwitchMode), - int(DefaultHeaderSourceSwitchMode)); - - map.insertValueWithDefault(clangdCompletionRankingModelKey(), - int(completionRankingModel), - int(DefaultCompletionRankingModel)); - - map.insertValueWithDefault(clangdHeaderInsertionKey(), - autoIncludeHeaders, - DefaultAutoIncludeHeaders); - - map.insertValueWithDefault(clangdThreadLimitKey(), workerThreadLimit, DefaultWorkerThreadLimit); - - map.insertValueWithDefault(clangdDocumentThresholdKey(), - documentUpdateThreshold, - DefaultDocumentUpdateThreshold); - - map.insertValueWithDefault(clangdSizeThresholdEnabledKey(), - sizeThresholdEnabled, - DefaultSizeThresholdEnabled); - - map.insertValueWithDefault(clangdSizeThresholdKey(), - sizeThresholdInKb, - DefaultSizeThresholdInKb); - - map.insertValueWithDefault(sessionsWithOneClangdKey(), sessionsWithOneClangd); - - map.insertValueWithDefault(diagnosticConfigIdKey(), - diagnosticConfigId.toSetting(), - initialClangDiagnosticConfigId().toSetting()); - - if (haveCheckedHardwareReqirements != false) - map.insert(checkedHardwareKey(), true); - - map.insertValueWithDefault(completionResultsKey(), - completionResults, - defaultCompletionResults()); + map.insert(useClangdKey(), useClangd); + map.insert(clangdPathKey(), + executableFilePath != fallbackClangdFilePath() ? executableFilePath.toString() + : QString()); + map.insert(clangdIndexingKey(), indexingPriority != IndexingPriority::Off); + map.insert(clangdIndexingPriorityKey(), int(indexingPriority)); + map.insert(clangdHeaderSourceSwitchModeKey(), int(headerSourceSwitchMode)); + map.insert(clangdCompletionRankingModelKey(), int(completionRankingModel)); + map.insert(clangdHeaderInsertionKey(), autoIncludeHeaders); + map.insert(clangdThreadLimitKey(), workerThreadLimit); + map.insert(clangdDocumentThresholdKey(), documentUpdateThreshold); + map.insert(clangdSizeThresholdEnabledKey(), sizeThresholdEnabled); + map.insert(clangdSizeThresholdKey(), sizeThresholdInKb); + map.insert(sessionsWithOneClangdKey(), sessionsWithOneClangd); + map.insert(diagnosticConfigIdKey(), diagnosticConfigId.toSetting()); + map.insert(checkedHardwareKey(), true); + map.insert(completionResultsKey(), completionResults); return map; } void ClangdSettings::Data::fromMap(const Store &map) { - useClangd = map.value(useClangdKey(), DefaultUseClangd).toBool(); + useClangd = map.value(useClangdKey(), true).toBool(); executableFilePath = FilePath::fromString(map.value(clangdPathKey()).toString()); indexingPriority = IndexingPriority( - map.value(clangdIndexingPriorityKey(), int(DefaultIndexingPriority)).toInt()); + map.value(clangdIndexingPriorityKey(), int(this->indexingPriority)).toInt()); const auto it = map.find(clangdIndexingKey()); if (it != map.end() && !it->toBool()) indexingPriority = IndexingPriority::Off; - headerSourceSwitchMode = HeaderSourceSwitchMode( - map.value(clangdHeaderSourceSwitchModeKey(), int(DefaultHeaderSourceSwitchMode)).toInt()); - completionRankingModel = CompletionRankingModel( - map.value(clangdCompletionRankingModelKey(), int(DefaultCompletionRankingModel)).toInt()); - autoIncludeHeaders = map.value(clangdHeaderInsertionKey(), DefaultAutoIncludeHeaders).toBool(); - workerThreadLimit = map.value(clangdThreadLimitKey(), DefaultWorkerThreadLimit).toInt(); - documentUpdateThreshold - = map.value(clangdDocumentThresholdKey(), DefaultDocumentUpdateThreshold).toInt(); - sizeThresholdEnabled - = map.value(clangdSizeThresholdEnabledKey(), DefaultSizeThresholdEnabled).toBool(); - sizeThresholdInKb = map.value(clangdSizeThresholdKey(), DefaultSizeThresholdInKb).toLongLong(); + headerSourceSwitchMode = HeaderSourceSwitchMode(map.value(clangdHeaderSourceSwitchModeKey(), + int(headerSourceSwitchMode)).toInt()); + completionRankingModel = CompletionRankingModel(map.value(clangdCompletionRankingModelKey(), + int(completionRankingModel)).toInt()); + autoIncludeHeaders = map.value(clangdHeaderInsertionKey(), false).toBool(); + workerThreadLimit = map.value(clangdThreadLimitKey(), 0).toInt(); + documentUpdateThreshold = map.value(clangdDocumentThresholdKey(), 500).toInt(); + sizeThresholdEnabled = map.value(clangdSizeThresholdEnabledKey(), false).toBool(); + sizeThresholdInKb = map.value(clangdSizeThresholdKey(), 1024).toLongLong(); sessionsWithOneClangd = map.value(sessionsWithOneClangdKey()).toStringList(); diagnosticConfigId = Id::fromSetting(map.value(diagnosticConfigIdKey(), initialClangDiagnosticConfigId().toSetting())); diff --git a/src/plugins/cppeditor/cppcodemodelsettings.h b/src/plugins/cppeditor/cppcodemodelsettings.h index 6b49185510..fe2e625c07 100644 --- a/src/plugins/cppeditor/cppcodemodelsettings.h +++ b/src/plugins/cppeditor/cppcodemodelsettings.h @@ -125,26 +125,15 @@ public: QStringList sessionsWithOneClangd; ClangDiagnosticConfigs customDiagnosticConfigs; Utils::Id diagnosticConfigId; - - static constexpr auto DefaultWorkerThreadLimit = 0; - static constexpr auto DefaultDocumentUpdateThreshold = 500; - static constexpr auto DefaultSizeThresholdInKb = 1024ll; - static constexpr auto DefaultUseClangd = true; - static constexpr auto DefaultIndexingPriority = ClangdSettings::IndexingPriority::Low; - static constexpr auto DefaultHeaderSourceSwitchMode = HeaderSourceSwitchMode::Both; - static constexpr auto DefaultCompletionRankingModel = CompletionRankingModel::Default; - static constexpr auto DefaultAutoIncludeHeaders = false; - static constexpr auto DefaultSizeThresholdEnabled = false; - - int workerThreadLimit = DefaultWorkerThreadLimit; - int documentUpdateThreshold = DefaultDocumentUpdateThreshold; - qint64 sizeThresholdInKb = DefaultSizeThresholdInKb; - bool useClangd = DefaultUseClangd; - IndexingPriority indexingPriority = DefaultIndexingPriority; - HeaderSourceSwitchMode headerSourceSwitchMode = DefaultHeaderSourceSwitchMode; - CompletionRankingModel completionRankingModel = DefaultCompletionRankingModel; - bool autoIncludeHeaders = DefaultAutoIncludeHeaders; - bool sizeThresholdEnabled = DefaultSizeThresholdEnabled; + int workerThreadLimit = 0; + int documentUpdateThreshold = 500; + qint64 sizeThresholdInKb = 1024; + bool useClangd = true; + IndexingPriority indexingPriority = IndexingPriority::Low; + HeaderSourceSwitchMode headerSourceSwitchMode = HeaderSourceSwitchMode::Both; + CompletionRankingModel completionRankingModel = CompletionRankingModel::Default; + bool autoIncludeHeaders = false; + bool sizeThresholdEnabled = false; bool haveCheckedHardwareReqirements = false; int completionResults = defaultCompletionResults(); }; |