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>
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
static QString clangDiagnosticConfigKey()
|
|
|
|
|
{ return QStringLiteral("ClangDiagnosticConfig"); }
|
|
|
|
|
|
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"); }
|
2021-02-23 13:51:41 +01:00
|
|
|
|
|
|
|
|
static FilePath g_defaultClangdFilePath;
|
|
|
|
|
static FilePath fallbackClangdFilePath()
|
|
|
|
|
{
|
|
|
|
|
if (g_defaultClangdFilePath.exists())
|
|
|
|
|
return g_defaultClangdFilePath;
|
2021-08-10 16:19:02 +02:00
|
|
|
return "clangd";
|
2021-02-23 13:51:41 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-12 09:39:02 +02:00
|
|
|
static Id clangDiagnosticConfigIdFromSettings(QSettings *s)
|
2018-01-19 13:18:43 +01:00
|
|
|
{
|
2021-08-30 10:58:08 +02:00
|
|
|
QTC_ASSERT(s->group() == QLatin1String(Constants::CPPEDITOR_SETTINGSGROUP), return Id());
|
2018-01-19 13:18:43 +01:00
|
|
|
|
2021-08-12 09:39:02 +02:00
|
|
|
return Id::fromSetting(
|
2018-01-19 13:18:43 +01:00
|
|
|
s->value(clangDiagnosticConfigKey(), initialClangDiagnosticConfigId().toSetting()));
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-27 13:50:40 +02:00
|
|
|
// Removed since Qt Creator 4.11
|
|
|
|
|
static ClangDiagnosticConfigs removedBuiltinConfigs()
|
|
|
|
|
{
|
|
|
|
|
ClangDiagnosticConfigs configs;
|
|
|
|
|
|
|
|
|
|
// Pedantic
|
|
|
|
|
ClangDiagnosticConfig config;
|
|
|
|
|
config.setId("Builtin.Pedantic");
|
|
|
|
|
config.setDisplayName(QCoreApplication::translate("ClangDiagnosticConfigsModel",
|
|
|
|
|
"Pedantic checks"));
|
|
|
|
|
config.setIsReadOnly(true);
|
|
|
|
|
config.setClangOptions(QStringList{QStringLiteral("-Wpedantic")});
|
2020-05-27 15:04:59 +02:00
|
|
|
config.setClangTidyMode(ClangDiagnosticConfig::TidyMode::UseCustomChecks);
|
|
|
|
|
config.setClazyMode(ClangDiagnosticConfig::ClazyMode::UseCustomChecks);
|
2019-09-27 13:50:40 +02:00
|
|
|
configs << config;
|
|
|
|
|
|
|
|
|
|
// Everything with exceptions
|
|
|
|
|
config = ClangDiagnosticConfig();
|
|
|
|
|
config.setId("Builtin.EverythingWithExceptions");
|
|
|
|
|
config.setDisplayName(QCoreApplication::translate(
|
|
|
|
|
"ClangDiagnosticConfigsModel",
|
|
|
|
|
"Checks for almost everything"));
|
|
|
|
|
config.setIsReadOnly(true);
|
|
|
|
|
config.setClangOptions(QStringList{
|
|
|
|
|
QStringLiteral("-Weverything"),
|
|
|
|
|
QStringLiteral("-Wno-c++98-compat"),
|
|
|
|
|
QStringLiteral("-Wno-c++98-compat-pedantic"),
|
|
|
|
|
QStringLiteral("-Wno-unused-macros"),
|
|
|
|
|
QStringLiteral("-Wno-newline-eof"),
|
|
|
|
|
QStringLiteral("-Wno-exit-time-destructors"),
|
|
|
|
|
QStringLiteral("-Wno-global-constructors"),
|
|
|
|
|
QStringLiteral("-Wno-gnu-zero-variadic-macro-arguments"),
|
|
|
|
|
QStringLiteral("-Wno-documentation"),
|
|
|
|
|
QStringLiteral("-Wno-shadow"),
|
|
|
|
|
QStringLiteral("-Wno-switch-enum"),
|
|
|
|
|
QStringLiteral("-Wno-missing-prototypes"), // Not optimal for C projects.
|
|
|
|
|
QStringLiteral("-Wno-used-but-marked-unused"), // e.g. QTest::qWait
|
|
|
|
|
});
|
2020-05-27 15:04:59 +02:00
|
|
|
config.setClangTidyMode(ClangDiagnosticConfig::TidyMode::UseCustomChecks);
|
|
|
|
|
config.setClazyMode(ClangDiagnosticConfig::ClazyMode::UseCustomChecks);
|
2019-09-27 13:50:40 +02:00
|
|
|
configs << config;
|
|
|
|
|
|
|
|
|
|
return configs;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-12 09:39:02 +02:00
|
|
|
static ClangDiagnosticConfig convertToCustomConfig(const Id &id)
|
2019-09-27 13:50:40 +02:00
|
|
|
{
|
|
|
|
|
const ClangDiagnosticConfig config
|
2021-08-30 10:58:08 +02:00
|
|
|
= findOrDefault(removedBuiltinConfigs(), [id](const ClangDiagnosticConfig &config) {
|
2019-09-27 13:50:40 +02:00
|
|
|
return config.id() == id;
|
|
|
|
|
});
|
|
|
|
|
return ClangDiagnosticConfigsModel::createCustomConfig(config, config.displayName());
|
|
|
|
|
}
|
|
|
|
|
|
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-09-25 15:46:15 +02:00
|
|
|
setClangCustomDiagnosticConfigs(diagnosticConfigsFromSettings(s));
|
2018-01-19 13:18:43 +01:00
|
|
|
setClangDiagnosticConfigId(clangDiagnosticConfigIdFromSettings(s));
|
2016-02-22 17:18:18 +01:00
|
|
|
|
2019-09-27 13:50:40 +02:00
|
|
|
// Qt Creator 4.11 removes some built-in configs.
|
|
|
|
|
bool write = false;
|
2021-08-12 09:39:02 +02:00
|
|
|
const Id id = m_clangDiagnosticConfigId;
|
2019-09-27 13:50:40 +02:00
|
|
|
if (id == "Builtin.Pedantic" || id == "Builtin.EverythingWithExceptions") {
|
|
|
|
|
// If one of them was used, continue to use it, but convert it to a custom config.
|
|
|
|
|
const ClangDiagnosticConfig customConfig = convertToCustomConfig(id);
|
|
|
|
|
m_clangCustomDiagnosticConfigs.append(customConfig);
|
|
|
|
|
m_clangDiagnosticConfigId = customConfig.id();
|
|
|
|
|
write = true;
|
2018-11-08 13:02:01 +01:00
|
|
|
}
|
|
|
|
|
|
2019-09-27 13:50:40 +02:00
|
|
|
// Before Qt Creator 4.8, inconsistent settings might have been written.
|
|
|
|
|
const ClangDiagnosticConfigsModel model = diagnosticConfigsModel(m_clangCustomDiagnosticConfigs);
|
|
|
|
|
if (!model.hasConfigWithId(m_clangDiagnosticConfigId))
|
|
|
|
|
setClangDiagnosticConfigId(initialClangDiagnosticConfigId());
|
|
|
|
|
|
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
|
|
|
|
2019-09-27 13:50:40 +02:00
|
|
|
if (write)
|
|
|
|
|
toSettings(s);
|
|
|
|
|
|
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));
|
2019-09-25 15:46:15 +02:00
|
|
|
const ClangDiagnosticConfigs previousConfigs = diagnosticConfigsFromSettings(s);
|
2021-08-12 09:39:02 +02:00
|
|
|
const Id previousConfigId = clangDiagnosticConfigIdFromSettings(s);
|
2015-11-11 10:47:27 +01:00
|
|
|
|
2019-09-25 15:46:15 +02:00
|
|
|
diagnosticConfigsToSettings(s, m_clangCustomDiagnosticConfigs);
|
2016-02-22 17:18:18 +01:00
|
|
|
|
|
|
|
|
s->setValue(clangDiagnosticConfigKey(), clangDiagnosticConfigId().toSetting());
|
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
|
|
|
|
2021-08-12 09:39:02 +02:00
|
|
|
QVector<Id> invalidated
|
2018-01-19 13:18:43 +01:00
|
|
|
= ClangDiagnosticConfigsModel::changedOrRemovedConfigs(previousConfigs,
|
|
|
|
|
m_clangCustomDiagnosticConfigs);
|
|
|
|
|
|
|
|
|
|
if (previousConfigId != clangDiagnosticConfigId() && !invalidated.contains(previousConfigId))
|
|
|
|
|
invalidated.append(previousConfigId);
|
|
|
|
|
|
|
|
|
|
if (!invalidated.isEmpty())
|
|
|
|
|
emit clangDiagnosticConfigsInvalidated(invalidated);
|
2015-05-08 15:48:17 +02:00
|
|
|
emit changed();
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-12 09:39:02 +02:00
|
|
|
Id CppCodeModelSettings::clangDiagnosticConfigId() const
|
2016-02-22 17:18:18 +01:00
|
|
|
{
|
2019-10-01 16:53:01 +02:00
|
|
|
if (!diagnosticConfigsModel().hasConfigWithId(m_clangDiagnosticConfigId))
|
|
|
|
|
return defaultClangDiagnosticConfigId();
|
2016-02-22 17:18:18 +01:00
|
|
|
return m_clangDiagnosticConfigId;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-12 09:39:02 +02:00
|
|
|
void CppCodeModelSettings::setClangDiagnosticConfigId(const Id &configId)
|
2015-11-10 16:54:53 +01:00
|
|
|
{
|
2016-02-22 17:18:18 +01:00
|
|
|
m_clangDiagnosticConfigId = configId;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-12 09:39:02 +02:00
|
|
|
Id CppCodeModelSettings::defaultClangDiagnosticConfigId()
|
2018-11-08 12:05:46 +01:00
|
|
|
{
|
2019-10-01 16:53:01 +02:00
|
|
|
return initialClangDiagnosticConfigId();
|
2018-11-08 12:05:46 +01:00
|
|
|
}
|
|
|
|
|
|
2016-02-22 17:18:18 +01:00
|
|
|
const ClangDiagnosticConfig CppCodeModelSettings::clangDiagnosticConfig() const
|
|
|
|
|
{
|
2019-09-25 15:46:15 +02:00
|
|
|
const ClangDiagnosticConfigsModel configsModel = diagnosticConfigsModel(
|
|
|
|
|
m_clangCustomDiagnosticConfigs);
|
2016-02-22 17:18:18 +01:00
|
|
|
|
|
|
|
|
return configsModel.configWithId(clangDiagnosticConfigId());
|
2015-11-10 16:54:53 +01:00
|
|
|
}
|
|
|
|
|
|
2016-02-22 17:18:18 +01:00
|
|
|
ClangDiagnosticConfigs CppCodeModelSettings::clangCustomDiagnosticConfigs() const
|
2015-11-10 16:54:53 +01:00
|
|
|
{
|
2016-02-22 17:18:18 +01:00
|
|
|
return m_clangCustomDiagnosticConfigs;
|
2015-11-10 16:54:53 +01:00
|
|
|
}
|
|
|
|
|
|
2016-02-22 17:18:18 +01:00
|
|
|
void CppCodeModelSettings::setClangCustomDiagnosticConfigs(const ClangDiagnosticConfigs &configs)
|
2015-11-10 16:54:53 +01:00
|
|
|
{
|
2016-02-22 17:18:18 +01:00
|
|
|
m_clangCustomDiagnosticConfigs = configs;
|
2015-11-10 16:54:53 +01:00
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-25 16:50:52 +02:00
|
|
|
void ClangdSettings::loadSettings()
|
|
|
|
|
{
|
2021-12-07 10:55:39 +01:00
|
|
|
Utils::fromSettings(clangdSettingsKey(), {}, Core::ICore::settings(), &m_data);
|
2021-06-25 16:50:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangdSettings::saveSettings()
|
|
|
|
|
{
|
2021-12-07 10:55:39 +01:00
|
|
|
Utils::toSettings(clangdSettingsKey(), {}, Core::ICore::settings(), &m_data);
|
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;
|
|
|
|
|
|
|
|
|
|
return data;
|
2021-06-28 14:55:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangdProjectSettings::setSettings(const ClangdSettings::Data &data)
|
|
|
|
|
{
|
|
|
|
|
m_customSettings = data;
|
|
|
|
|
saveSettings();
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2021-10-19 15:00:19 +02:00
|
|
|
if (executableFilePath != fallbackClangdFilePath())
|
|
|
|
|
map.insert(clangdPathKey(), executableFilePath.toString());
|
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);
|
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();
|
2021-06-28 14:55:54 +02:00
|
|
|
}
|
2021-08-30 10:58:08 +02:00
|
|
|
|
|
|
|
|
} // namespace CppEditor
|