2013-09-06 13:14:15 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2013-09-06 13:14:15 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2013-09-06 13:14:15 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2013-09-06 13:14:15 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "cppcodemodelsettings.h"
|
2016-02-22 17:18:18 +01:00
|
|
|
|
|
|
|
|
#include "clangdiagnosticconfigsmodel.h"
|
2021-08-30 10:58:08 +02:00
|
|
|
#include "cppeditorconstants.h"
|
2019-01-28 12:40:03 +01:00
|
|
|
#include "cpptoolsreuse.h"
|
2013-09-06 13:14:15 +02:00
|
|
|
|
2021-06-25 16:50:52 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2021-06-28 14:55:54 +02:00
|
|
|
#include <projectexplorer/project.h>
|
2021-11-23 17:04:13 +01:00
|
|
|
#include <projectexplorer/session.h>
|
2021-06-25 16:50:52 +02:00
|
|
|
|
2019-09-27 13:50:40 +02:00
|
|
|
#include <utils/algorithm.h>
|
2016-02-22 17:18:18 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2021-11-01 12:06:38 +01:00
|
|
|
#include <utils/qtcprocess.h>
|
2021-11-30 22:21:24 +02:00
|
|
|
#include <utils/settingsutils.h>
|
2016-02-22 17:18:18 +01:00
|
|
|
|
2021-11-10 10:48:35 +01:00
|
|
|
#include <QDateTime>
|
|
|
|
|
#include <QHash>
|
|
|
|
|
#include <QPair>
|
2015-11-11 10:47:27 +01:00
|
|
|
#include <QSettings>
|
2022-05-16 16:40:29 +02:00
|
|
|
#include <QStandardPaths>
|
2015-11-11 10:47:27 +01:00
|
|
|
|
2021-02-23 13:51:41 +01:00
|
|
|
using namespace Utils;
|
2013-09-06 13:14:15 +02:00
|
|
|
|
2021-08-30 10:58:08 +02:00
|
|
|
namespace CppEditor {
|
|
|
|
|
|
|
|
|
|
static Id initialClangDiagnosticConfigId()
|
2021-02-18 14:38:17 +01:00
|
|
|
{ return Constants::CPP_CLANG_DIAG_CONFIG_BUILDSYSTEM; }
|
2016-02-22 17:18:18 +01:00
|
|
|
|
|
|
|
|
static CppCodeModelSettings::PCHUsage initialPchUsage()
|
2018-10-31 08:37:44 +02:00
|
|
|
{ return CppCodeModelSettings::PchUse_BuildSystem; }
|
2016-02-22 17:18:18 +01:00
|
|
|
|
2019-01-14 15:06:28 +01:00
|
|
|
static QString enableLowerClazyLevelsKey()
|
|
|
|
|
{ return QLatin1String("enableLowerClazyLevels"); }
|
|
|
|
|
|
2016-02-22 17:18:18 +01:00
|
|
|
static QString pchUsageKey()
|
2021-08-30 10:58:08 +02:00
|
|
|
{ return QLatin1String(Constants::CPPEDITOR_MODEL_MANAGER_PCH_USAGE); }
|
2013-12-10 14:32:09 +01:00
|
|
|
|
2017-01-12 18:01:12 +01:00
|
|
|
static QString interpretAmbiguousHeadersAsCHeadersKey()
|
2021-08-30 10:58:08 +02:00
|
|
|
{ return QLatin1String(Constants::CPPEDITOR_INTERPRET_AMBIGIUOUS_HEADERS_AS_C_HEADERS); }
|
2017-01-12 18:01:12 +01:00
|
|
|
|
2016-08-16 13:37:49 +02:00
|
|
|
static QString skipIndexingBigFilesKey()
|
2021-08-30 10:58:08 +02:00
|
|
|
{ return QLatin1String(Constants::CPPEDITOR_SKIP_INDEXING_BIG_FILES); }
|
2016-08-16 13:37:49 +02:00
|
|
|
|
|
|
|
|
static QString indexerFileSizeLimitKey()
|
2021-08-30 10:58:08 +02:00
|
|
|
{ return QLatin1String(Constants::CPPEDITOR_INDEXER_FILE_SIZE_LIMIT); }
|
2016-08-16 13:37:49 +02:00
|
|
|
|
2021-06-28 14:55:54 +02:00
|
|
|
static QString clangdSettingsKey() { return QLatin1String("ClangdSettings"); }
|
2022-01-27 11:16:46 +01:00
|
|
|
static QString useClangdKey() { return QLatin1String("UseClangdV7"); }
|
2021-02-23 13:51:41 +01:00
|
|
|
static QString clangdPathKey() { return QLatin1String("ClangdPath"); }
|
2021-06-25 17:40:20 +02:00
|
|
|
static QString clangdIndexingKey() { return QLatin1String("ClangdIndexing"); }
|
2021-10-27 11:03:42 +02:00
|
|
|
static QString clangdHeaderInsertionKey() { return QLatin1String("ClangdHeaderInsertion"); }
|
2021-06-25 18:16:08 +02:00
|
|
|
static QString clangdThreadLimitKey() { return QLatin1String("ClangdThreadLimit"); }
|
2021-08-12 12:00:58 +02:00
|
|
|
static QString clangdDocumentThresholdKey() { return QLatin1String("ClangdDocumentThreshold"); }
|
2022-03-29 15:47:10 +02:00
|
|
|
static QString clangdSizeThresholdEnabledKey() { return QLatin1String("ClangdSizeThresholdEnabled"); }
|
|
|
|
|
static QString clangdSizeThresholdKey() { return QLatin1String("ClangdSizeThreshold"); }
|
2021-06-28 14:55:54 +02:00
|
|
|
static QString clangdUseGlobalSettingsKey() { return QLatin1String("useGlobalSettings"); }
|
2021-11-23 17:04:13 +01:00
|
|
|
static QString sessionsWithOneClangdKey() { return QLatin1String("SessionsWithOneClangd"); }
|
2022-05-19 14:48:09 +02:00
|
|
|
static QString diagnosticConfigIdKey() { return QLatin1String("diagnosticConfigId"); }
|
2021-02-23 13:51:41 +01:00
|
|
|
|
|
|
|
|
static FilePath g_defaultClangdFilePath;
|
|
|
|
|
static FilePath fallbackClangdFilePath()
|
|
|
|
|
{
|
|
|
|
|
if (g_defaultClangdFilePath.exists())
|
|
|
|
|
return g_defaultClangdFilePath;
|
2022-06-15 13:49:38 +02:00
|
|
|
return Environment::systemEnvironment().searchInPath("clangd");
|
2021-02-23 13:51:41 +01:00
|
|
|
}
|
|
|
|
|
|
2018-01-19 13:18:43 +01:00
|
|
|
void CppCodeModelSettings::fromSettings(QSettings *s)
|
|
|
|
|
{
|
2021-08-30 10:58:08 +02:00
|
|
|
s->beginGroup(QLatin1String(Constants::CPPEDITOR_SETTINGSGROUP));
|
2018-01-19 13:18:43 +01:00
|
|
|
|
2019-01-14 15:06:28 +01:00
|
|
|
setEnableLowerClazyLevels(s->value(enableLowerClazyLevelsKey(), true).toBool());
|
|
|
|
|
|
2016-02-22 17:18:18 +01:00
|
|
|
const QVariant pchUsageVariant = s->value(pchUsageKey(), initialPchUsage());
|
|
|
|
|
setPCHUsage(static_cast<PCHUsage>(pchUsageVariant.toInt()));
|
2016-08-16 13:37:49 +02:00
|
|
|
|
2017-01-12 18:01:12 +01:00
|
|
|
const QVariant interpretAmbiguousHeadersAsCHeaders
|
|
|
|
|
= s->value(interpretAmbiguousHeadersAsCHeadersKey(), false);
|
|
|
|
|
setInterpretAmbigiousHeadersAsCHeaders(interpretAmbiguousHeadersAsCHeaders.toBool());
|
|
|
|
|
|
2016-08-16 13:37:49 +02:00
|
|
|
const QVariant skipIndexingBigFiles = s->value(skipIndexingBigFilesKey(), true);
|
|
|
|
|
setSkipIndexingBigFiles(skipIndexingBigFiles.toBool());
|
|
|
|
|
|
|
|
|
|
const QVariant indexerFileSizeLimit = s->value(indexerFileSizeLimitKey(), 5);
|
|
|
|
|
setIndexerFileSizeLimitInMb(indexerFileSizeLimit.toInt());
|
|
|
|
|
|
2013-09-06 13:14:15 +02:00
|
|
|
s->endGroup();
|
2015-05-08 15:48:17 +02:00
|
|
|
|
|
|
|
|
emit changed();
|
2013-09-06 13:14:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppCodeModelSettings::toSettings(QSettings *s)
|
|
|
|
|
{
|
2021-08-30 10:58:08 +02:00
|
|
|
s->beginGroup(QLatin1String(Constants::CPPEDITOR_SETTINGSGROUP));
|
2016-02-22 17:18:18 +01:00
|
|
|
|
2019-01-14 15:06:28 +01:00
|
|
|
s->setValue(enableLowerClazyLevelsKey(), enableLowerClazyLevels());
|
2016-02-22 17:18:18 +01:00
|
|
|
s->setValue(pchUsageKey(), pchUsage());
|
2017-01-12 18:01:12 +01:00
|
|
|
|
|
|
|
|
s->setValue(interpretAmbiguousHeadersAsCHeadersKey(), interpretAmbigiousHeadersAsCHeaders());
|
2016-08-16 13:37:49 +02:00
|
|
|
s->setValue(skipIndexingBigFilesKey(), skipIndexingBigFiles());
|
|
|
|
|
s->setValue(indexerFileSizeLimitKey(), indexerFileSizeLimitInMb());
|
2013-09-06 13:14:15 +02:00
|
|
|
|
2015-11-11 10:47:27 +01:00
|
|
|
s->endGroup();
|
2015-06-02 17:25:41 +02:00
|
|
|
|
2015-05-08 15:48:17 +02:00
|
|
|
emit changed();
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-11 10:47:27 +01:00
|
|
|
CppCodeModelSettings::PCHUsage CppCodeModelSettings::pchUsage() const
|
2013-09-06 13:14:15 +02:00
|
|
|
{
|
2015-11-11 10:47:27 +01:00
|
|
|
return m_pchUsage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppCodeModelSettings::setPCHUsage(CppCodeModelSettings::PCHUsage pchUsage)
|
|
|
|
|
{
|
|
|
|
|
m_pchUsage = pchUsage;
|
2013-09-06 13:14:15 +02:00
|
|
|
}
|
2016-08-16 13:37:49 +02:00
|
|
|
|
2017-01-12 18:01:12 +01:00
|
|
|
bool CppCodeModelSettings::interpretAmbigiousHeadersAsCHeaders() const
|
|
|
|
|
{
|
|
|
|
|
return m_interpretAmbigiousHeadersAsCHeaders;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppCodeModelSettings::setInterpretAmbigiousHeadersAsCHeaders(bool yesno)
|
|
|
|
|
{
|
|
|
|
|
m_interpretAmbigiousHeadersAsCHeaders = yesno;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-16 13:37:49 +02:00
|
|
|
bool CppCodeModelSettings::skipIndexingBigFiles() const
|
|
|
|
|
{
|
|
|
|
|
return m_skipIndexingBigFiles;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppCodeModelSettings::setSkipIndexingBigFiles(bool yesno)
|
|
|
|
|
{
|
|
|
|
|
m_skipIndexingBigFiles = yesno;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CppCodeModelSettings::indexerFileSizeLimitInMb() const
|
|
|
|
|
{
|
|
|
|
|
return m_indexerFileSizeLimitInMB;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppCodeModelSettings::setIndexerFileSizeLimitInMb(int sizeInMB)
|
|
|
|
|
{
|
|
|
|
|
m_indexerFileSizeLimitInMB = sizeInMB;
|
|
|
|
|
}
|
2019-01-14 15:06:28 +01:00
|
|
|
|
|
|
|
|
bool CppCodeModelSettings::enableLowerClazyLevels() const
|
|
|
|
|
{
|
|
|
|
|
return m_enableLowerClazyLevels;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppCodeModelSettings::setEnableLowerClazyLevels(bool yesno)
|
|
|
|
|
{
|
|
|
|
|
m_enableLowerClazyLevels = yesno;
|
|
|
|
|
}
|
2021-02-23 13:51:41 +01:00
|
|
|
|
2021-06-25 16:50:52 +02:00
|
|
|
|
|
|
|
|
ClangdSettings &ClangdSettings::instance()
|
|
|
|
|
{
|
|
|
|
|
static ClangdSettings settings;
|
|
|
|
|
return settings;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-23 17:04:13 +01:00
|
|
|
ClangdSettings::ClangdSettings()
|
|
|
|
|
{
|
|
|
|
|
loadSettings();
|
|
|
|
|
const auto sessionMgr = ProjectExplorer::SessionManager::instance();
|
|
|
|
|
connect(sessionMgr, &ProjectExplorer::SessionManager::sessionRemoved,
|
|
|
|
|
this, [this](const QString &name) { m_data.sessionsWithOneClangd.removeOne(name); });
|
|
|
|
|
connect(sessionMgr, &ProjectExplorer::SessionManager::sessionRenamed,
|
|
|
|
|
this, [this](const QString &oldName, const QString &newName) {
|
|
|
|
|
const auto index = m_data.sessionsWithOneClangd.indexOf(oldName);
|
|
|
|
|
if (index != -1)
|
|
|
|
|
m_data.sessionsWithOneClangd[index] = newName;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-01 12:06:38 +01:00
|
|
|
bool ClangdSettings::useClangd() const
|
|
|
|
|
{
|
2022-05-02 17:18:46 +02:00
|
|
|
return m_data.useClangd && clangdVersion() >= QVersionNumber(14);
|
2021-11-01 12:06:38 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-12 09:39:02 +02:00
|
|
|
void ClangdSettings::setDefaultClangdPath(const FilePath &filePath)
|
2021-02-23 13:51:41 +01:00
|
|
|
{
|
|
|
|
|
g_defaultClangdFilePath = filePath;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-19 14:48:09 +02:00
|
|
|
void ClangdSettings::setCustomDiagnosticConfigs(const ClangDiagnosticConfigs &configs)
|
|
|
|
|
{
|
|
|
|
|
if (instance().customDiagnosticConfigs() == configs)
|
|
|
|
|
return;
|
|
|
|
|
instance().m_data.customDiagnosticConfigs = configs;
|
|
|
|
|
instance().saveSettings();
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-28 14:55:54 +02:00
|
|
|
FilePath ClangdSettings::clangdFilePath() const
|
2021-02-23 13:51:41 +01:00
|
|
|
{
|
2021-06-28 14:55:54 +02:00
|
|
|
if (!m_data.executableFilePath.isEmpty())
|
|
|
|
|
return m_data.executableFilePath;
|
2021-02-23 13:51:41 +01:00
|
|
|
return fallbackClangdFilePath();
|
|
|
|
|
}
|
2021-06-25 16:50:52 +02:00
|
|
|
|
2022-03-29 15:47:10 +02:00
|
|
|
bool ClangdSettings::sizeIsOkay(const Utils::FilePath &fp) const
|
|
|
|
|
{
|
|
|
|
|
return !sizeThresholdEnabled() || sizeThresholdInKb() * 1024 >= fp.fileSize();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-19 14:48:09 +02:00
|
|
|
ClangDiagnosticConfigs ClangdSettings::customDiagnosticConfigs() const
|
|
|
|
|
{
|
|
|
|
|
return m_data.customDiagnosticConfigs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Id ClangdSettings::diagnosticConfigId() const
|
|
|
|
|
{
|
|
|
|
|
if (!diagnosticConfigsModel().hasConfigWithId(m_data.diagnosticConfigId))
|
|
|
|
|
return initialClangDiagnosticConfigId();
|
|
|
|
|
return m_data.diagnosticConfigId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClangDiagnosticConfig ClangdSettings::diagnosticConfig() const
|
|
|
|
|
{
|
|
|
|
|
return diagnosticConfigsModel(customDiagnosticConfigs()).configWithId(diagnosticConfigId());
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-23 17:04:13 +01:00
|
|
|
ClangdSettings::Granularity ClangdSettings::granularity() const
|
|
|
|
|
{
|
|
|
|
|
if (m_data.sessionsWithOneClangd.contains(ProjectExplorer::SessionManager::activeSession()))
|
|
|
|
|
return Granularity::Session;
|
|
|
|
|
return Granularity::Project;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-25 16:50:52 +02:00
|
|
|
void ClangdSettings::setData(const Data &data)
|
|
|
|
|
{
|
2021-06-28 14:55:54 +02:00
|
|
|
if (this == &instance() && data != m_data) {
|
|
|
|
|
m_data = data;
|
|
|
|
|
saveSettings();
|
2021-07-01 04:17:54 +02:00
|
|
|
emit changed();
|
2021-06-25 16:50:52 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-01 12:06:38 +01:00
|
|
|
static QVersionNumber getClangdVersion(const FilePath &clangdFilePath)
|
|
|
|
|
{
|
|
|
|
|
Utils::QtcProcess clangdProc;
|
|
|
|
|
clangdProc.setCommand({clangdFilePath, {"--version"}});
|
|
|
|
|
clangdProc.start();
|
|
|
|
|
if (!clangdProc.waitForStarted() || !clangdProc.waitForFinished())
|
|
|
|
|
return{};
|
|
|
|
|
const QString output = clangdProc.allOutput();
|
|
|
|
|
static const QString versionPrefix = "clangd version ";
|
|
|
|
|
const int prefixOffset = output.indexOf(versionPrefix);
|
|
|
|
|
if (prefixOffset == -1)
|
|
|
|
|
return {};
|
|
|
|
|
return QVersionNumber::fromString(output.mid(prefixOffset + versionPrefix.length()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVersionNumber ClangdSettings::clangdVersion(const FilePath &clangdFilePath)
|
|
|
|
|
{
|
2021-11-10 10:48:35 +01:00
|
|
|
static QHash<Utils::FilePath, QPair<QDateTime, QVersionNumber>> versionCache;
|
2021-11-01 12:06:38 +01:00
|
|
|
const QDateTime timeStamp = clangdFilePath.lastModified();
|
2021-11-10 10:48:35 +01:00
|
|
|
const auto it = versionCache.find(clangdFilePath);
|
|
|
|
|
if (it == versionCache.end()) {
|
2021-11-01 12:06:38 +01:00
|
|
|
const QVersionNumber version = getClangdVersion(clangdFilePath);
|
2021-11-10 10:48:35 +01:00
|
|
|
versionCache.insert(clangdFilePath, qMakePair(timeStamp, version));
|
2021-11-01 12:06:38 +01:00
|
|
|
return version;
|
|
|
|
|
}
|
|
|
|
|
if (it->first != timeStamp) {
|
|
|
|
|
it->first = timeStamp;
|
|
|
|
|
it->second = getClangdVersion(clangdFilePath);
|
|
|
|
|
}
|
|
|
|
|
return it->second;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-03 13:06:49 +02:00
|
|
|
FilePath ClangdSettings::clangdIncludePath() const
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(useClangd(), return {});
|
|
|
|
|
FilePath clangdPath = clangdFilePath();
|
|
|
|
|
QTC_ASSERT(!clangdPath.isEmpty() && clangdPath.exists(), return {});
|
|
|
|
|
const QVersionNumber version = clangdVersion();
|
|
|
|
|
QTC_ASSERT(!version.isNull(), return {});
|
2022-06-01 14:52:16 -07:00
|
|
|
static const QStringList libDirs{"lib", "lib64"};
|
|
|
|
|
for (const QString &libDir : libDirs) {
|
|
|
|
|
const FilePath includePath = clangdPath.absolutePath().parentDir().pathAppended(libDir)
|
|
|
|
|
.pathAppended("clang").pathAppended(version.toString()).pathAppended("include");
|
|
|
|
|
if (includePath.exists())
|
|
|
|
|
return includePath;
|
|
|
|
|
}
|
|
|
|
|
QTC_CHECK(false);
|
|
|
|
|
return {};
|
2022-05-03 13:06:49 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-16 16:40:29 +02:00
|
|
|
FilePath ClangdSettings::clangdUserConfigFilePath()
|
|
|
|
|
{
|
|
|
|
|
return FilePath::fromString(
|
|
|
|
|
QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation))
|
|
|
|
|
/ "clangd/config.yaml";
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-25 16:50:52 +02:00
|
|
|
void ClangdSettings::loadSettings()
|
|
|
|
|
{
|
2022-05-19 14:48:09 +02:00
|
|
|
const auto settings = Core::ICore::settings();
|
|
|
|
|
Utils::fromSettings(clangdSettingsKey(), {}, settings, &m_data);
|
|
|
|
|
|
|
|
|
|
settings->beginGroup(QLatin1String(Constants::CPPEDITOR_SETTINGSGROUP));
|
|
|
|
|
m_data.customDiagnosticConfigs = diagnosticConfigsFromSettings(settings);
|
|
|
|
|
|
|
|
|
|
// Pre-8.0 compat
|
|
|
|
|
static const QString oldKey("ClangDiagnosticConfig");
|
|
|
|
|
const QVariant configId = settings->value(oldKey);
|
|
|
|
|
if (configId.isValid()) {
|
|
|
|
|
m_data.diagnosticConfigId = Id::fromSetting(configId);
|
|
|
|
|
settings->setValue(oldKey, {});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
settings->endGroup();
|
2021-06-25 16:50:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangdSettings::saveSettings()
|
|
|
|
|
{
|
2022-05-19 14:48:09 +02:00
|
|
|
const auto settings = Core::ICore::settings();
|
|
|
|
|
Utils::toSettings(clangdSettingsKey(), {}, settings, &m_data);
|
|
|
|
|
settings->beginGroup(QLatin1String(Constants::CPPEDITOR_SETTINGSGROUP));
|
|
|
|
|
diagnosticConfigsToSettings(settings, m_data.customDiagnosticConfigs);
|
|
|
|
|
settings->endGroup();
|
2021-06-25 16:50:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
void ClangdSettings::setUseClangd(bool use) { instance().m_data.useClangd = use; }
|
2021-08-12 09:39:02 +02:00
|
|
|
|
|
|
|
|
void ClangdSettings::setClangdFilePath(const FilePath &filePath)
|
2021-06-25 16:50:52 +02:00
|
|
|
{
|
|
|
|
|
instance().m_data.executableFilePath = filePath;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2021-06-28 14:55:54 +02:00
|
|
|
|
|
|
|
|
ClangdProjectSettings::ClangdProjectSettings(ProjectExplorer::Project *project) : m_project(project)
|
|
|
|
|
{
|
|
|
|
|
loadSettings();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-01 04:17:54 +02:00
|
|
|
ClangdSettings::Data ClangdProjectSettings::settings() const
|
2021-06-28 14:55:54 +02:00
|
|
|
{
|
|
|
|
|
if (m_useGlobalSettings)
|
2021-07-01 04:17:54 +02:00
|
|
|
return ClangdSettings::instance().data();
|
2021-11-23 17:04:13 +01:00
|
|
|
ClangdSettings::Data data = m_customSettings;
|
|
|
|
|
|
|
|
|
|
// This property is global by definition.
|
|
|
|
|
data.sessionsWithOneClangd = ClangdSettings::instance().data().sessionsWithOneClangd;
|
|
|
|
|
|
2022-05-19 14:48:09 +02:00
|
|
|
// This list exists only once.
|
|
|
|
|
data.customDiagnosticConfigs = ClangdSettings::instance().data().customDiagnosticConfigs;
|
|
|
|
|
|
2021-11-23 17:04:13 +01:00
|
|
|
return data;
|
2021-06-28 14:55:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangdProjectSettings::setSettings(const ClangdSettings::Data &data)
|
|
|
|
|
{
|
|
|
|
|
m_customSettings = data;
|
|
|
|
|
saveSettings();
|
2022-05-19 14:48:09 +02:00
|
|
|
ClangdSettings::setCustomDiagnosticConfigs(data.customDiagnosticConfigs);
|
2021-07-01 04:17:54 +02:00
|
|
|
emit ClangdSettings::instance().changed();
|
2021-06-28 14:55:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangdProjectSettings::setUseGlobalSettings(bool useGlobal)
|
|
|
|
|
{
|
|
|
|
|
m_useGlobalSettings = useGlobal;
|
|
|
|
|
saveSettings();
|
2021-07-01 04:17:54 +02:00
|
|
|
emit ClangdSettings::instance().changed();
|
2021-06-28 14:55:54 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-19 14:48:09 +02:00
|
|
|
void ClangdProjectSettings::setDiagnosticConfigId(Utils::Id configId)
|
|
|
|
|
{
|
|
|
|
|
m_customSettings.diagnosticConfigId = configId;
|
|
|
|
|
saveSettings();
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-28 14:55:54 +02:00
|
|
|
void ClangdProjectSettings::loadSettings()
|
|
|
|
|
{
|
|
|
|
|
if (!m_project)
|
|
|
|
|
return;
|
|
|
|
|
const QVariantMap data = m_project->namedSettings(clangdSettingsKey()).toMap();
|
|
|
|
|
m_useGlobalSettings = data.value(clangdUseGlobalSettingsKey(), true).toBool();
|
|
|
|
|
if (!m_useGlobalSettings)
|
|
|
|
|
m_customSettings.fromMap(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangdProjectSettings::saveSettings()
|
|
|
|
|
{
|
|
|
|
|
if (!m_project)
|
|
|
|
|
return;
|
|
|
|
|
QVariantMap data;
|
|
|
|
|
if (!m_useGlobalSettings)
|
|
|
|
|
data = m_customSettings.toMap();
|
|
|
|
|
data.insert(clangdUseGlobalSettingsKey(), m_useGlobalSettings);
|
|
|
|
|
m_project->setNamedSettings(clangdSettingsKey(), data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap ClangdSettings::Data::toMap() const
|
|
|
|
|
{
|
|
|
|
|
QVariantMap map;
|
|
|
|
|
map.insert(useClangdKey(), useClangd);
|
2022-05-04 14:46:02 +02:00
|
|
|
map.insert(clangdPathKey(),
|
|
|
|
|
executableFilePath != fallbackClangdFilePath() ? executableFilePath.toString()
|
|
|
|
|
: QString());
|
2021-06-28 14:55:54 +02:00
|
|
|
map.insert(clangdIndexingKey(), enableIndexing);
|
2021-10-27 11:03:42 +02:00
|
|
|
map.insert(clangdHeaderInsertionKey(), autoIncludeHeaders);
|
2021-06-28 14:55:54 +02:00
|
|
|
map.insert(clangdThreadLimitKey(), workerThreadLimit);
|
2021-08-12 12:00:58 +02:00
|
|
|
map.insert(clangdDocumentThresholdKey(), documentUpdateThreshold);
|
2022-03-29 15:47:10 +02:00
|
|
|
map.insert(clangdSizeThresholdEnabledKey(), sizeThresholdEnabled);
|
|
|
|
|
map.insert(clangdSizeThresholdKey(), sizeThresholdInKb);
|
2021-11-23 17:04:13 +01:00
|
|
|
map.insert(sessionsWithOneClangdKey(), sessionsWithOneClangd);
|
2022-05-19 14:48:09 +02:00
|
|
|
map.insert(diagnosticConfigIdKey(), diagnosticConfigId.toSetting());
|
2021-06-28 14:55:54 +02:00
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangdSettings::Data::fromMap(const QVariantMap &map)
|
|
|
|
|
{
|
2022-01-27 11:16:46 +01:00
|
|
|
useClangd = map.value(useClangdKey(), true).toBool();
|
2021-06-28 14:55:54 +02:00
|
|
|
executableFilePath = FilePath::fromString(map.value(clangdPathKey()).toString());
|
|
|
|
|
enableIndexing = map.value(clangdIndexingKey(), true).toBool();
|
2021-10-27 11:03:42 +02:00
|
|
|
autoIncludeHeaders = map.value(clangdHeaderInsertionKey(), false).toBool();
|
2021-06-28 14:55:54 +02:00
|
|
|
workerThreadLimit = map.value(clangdThreadLimitKey(), 0).toInt();
|
2021-08-12 12:00:58 +02:00
|
|
|
documentUpdateThreshold = map.value(clangdDocumentThresholdKey(), 500).toInt();
|
2022-03-29 15:47:10 +02:00
|
|
|
sizeThresholdEnabled = map.value(clangdSizeThresholdEnabledKey(), false).toBool();
|
|
|
|
|
sizeThresholdInKb = map.value(clangdSizeThresholdKey(), 1024).toLongLong();
|
2021-11-23 17:04:13 +01:00
|
|
|
sessionsWithOneClangd = map.value(sessionsWithOneClangdKey()).toStringList();
|
2022-05-19 14:48:09 +02:00
|
|
|
diagnosticConfigId = Id::fromSetting(map.value(diagnosticConfigIdKey(),
|
|
|
|
|
initialClangDiagnosticConfigId().toSetting()));
|
2021-06-28 14:55:54 +02:00
|
|
|
}
|
2021-08-30 10:58:08 +02:00
|
|
|
|
|
|
|
|
} // namespace CppEditor
|