aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plugins/clangcodemodel/clangdclient.cpp14
-rw-r--r--src/plugins/clangcodemodel/clangmodelmanagersupport.cpp10
-rw-r--r--src/plugins/clangcodemodel/test/clangdtests.cpp2
-rw-r--r--src/plugins/cppeditor/cppeditortestcase.cpp2
-rw-r--r--src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp6
-rw-r--r--src/plugins/cpptools/cppcodemodelsettings.cpp90
-rw-r--r--src/plugins/cpptools/cppcodemodelsettings.h40
-rw-r--r--src/plugins/cpptools/cppcodemodelsettingspage.cpp176
-rw-r--r--src/plugins/cpptools/cppcodemodelsettingspage.h31
-rw-r--r--src/plugins/cpptools/cpptoolsplugin.cpp9
10 files changed, 286 insertions, 94 deletions
diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp
index 0a3c33327d3..0b027f44752 100644
--- a/src/plugins/clangcodemodel/clangdclient.cpp
+++ b/src/plugins/clangcodemodel/clangdclient.cpp
@@ -416,15 +416,15 @@ public:
: Request("textDocument/symbolInfo", params) {}
};
-static BaseClientInterface *clientInterface(const Utils::FilePath &jsonDbDir)
+static BaseClientInterface *clientInterface(Project *project, const Utils::FilePath &jsonDbDir)
{
QString indexingOption = "--background-index";
- if (!CppTools::ClangdSettings::indexingEnabled())
+ const CppTools::ClangdSettings settings = CppTools::ClangdProjectSettings(project).settings();
+ if (!settings.indexingEnabled())
indexingOption += "=0";
- Utils::CommandLine cmd{CppTools::ClangdSettings::clangdFilePath(),
- {indexingOption, "--limit-results=0"}};
- if (CppTools::ClangdSettings::workerThreadLimit() != 0)
- cmd.addArg("-j=" + QString::number(CppTools::ClangdSettings::workerThreadLimit()));
+ Utils::CommandLine cmd{settings.clangdFilePath(), {indexingOption, "--limit-results=0"}};
+ if (settings.workerThreadLimit() != 0)
+ cmd.addArg("-j=" + QString::number(settings.workerThreadLimit()));
if (!jsonDbDir.isEmpty())
cmd.addArg("--compile-commands-dir=" + jsonDbDir.toString());
if (clangdLog().isDebugEnabled())
@@ -700,7 +700,7 @@ public:
};
ClangdClient::ClangdClient(Project *project, const Utils::FilePath &jsonDbDir)
- : Client(clientInterface(jsonDbDir)), d(new Private(this))
+ : Client(clientInterface(project, jsonDbDir)), d(new Private(this))
{
setName(tr("clangd"));
LanguageFilter langFilter;
diff --git a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp
index 569cf792c88..d9a07ef777c 100644
--- a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp
+++ b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp
@@ -247,7 +247,7 @@ void ClangModelManagerSupport::connectToWidgetsMarkContextMenuRequested(QWidget
void ClangModelManagerSupport::updateLanguageClient(ProjectExplorer::Project *project,
const CppTools::ProjectInfo &projectInfo)
{
- if (!CppTools::ClangdSettings::useClangd())
+ if (!CppTools::ClangdProjectSettings(project).settings().useClangd())
return;
const auto getJsonDbDir = [project] {
if (const ProjectExplorer::Target * const target = project->activeTarget()) {
@@ -266,10 +266,10 @@ void ClangModelManagerSupport::updateLanguageClient(ProjectExplorer::Project *pr
connect(generatorWatcher, &QFutureWatcher<GenerateCompilationDbResult>::finished,
[this, project, projectInfo, getJsonDbDir, jsonDbDir, generatorWatcher] {
generatorWatcher->deleteLater();
- if (!CppTools::ClangdSettings::useClangd())
- return;
if (!ProjectExplorer::SessionManager::hasProject(project))
return;
+ if (!CppTools::ClangdProjectSettings(project).settings().useClangd())
+ return;
if (cppModelManager()->projectInfo(project) != projectInfo)
return;
if (getJsonDbDir() != jsonDbDir)
@@ -286,10 +286,10 @@ void ClangModelManagerSupport::updateLanguageClient(ProjectExplorer::Project *pr
ClangdClient * const client = createClient(project, jsonDbDir);
connect(client, &Client::initialized, this, [client, project, projectInfo, jsonDbDir] {
using namespace ProjectExplorer;
- if (!CppTools::ClangdSettings::useClangd())
- return;
if (!SessionManager::hasProject(project))
return;
+ if (!CppTools::ClangdProjectSettings(project).settings().useClangd())
+ return;
if (cppModelManager()->projectInfo(project) != projectInfo)
return;
diff --git a/src/plugins/clangcodemodel/test/clangdtests.cpp b/src/plugins/clangcodemodel/test/clangdtests.cpp
index e4772e89742..2d5fb510d3f 100644
--- a/src/plugins/clangcodemodel/test/clangdtests.cpp
+++ b/src/plugins/clangcodemodel/test/clangdtests.cpp
@@ -88,7 +88,7 @@ void ClangdTest::initTestCase()
const QString clangdFromEnv = qEnvironmentVariable("QTC_CLANGD");
if (!clangdFromEnv.isEmpty())
CppTools::ClangdSettings::setClangdFilePath(Utils::FilePath::fromString(clangdFromEnv));
- const auto clangd = CppTools::ClangdSettings::clangdFilePath();
+ const auto clangd = CppTools::ClangdSettings::instance().clangdFilePath();
if (clangd.isEmpty() || !clangd.exists())
QSKIP("clangd binary not found");
CppTools::ClangdSettings::setUseClangd(true);
diff --git a/src/plugins/cppeditor/cppeditortestcase.cpp b/src/plugins/cppeditor/cppeditortestcase.cpp
index 7d6c24406fc..876c3f2aa84 100644
--- a/src/plugins/cppeditor/cppeditortestcase.cpp
+++ b/src/plugins/cppeditor/cppeditortestcase.cpp
@@ -78,7 +78,7 @@ bool TestDocument::hasAnchorMarker() const { return m_anchorPosition != -1; }
TestCase::TestCase(bool runGarbageCollector)
: CppTools::Tests::TestCase(runGarbageCollector),
- m_prevUseClangd(CppTools::ClangdSettings::useClangd())
+ m_prevUseClangd(CppTools::ClangdSettings::instance().useClangd())
{
}
diff --git a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp
index 90ee657f6c9..9af92352c38 100644
--- a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp
+++ b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp
@@ -285,7 +285,7 @@ F2TestCase::F2TestCase(CppEditorAction action,
const QString curTestName = QLatin1String(QTest::currentTestFunction());
const QString tag = QLatin1String(QTest::currentDataTag());
- const bool useClangd = CppTools::ClangdSettings::useClangd();
+ const bool useClangd = CppTools::ClangdSettings::instance().useClangd();
if (useClangd) {
if (curTestName == "test_FollowSymbolUnderCursor_QObject_connect"
|| curTestName == "test_FollowSymbolUnderCursor_QObject_oldStyleConnect") {
@@ -475,7 +475,7 @@ F2TestCase::F2TestCase(CppEditorAction action,
// qDebug() << "Expected line:" << expectedLine;
// qDebug() << "Expected column:" << expectedColumn;
- if (!CppTools::ClangdSettings::useClangd()) {
+ if (!CppTools::ClangdSettings::instance().useClangd()) {
QEXPECT_FAIL("globalVarFromEnum", "Contributor works on a fix.", Abort);
QEXPECT_FAIL("matchFunctionSignature_Follow_5", "foo(int) resolved as CallAST", Abort);
}
@@ -545,7 +545,7 @@ void CppEditorPlugin::initTestCase()
if (clangdFromEnv.isEmpty())
return;
ClangdSettings::setClangdFilePath(Utils::FilePath::fromString(clangdFromEnv));
- const auto clangd = ClangdSettings::clangdFilePath();
+ const auto clangd = ClangdSettings::instance().clangdFilePath();
if (clangd.isEmpty() || !clangd.exists())
return;
diff --git a/src/plugins/cpptools/cppcodemodelsettings.cpp b/src/plugins/cpptools/cppcodemodelsettings.cpp
index 6fd9a15b534..41a9c99ea2c 100644
--- a/src/plugins/cpptools/cppcodemodelsettings.cpp
+++ b/src/plugins/cpptools/cppcodemodelsettings.cpp
@@ -30,6 +30,7 @@
#include "cpptoolsreuse.h"
#include <coreplugin/icore.h>
+#include <projectexplorer/project.h>
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
@@ -63,10 +64,12 @@ static QString skipIndexingBigFilesKey()
static QString indexerFileSizeLimitKey()
{ return QLatin1String(Constants::CPPTOOLS_INDEXER_FILE_SIZE_LIMIT); }
+static QString clangdSettingsKey() { return QLatin1String("ClangdSettings"); }
static QString useClangdKey() { return QLatin1String("UseClangd"); }
static QString clangdPathKey() { return QLatin1String("ClangdPath"); }
static QString clangdIndexingKey() { return QLatin1String("ClangdIndexing"); }
static QString clangdThreadLimitKey() { return QLatin1String("ClangdThreadLimit"); }
+static QString clangdUseGlobalSettingsKey() { return QLatin1String("useGlobalSettings"); }
static FilePath g_defaultClangdFilePath;
static FilePath fallbackClangdFilePath()
@@ -323,37 +326,29 @@ void ClangdSettings::setDefaultClangdPath(const Utils::FilePath &filePath)
g_defaultClangdFilePath = filePath;
}
-FilePath ClangdSettings::clangdFilePath()
+FilePath ClangdSettings::clangdFilePath() const
{
- if (!instance().m_data.executableFilePath.isEmpty())
- return instance().m_data.executableFilePath;
+ if (!m_data.executableFilePath.isEmpty())
+ return m_data.executableFilePath;
return fallbackClangdFilePath();
}
void ClangdSettings::setData(const Data &data)
{
- if (data != instance().m_data) {
- instance().m_data = data;
- instance().saveSettings();
+ if (this == &instance() && data != m_data) {
+ m_data = data;
+ saveSettings();
}
}
void ClangdSettings::loadSettings()
{
- QSettings * const s = Core::ICore::settings();
- m_data.useClangd = s->value(useClangdKey(), false).toBool();
- m_data.executableFilePath = FilePath::fromString(s->value(clangdPathKey()).toString());
- m_data.enableIndexing = s->value(clangdIndexingKey(), true).toBool();
- m_data.workerThreadLimit = s->value(clangdThreadLimitKey(), 0).toInt();
+ m_data.fromMap(Core::ICore::settings()->value(clangdSettingsKey()).toMap());
}
void ClangdSettings::saveSettings()
{
- QSettings * const s = Core::ICore::settings();
- s->setValue(useClangdKey(), useClangd());
- s->setValue(clangdPathKey(), m_data.executableFilePath.toString());
- s->setValue(clangdIndexingKey(), m_data.enableIndexing);
- s->setValue(clangdThreadLimitKey(), m_data.workerThreadLimit);
+ Core::ICore::settings()->setValue(clangdSettingsKey(), m_data.toMap());
}
#ifdef WITH_TESTS
@@ -363,3 +358,66 @@ void ClangdSettings::setClangdFilePath(const Utils::FilePath &filePath)
instance().m_data.executableFilePath = filePath;
}
#endif
+
+ClangdProjectSettings::ClangdProjectSettings(ProjectExplorer::Project *project) : m_project(project)
+{
+ loadSettings();
+}
+
+ClangdSettings ClangdProjectSettings::settings() const
+{
+ if (m_useGlobalSettings)
+ return ClangdSettings::instance();
+ return ClangdSettings(m_customSettings);
+}
+
+void ClangdProjectSettings::setSettings(const ClangdSettings::Data &data)
+{
+ m_customSettings = data;
+ saveSettings();
+}
+
+void ClangdProjectSettings::setUseGlobalSettings(bool useGlobal)
+{
+ m_useGlobalSettings = useGlobal;
+ saveSettings();
+}
+
+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);
+ map.insert(clangdPathKey(), executableFilePath.toString());
+ map.insert(clangdIndexingKey(), enableIndexing);
+ map.insert(clangdThreadLimitKey(), workerThreadLimit);
+ return map;
+}
+
+void ClangdSettings::Data::fromMap(const QVariantMap &map)
+{
+ useClangd = map.value(useClangdKey(), false).toBool();
+ executableFilePath = FilePath::fromString(map.value(clangdPathKey()).toString());
+ enableIndexing = map.value(clangdIndexingKey(), true).toBool();
+ workerThreadLimit = map.value(clangdThreadLimitKey(), 0).toInt();
+}
diff --git a/src/plugins/cpptools/cppcodemodelsettings.h b/src/plugins/cpptools/cppcodemodelsettings.h
index eb4abe4537e..6bfccc4bf75 100644
--- a/src/plugins/cpptools/cppcodemodelsettings.h
+++ b/src/plugins/cpptools/cppcodemodelsettings.h
@@ -38,6 +38,8 @@ QT_BEGIN_NAMESPACE
class QSettings;
QT_END_NAMESPACE
+namespace ProjectExplorer { class Project; }
+
namespace CppTools {
class CPPTOOLS_EXPORT CppCodeModelSettings : public QObject
@@ -102,21 +104,27 @@ public:
class Data
{
public:
+ QVariantMap toMap() const;
+ void fromMap(const QVariantMap &map);
+
Utils::FilePath executableFilePath;
int workerThreadLimit = 0;
bool useClangd = false;
bool enableIndexing = true;
};
- static bool useClangd() { return instance().m_data.useClangd; }
+ ClangdSettings(const Data &data) : m_data(data) {}
+
+ static ClangdSettings &instance();
+ bool useClangd() const { return m_data.useClangd; }
static void setDefaultClangdPath(const Utils::FilePath &filePath);
- static Utils::FilePath clangdFilePath();
- static bool indexingEnabled() { return instance().m_data.enableIndexing; }
- static int workerThreadLimit() { return instance().m_data.workerThreadLimit; }
+ Utils::FilePath clangdFilePath() const;
+ bool indexingEnabled() const { return m_data.enableIndexing; }
+ int workerThreadLimit() const { return m_data.workerThreadLimit; }
- static void setData(const Data &data);
- static Data data() { return instance().m_data; }
+ void setData(const Data &data);
+ Data data() const { return m_data; }
#ifdef WITH_TESTS
static void setUseClangd(bool use);
@@ -125,7 +133,6 @@ public:
private:
ClangdSettings() { loadSettings(); }
- static ClangdSettings &instance();
void loadSettings();
void saveSettings();
@@ -133,4 +140,23 @@ private:
Data m_data;
};
+class CPPTOOLS_EXPORT ClangdProjectSettings
+{
+public:
+ ClangdProjectSettings(ProjectExplorer::Project *project);
+
+ ClangdSettings settings() const;
+ void setSettings(const ClangdSettings::Data &data);
+ bool useGlobalSettings() const { return m_useGlobalSettings; }
+ void setUseGlobalSettings(bool useGlobal);
+
+private:
+ void loadSettings();
+ void saveSettings();
+
+ ProjectExplorer::Project * const m_project;
+ ClangdSettings::Data m_customSettings;
+ bool m_useGlobalSettings = true;
+};
+
} // namespace CppTools
diff --git a/src/plugins/cpptools/cppcodemodelsettingspage.cpp b/src/plugins/cpptools/cppcodemodelsettingspage.cpp
index 05b39cfea2c..5631f8b8d1c 100644
--- a/src/plugins/cpptools/cppcodemodelsettingspage.cpp
+++ b/src/plugins/cpptools/cppcodemodelsettingspage.cpp
@@ -191,71 +191,99 @@ CppCodeModelSettingsPage::CppCodeModelSettingsPage(CppCodeModelSettings *setting
setWidgetCreator([settings] { return new CppCodeModelSettingsWidget(settings); });
}
+class ClangdSettingsWidget::Private
+{
+public:
+ QCheckBox useClangdCheckBox;
+ QCheckBox indexingCheckBox;
+ QSpinBox threadLimitSpinBox;
+ Utils::PathChooser clangdChooser;
+};
-class ClangdSettingsWidget final : public Core::IOptionsPageWidget
+ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings &settings) : d(new Private)
+{
+ d->useClangdCheckBox.setText(tr("Use clangd (EXPERIMENTAL)"));
+ d->useClangdCheckBox.setChecked(settings.useClangd());
+ d->useClangdCheckBox.setToolTip(tr("Changing this option does not affect projects "
+ "that are already open."));
+ d->clangdChooser.setExpectedKind(Utils::PathChooser::ExistingCommand);
+ d->clangdChooser.setFilePath(settings.clangdFilePath());
+ d->clangdChooser.setEnabled(d->useClangdCheckBox.isChecked());
+ d->indexingCheckBox.setChecked(settings.indexingEnabled());
+ d->indexingCheckBox.setToolTip(tr(
+ "If background indexing is enabled, global symbol searches will yield\n"
+ "more accurate results, at the cost of additional CPU load when\n"
+ "the project is first opened."));
+ d->threadLimitSpinBox.setValue(settings.workerThreadLimit());
+ d->threadLimitSpinBox.setSpecialValueText("Automatic");
+
+ const auto layout = new QVBoxLayout(this);
+ layout->addWidget(&d->useClangdCheckBox);
+ const auto formLayout = new QFormLayout;
+ const auto chooserLabel = new QLabel(tr("Path to executable:"));
+ formLayout->addRow(chooserLabel, &d->clangdChooser);
+ const auto indexingLabel = new QLabel(tr("Enable background indexing:"));
+ formLayout->addRow(indexingLabel, &d->indexingCheckBox);
+ const auto threadLimitLayout = new QHBoxLayout;
+ threadLimitLayout->addWidget(&d->threadLimitSpinBox);
+ threadLimitLayout->addStretch(1);
+ const auto threadLimitLabel = new QLabel(tr("Set worker thread count:"));
+ formLayout->addRow(threadLimitLabel, threadLimitLayout);
+ layout->addLayout(formLayout);
+ layout->addStretch(1);
+
+ const auto toggleEnabled = [=](const bool checked) {
+ chooserLabel->setEnabled(checked);
+ d->clangdChooser.setEnabled(checked);
+ indexingLabel->setEnabled(checked);
+ d->indexingCheckBox.setEnabled(checked);
+ d->threadLimitSpinBox.setEnabled(checked);
+ };
+ connect(&d->useClangdCheckBox, &QCheckBox::toggled, toggleEnabled);
+ toggleEnabled(d->useClangdCheckBox.isChecked());
+ d->threadLimitSpinBox.setEnabled(d->useClangdCheckBox.isChecked());
+
+ connect(&d->useClangdCheckBox, &QCheckBox::toggled,
+ this, &ClangdSettingsWidget::settingsDataChanged);
+ connect(&d->indexingCheckBox, &QCheckBox::toggled,
+ this, &ClangdSettingsWidget::settingsDataChanged);
+ connect(&d->threadLimitSpinBox, qOverload<int>(&QSpinBox::valueChanged),
+ this, &ClangdSettingsWidget::settingsDataChanged);
+ connect(&d->clangdChooser, &Utils::PathChooser::pathChanged,
+ this, &ClangdSettingsWidget::settingsDataChanged);
+}
+
+ClangdSettingsWidget::~ClangdSettingsWidget()
+{
+ delete d;
+}
+
+ClangdSettings::Data ClangdSettingsWidget::settingsData() const
+{
+ ClangdSettings::Data data;
+ data.useClangd = d->useClangdCheckBox.isChecked();
+ data.executableFilePath = d->clangdChooser.filePath();
+ data.enableIndexing = d->indexingCheckBox.isChecked();
+ data.workerThreadLimit = d->threadLimitSpinBox.value();
+ return data;
+}
+
+class ClangdSettingsPageWidget final : public Core::IOptionsPageWidget
{
Q_DECLARE_TR_FUNCTIONS(CppTools::Internal::ClangdSettingsWidget)
public:
- ClangdSettingsWidget()
+ ClangdSettingsPageWidget() : m_widget(ClangdSettings::instance())
{
- m_useClangdCheckBox.setText(tr("Use clangd (EXPERIMENTAL)"));
- m_useClangdCheckBox.setChecked(ClangdSettings::useClangd());
- m_useClangdCheckBox.setToolTip(tr("Changing this option does not affect projects "
- "that are already open."));
- m_clangdChooser.setExpectedKind(Utils::PathChooser::ExistingCommand);
- m_clangdChooser.setFilePath(ClangdSettings::clangdFilePath());
- m_clangdChooser.setEnabled(m_useClangdCheckBox.isChecked());
- m_indexingCheckBox.setChecked(ClangdSettings::indexingEnabled());
- m_indexingCheckBox.setToolTip(tr(
- "If background indexing is enabled, global symbol searches will yield\n"
- "more accurate results, at the cost of additional CPU load when\n"
- "the project is first opened."));
- m_threadLimitSpinBox.setValue(ClangdSettings::workerThreadLimit());
- m_threadLimitSpinBox.setSpecialValueText("Automatic");
const auto layout = new QVBoxLayout(this);
- layout->addWidget(&m_useClangdCheckBox);
- const auto formLayout = new QFormLayout;
- const auto chooserLabel = new QLabel(tr("Path to executable:"));
- formLayout->addRow(chooserLabel, &m_clangdChooser);
- const auto indexingLabel = new QLabel(tr("Enable background indexing:"));
- formLayout->addRow(indexingLabel, &m_indexingCheckBox);
- const auto threadLimitLayout = new QHBoxLayout;
- threadLimitLayout->addWidget(&m_threadLimitSpinBox);
- threadLimitLayout->addStretch(1);
- const auto threadLimitLabel = new QLabel(tr("Set worker thread count:"));
- formLayout->addRow(threadLimitLabel, threadLimitLayout);
- layout->addLayout(formLayout);
- layout->addStretch(1);
-
- const auto toggleEnabled = [=](const bool checked) {
- chooserLabel->setEnabled(checked);
- m_clangdChooser.setEnabled(checked);
- indexingLabel->setEnabled(checked);
- m_indexingCheckBox.setEnabled(checked);
- m_threadLimitSpinBox.setEnabled(checked);
- };
- connect(&m_useClangdCheckBox, &QCheckBox::toggled, toggleEnabled);
- toggleEnabled(m_useClangdCheckBox.isChecked());
- m_threadLimitSpinBox.setEnabled(m_useClangdCheckBox.isChecked());
+ layout->addWidget(&m_widget);
}
private:
- void apply() final
- {
- ClangdSettings::Data data;
- data.useClangd = m_useClangdCheckBox.isChecked();
- data.executableFilePath = m_clangdChooser.filePath();
- data.enableIndexing = m_indexingCheckBox.isChecked();
- data.workerThreadLimit = m_threadLimitSpinBox.value();
- ClangdSettings::setData(data);
- }
+ void apply() final { ClangdSettings::instance().setData(m_widget.settingsData()); }
- QCheckBox m_useClangdCheckBox;
- QCheckBox m_indexingCheckBox;
- QSpinBox m_threadLimitSpinBox;
- Utils::PathChooser m_clangdChooser;
+ ClangdSettingsWidget m_widget;
};
ClangdSettingsPage::ClangdSettingsPage()
@@ -263,7 +291,47 @@ ClangdSettingsPage::ClangdSettingsPage()
setId("K.Clangd");
setDisplayName(ClangdSettingsWidget::tr("Clangd"));
setCategory(Constants::CPP_SETTINGS_CATEGORY);
- setWidgetCreator([] { return new ClangdSettingsWidget; });
+ setWidgetCreator([] { return new ClangdSettingsPageWidget; });
+}
+
+
+class ClangdProjectSettingsWidget::Private
+{
+public:
+ Private(const ClangdProjectSettings &s) : settings(s), widget(s.settings()) {}
+
+ ClangdProjectSettings settings;
+ ClangdSettingsWidget widget;
+ QCheckBox useGlobalSettingsCheckBox;
+};
+
+ClangdProjectSettingsWidget::ClangdProjectSettingsWidget(const ClangdProjectSettings &settings)
+ : d(new Private(settings))
+{
+ const auto layout = new QVBoxLayout(this);
+ d->useGlobalSettingsCheckBox.setText(tr("Use global settings"));
+ layout->addWidget(&d->useGlobalSettingsCheckBox);
+ const auto separator = new QFrame;
+ separator->setFrameShape(QFrame::HLine);
+ layout->addWidget(separator);
+ layout->addWidget(&d->widget);
+
+ d->useGlobalSettingsCheckBox.setChecked(d->settings.useGlobalSettings());
+ d->widget.setEnabled(!d->settings.useGlobalSettings());
+ connect(&d->useGlobalSettingsCheckBox, &QCheckBox::toggled, [this](bool checked) {
+ d->widget.setEnabled(!checked);
+ d->settings.setUseGlobalSettings(checked);
+ if (!checked)
+ d->settings.setSettings(d->widget.settingsData());
+ });
+ connect(&d->widget, &ClangdSettingsWidget::settingsDataChanged, [this] {
+ d->settings.setSettings(d->widget.settingsData());
+ });
+}
+
+ClangdProjectSettingsWidget::~ClangdProjectSettingsWidget()
+{
+ delete d;
}
} // Internal
diff --git a/src/plugins/cpptools/cppcodemodelsettingspage.h b/src/plugins/cpptools/cppcodemodelsettingspage.h
index 5e48be1ffe0..b8c595c7c5e 100644
--- a/src/plugins/cpptools/cppcodemodelsettingspage.h
+++ b/src/plugins/cpptools/cppcodemodelsettingspage.h
@@ -44,5 +44,36 @@ public:
explicit ClangdSettingsPage();
};
+class ClangdSettingsWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ ClangdSettingsWidget(const ClangdSettings &settings);
+ ~ClangdSettingsWidget();
+
+ ClangdSettings::Data settingsData() const;
+
+signals:
+ void settingsDataChanged();
+
+private:
+ class Private;
+ Private * const d;
+};
+
+class ClangdProjectSettingsWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ ClangdProjectSettingsWidget(const ClangdProjectSettings &settings);
+ ~ClangdProjectSettingsWidget();
+
+private:
+ class Private;
+ Private * const d;
+};
+
} // Internal namespace
} // CppTools namespace
diff --git a/src/plugins/cpptools/cpptoolsplugin.cpp b/src/plugins/cpptools/cpptoolsplugin.cpp
index 87ecc25d713..1e77501c0f4 100644
--- a/src/plugins/cpptools/cpptoolsplugin.cpp
+++ b/src/plugins/cpptools/cpptoolsplugin.cpp
@@ -49,6 +49,7 @@
#include <cppeditor/cppeditorconstants.h>
#include <extensionsystem/pluginmanager.h>
#include <projectexplorer/project.h>
+#include <projectexplorer/projectpanelfactory.h>
#include <projectexplorer/projecttree.h>
#include <utils/algorithm.h>
@@ -210,6 +211,14 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
tr("Insert \"#pragma once\" instead of \"#ifndef\" include guards into header file"),
[] { return usePragmaOnce() ? QString("true") : QString(); });
+ const auto panelFactory = new ProjectExplorer::ProjectPanelFactory;
+ panelFactory->setPriority(100);
+ panelFactory->setDisplayName(tr("Clangd"));
+ panelFactory->setCreateWidgetFunction([](ProjectExplorer::Project *project) {
+ return new ClangdProjectSettingsWidget(project);
+ });
+ ProjectExplorer::ProjectPanelFactory::registerFactory(panelFactory);
+
return true;
}