forked from qt-creator/qt-creator
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 a4fbc5f00d
.
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>
This commit is contained in:
@@ -190,4 +190,20 @@ void storeToSettings(const Key &groupKey, QtcSettings *s, const Store &store)
|
|||||||
s->endGroup();
|
s->endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void storeToSettingsWithDefault(const Key &groupKey,
|
||||||
|
QtcSettings *s,
|
||||||
|
const Store &store,
|
||||||
|
const Store &defaultStore)
|
||||||
|
{
|
||||||
|
QTC_ASSERT(store.size() == defaultStore.size(), storeToSettings(groupKey, s, store); return);
|
||||||
|
|
||||||
|
s->beginGroup(groupKey);
|
||||||
|
for (auto it = store.begin(), defaultIt = defaultStore.begin(), end = store.end(); it != end;
|
||||||
|
++it, ++defaultIt)
|
||||||
|
s->setValueWithDefault(it.key(),
|
||||||
|
mapEntryFromStoreEntry(it.value()),
|
||||||
|
mapEntryFromStoreEntry(defaultIt.value()));
|
||||||
|
s->endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
} // Utils
|
} // Utils
|
||||||
|
@@ -15,26 +15,7 @@ class QtcSettings;
|
|||||||
|
|
||||||
using KeyList = QList<Key>;
|
using KeyList = QList<Key>;
|
||||||
|
|
||||||
class Store : public QMap<Key, QVariant>
|
using Store = QMap<Key, QVariant>;
|
||||||
{
|
|
||||||
public:
|
|
||||||
using QMap<Key, QVariant>::QMap;
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
void insertValueWithDefault(const Key &key, const T &val, const T &defaultValue)
|
|
||||||
{
|
|
||||||
if (val != defaultValue)
|
|
||||||
insert(key, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
void insertValueWithDefault(const Key &key, const T &val)
|
|
||||||
{
|
|
||||||
if (val != T())
|
|
||||||
insert(key, val);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
using OldStore = QMap<QByteArray, QVariant>;
|
using OldStore = QMap<QByteArray, QVariant>;
|
||||||
|
|
||||||
QTCREATOR_UTILS_EXPORT KeyList keysFromStrings(const QStringList &list);
|
QTCREATOR_UTILS_EXPORT KeyList keysFromStrings(const QStringList &list);
|
||||||
@@ -60,6 +41,10 @@ QTCREATOR_UTILS_EXPORT QVariant mapEntryFromStoreEntry(const QVariant &value);
|
|||||||
// Don't use in new code.
|
// Don't use in new code.
|
||||||
QTCREATOR_UTILS_EXPORT Store storeFromSettings(const Key &groupKey, QtcSettings *s);
|
QTCREATOR_UTILS_EXPORT Store storeFromSettings(const Key &groupKey, QtcSettings *s);
|
||||||
QTCREATOR_UTILS_EXPORT void storeToSettings(const Key &groupKey, QtcSettings *s, const Store &store);
|
QTCREATOR_UTILS_EXPORT void storeToSettings(const Key &groupKey, QtcSettings *s, const Store &store);
|
||||||
|
QTCREATOR_UTILS_EXPORT void storeToSettingsWithDefault(const Key &groupKey,
|
||||||
|
QtcSettings *s,
|
||||||
|
const Store &store,
|
||||||
|
const Store &defaultStore);
|
||||||
|
|
||||||
} // Utils
|
} // Utils
|
||||||
|
|
||||||
|
@@ -445,7 +445,11 @@ void ClangdSettings::loadSettings()
|
|||||||
void ClangdSettings::saveSettings()
|
void ClangdSettings::saveSettings()
|
||||||
{
|
{
|
||||||
const auto settings = Core::ICore::settings();
|
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);
|
settings->beginGroup(Constants::CPPEDITOR_SETTINGSGROUP);
|
||||||
diagnosticConfigsToSettings(settings, m_data.customDiagnosticConfigs);
|
diagnosticConfigsToSettings(settings, m_data.customDiagnosticConfigs);
|
||||||
settings->endGroup();
|
settings->endGroup();
|
||||||
@@ -546,81 +550,44 @@ void ClangdProjectSettings::saveSettings()
|
|||||||
Store ClangdSettings::Data::toMap() const
|
Store ClangdSettings::Data::toMap() const
|
||||||
{
|
{
|
||||||
Store map;
|
Store map;
|
||||||
|
map.insert(useClangdKey(), useClangd);
|
||||||
map.insertValueWithDefault(useClangdKey(), useClangd, DefaultUseClangd);
|
map.insert(clangdPathKey(),
|
||||||
|
executableFilePath != fallbackClangdFilePath() ? executableFilePath.toString()
|
||||||
const QString clangdPath = executableFilePath != fallbackClangdFilePath()
|
: QString());
|
||||||
? executableFilePath.toString()
|
map.insert(clangdIndexingKey(), indexingPriority != IndexingPriority::Off);
|
||||||
: QString();
|
map.insert(clangdIndexingPriorityKey(), int(indexingPriority));
|
||||||
|
map.insert(clangdHeaderSourceSwitchModeKey(), int(headerSourceSwitchMode));
|
||||||
map.insertValueWithDefault(clangdPathKey(), clangdPath);
|
map.insert(clangdCompletionRankingModelKey(), int(completionRankingModel));
|
||||||
|
map.insert(clangdHeaderInsertionKey(), autoIncludeHeaders);
|
||||||
map.insertValueWithDefault(clangdIndexingKey(), indexingPriority != IndexingPriority::Off, true);
|
map.insert(clangdThreadLimitKey(), workerThreadLimit);
|
||||||
map.insertValueWithDefault(clangdIndexingPriorityKey(),
|
map.insert(clangdDocumentThresholdKey(), documentUpdateThreshold);
|
||||||
int(indexingPriority),
|
map.insert(clangdSizeThresholdEnabledKey(), sizeThresholdEnabled);
|
||||||
int(DefaultIndexingPriority));
|
map.insert(clangdSizeThresholdKey(), sizeThresholdInKb);
|
||||||
|
map.insert(sessionsWithOneClangdKey(), sessionsWithOneClangd);
|
||||||
map.insertValueWithDefault(clangdHeaderSourceSwitchModeKey(),
|
map.insert(diagnosticConfigIdKey(), diagnosticConfigId.toSetting());
|
||||||
int(headerSourceSwitchMode),
|
map.insert(checkedHardwareKey(), true);
|
||||||
int(DefaultHeaderSourceSwitchMode));
|
map.insert(completionResultsKey(), completionResults);
|
||||||
|
|
||||||
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());
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangdSettings::Data::fromMap(const Store &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());
|
executableFilePath = FilePath::fromString(map.value(clangdPathKey()).toString());
|
||||||
indexingPriority = IndexingPriority(
|
indexingPriority = IndexingPriority(
|
||||||
map.value(clangdIndexingPriorityKey(), int(DefaultIndexingPriority)).toInt());
|
map.value(clangdIndexingPriorityKey(), int(this->indexingPriority)).toInt());
|
||||||
const auto it = map.find(clangdIndexingKey());
|
const auto it = map.find(clangdIndexingKey());
|
||||||
if (it != map.end() && !it->toBool())
|
if (it != map.end() && !it->toBool())
|
||||||
indexingPriority = IndexingPriority::Off;
|
indexingPriority = IndexingPriority::Off;
|
||||||
headerSourceSwitchMode = HeaderSourceSwitchMode(
|
headerSourceSwitchMode = HeaderSourceSwitchMode(map.value(clangdHeaderSourceSwitchModeKey(),
|
||||||
map.value(clangdHeaderSourceSwitchModeKey(), int(DefaultHeaderSourceSwitchMode)).toInt());
|
int(headerSourceSwitchMode)).toInt());
|
||||||
completionRankingModel = CompletionRankingModel(
|
completionRankingModel = CompletionRankingModel(map.value(clangdCompletionRankingModelKey(),
|
||||||
map.value(clangdCompletionRankingModelKey(), int(DefaultCompletionRankingModel)).toInt());
|
int(completionRankingModel)).toInt());
|
||||||
autoIncludeHeaders = map.value(clangdHeaderInsertionKey(), DefaultAutoIncludeHeaders).toBool();
|
autoIncludeHeaders = map.value(clangdHeaderInsertionKey(), false).toBool();
|
||||||
workerThreadLimit = map.value(clangdThreadLimitKey(), DefaultWorkerThreadLimit).toInt();
|
workerThreadLimit = map.value(clangdThreadLimitKey(), 0).toInt();
|
||||||
documentUpdateThreshold
|
documentUpdateThreshold = map.value(clangdDocumentThresholdKey(), 500).toInt();
|
||||||
= map.value(clangdDocumentThresholdKey(), DefaultDocumentUpdateThreshold).toInt();
|
sizeThresholdEnabled = map.value(clangdSizeThresholdEnabledKey(), false).toBool();
|
||||||
sizeThresholdEnabled
|
sizeThresholdInKb = map.value(clangdSizeThresholdKey(), 1024).toLongLong();
|
||||||
= map.value(clangdSizeThresholdEnabledKey(), DefaultSizeThresholdEnabled).toBool();
|
|
||||||
sizeThresholdInKb = map.value(clangdSizeThresholdKey(), DefaultSizeThresholdInKb).toLongLong();
|
|
||||||
sessionsWithOneClangd = map.value(sessionsWithOneClangdKey()).toStringList();
|
sessionsWithOneClangd = map.value(sessionsWithOneClangdKey()).toStringList();
|
||||||
diagnosticConfigId = Id::fromSetting(map.value(diagnosticConfigIdKey(),
|
diagnosticConfigId = Id::fromSetting(map.value(diagnosticConfigIdKey(),
|
||||||
initialClangDiagnosticConfigId().toSetting()));
|
initialClangDiagnosticConfigId().toSetting()));
|
||||||
|
@@ -125,26 +125,15 @@ public:
|
|||||||
QStringList sessionsWithOneClangd;
|
QStringList sessionsWithOneClangd;
|
||||||
ClangDiagnosticConfigs customDiagnosticConfigs;
|
ClangDiagnosticConfigs customDiagnosticConfigs;
|
||||||
Utils::Id diagnosticConfigId;
|
Utils::Id diagnosticConfigId;
|
||||||
|
int workerThreadLimit = 0;
|
||||||
static constexpr auto DefaultWorkerThreadLimit = 0;
|
int documentUpdateThreshold = 500;
|
||||||
static constexpr auto DefaultDocumentUpdateThreshold = 500;
|
qint64 sizeThresholdInKb = 1024;
|
||||||
static constexpr auto DefaultSizeThresholdInKb = 1024ll;
|
bool useClangd = true;
|
||||||
static constexpr auto DefaultUseClangd = true;
|
IndexingPriority indexingPriority = IndexingPriority::Low;
|
||||||
static constexpr auto DefaultIndexingPriority = ClangdSettings::IndexingPriority::Low;
|
HeaderSourceSwitchMode headerSourceSwitchMode = HeaderSourceSwitchMode::Both;
|
||||||
static constexpr auto DefaultHeaderSourceSwitchMode = HeaderSourceSwitchMode::Both;
|
CompletionRankingModel completionRankingModel = CompletionRankingModel::Default;
|
||||||
static constexpr auto DefaultCompletionRankingModel = CompletionRankingModel::Default;
|
bool autoIncludeHeaders = false;
|
||||||
static constexpr auto DefaultAutoIncludeHeaders = false;
|
bool sizeThresholdEnabled = 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;
|
|
||||||
bool haveCheckedHardwareReqirements = false;
|
bool haveCheckedHardwareReqirements = false;
|
||||||
int completionResults = defaultCompletionResults();
|
int completionResults = defaultCompletionResults();
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user