forked from qt-creator/qt-creator
CppTools: Add dedicated settings and settings page for clangd
We plan to add more clangd settings, and it makes sense to have a dedicated place for them both in the code and the UI. Change-Id: Ideb92935b7a5a6a98e07980f4011736fb82042d1 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -382,7 +382,7 @@ public:
|
|||||||
|
|
||||||
static BaseClientInterface *clientInterface(const Utils::FilePath &jsonDbDir)
|
static BaseClientInterface *clientInterface(const Utils::FilePath &jsonDbDir)
|
||||||
{
|
{
|
||||||
Utils::CommandLine cmd{CppTools::codeModelSettings()->clangdFilePath(),
|
Utils::CommandLine cmd{CppTools::ClangdSettings::clangdFilePath(),
|
||||||
{"--background-index", "--limit-results=0"}};
|
{"--background-index", "--limit-results=0"}};
|
||||||
if (!jsonDbDir.isEmpty())
|
if (!jsonDbDir.isEmpty())
|
||||||
cmd.addArg("--compile-commands-dir=" + jsonDbDir.toString());
|
cmd.addArg("--compile-commands-dir=" + jsonDbDir.toString());
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ ClangModelManagerSupport::ClangModelManagerSupport()
|
|||||||
connect(sessionManager, &ProjectExplorer::SessionManager::aboutToRemoveProject,
|
connect(sessionManager, &ProjectExplorer::SessionManager::aboutToRemoveProject,
|
||||||
this, &ClangModelManagerSupport::onAboutToRemoveProject);
|
this, &ClangModelManagerSupport::onAboutToRemoveProject);
|
||||||
|
|
||||||
CppTools::CppCodeModelSettings::setDefaultClangdPath(Utils::FilePath::fromString(
|
CppTools::ClangdSettings::setDefaultClangdPath(Utils::FilePath::fromString(
|
||||||
Core::ICore::clangdExecutable(CLANG_BINDIR)));
|
Core::ICore::clangdExecutable(CLANG_BINDIR)));
|
||||||
CppTools::CppCodeModelSettings *settings = CppTools::codeModelSettings();
|
CppTools::CppCodeModelSettings *settings = CppTools::codeModelSettings();
|
||||||
connect(settings, &CppTools::CppCodeModelSettings::clangDiagnosticConfigsInvalidated,
|
connect(settings, &CppTools::CppCodeModelSettings::clangDiagnosticConfigsInvalidated,
|
||||||
@@ -245,7 +245,7 @@ void ClangModelManagerSupport::connectToWidgetsMarkContextMenuRequested(QWidget
|
|||||||
void ClangModelManagerSupport::updateLanguageClient(ProjectExplorer::Project *project,
|
void ClangModelManagerSupport::updateLanguageClient(ProjectExplorer::Project *project,
|
||||||
const CppTools::ProjectInfo &projectInfo)
|
const CppTools::ProjectInfo &projectInfo)
|
||||||
{
|
{
|
||||||
if (!CppTools::codeModelSettings()->useClangd())
|
if (!CppTools::ClangdSettings::useClangd())
|
||||||
return;
|
return;
|
||||||
const auto getJsonDbDir = [project] {
|
const auto getJsonDbDir = [project] {
|
||||||
if (const ProjectExplorer::Target * const target = project->activeTarget()) {
|
if (const ProjectExplorer::Target * const target = project->activeTarget()) {
|
||||||
@@ -264,7 +264,7 @@ void ClangModelManagerSupport::updateLanguageClient(ProjectExplorer::Project *pr
|
|||||||
connect(generatorWatcher, &QFutureWatcher<GenerateCompilationDbResult>::finished,
|
connect(generatorWatcher, &QFutureWatcher<GenerateCompilationDbResult>::finished,
|
||||||
[this, project, projectInfo, getJsonDbDir, jsonDbDir, generatorWatcher] {
|
[this, project, projectInfo, getJsonDbDir, jsonDbDir, generatorWatcher] {
|
||||||
generatorWatcher->deleteLater();
|
generatorWatcher->deleteLater();
|
||||||
if (!CppTools::codeModelSettings()->useClangd())
|
if (!CppTools::ClangdSettings::useClangd())
|
||||||
return;
|
return;
|
||||||
if (!ProjectExplorer::SessionManager::hasProject(project))
|
if (!ProjectExplorer::SessionManager::hasProject(project))
|
||||||
return;
|
return;
|
||||||
@@ -284,7 +284,7 @@ void ClangModelManagerSupport::updateLanguageClient(ProjectExplorer::Project *pr
|
|||||||
ClangdClient * const client = createClient(project, jsonDbDir);
|
ClangdClient * const client = createClient(project, jsonDbDir);
|
||||||
connect(client, &Client::initialized, this, [client, project, projectInfo, jsonDbDir] {
|
connect(client, &Client::initialized, this, [client, project, projectInfo, jsonDbDir] {
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
if (!CppTools::codeModelSettings()->useClangd())
|
if (!CppTools::ClangdSettings::useClangd())
|
||||||
return;
|
return;
|
||||||
if (!SessionManager::hasProject(project))
|
if (!SessionManager::hasProject(project))
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -85,14 +85,13 @@ Utils::FilePath ClangdTest::filePath(const QString &fileName) const
|
|||||||
|
|
||||||
void ClangdTest::initTestCase()
|
void ClangdTest::initTestCase()
|
||||||
{
|
{
|
||||||
const auto settings = CppTools::codeModelSettings();
|
|
||||||
const QString clangdFromEnv = qEnvironmentVariable("QTC_CLANGD");
|
const QString clangdFromEnv = qEnvironmentVariable("QTC_CLANGD");
|
||||||
if (!clangdFromEnv.isEmpty())
|
if (!clangdFromEnv.isEmpty())
|
||||||
settings->setClangdFilePath(Utils::FilePath::fromString(clangdFromEnv));
|
CppTools::ClangdSettings::setClangdFilePath(Utils::FilePath::fromString(clangdFromEnv));
|
||||||
const auto clangd = settings->clangdFilePath();
|
const auto clangd = CppTools::ClangdSettings::clangdFilePath();
|
||||||
if (clangd.isEmpty() || !clangd.exists())
|
if (clangd.isEmpty() || !clangd.exists())
|
||||||
QSKIP("clangd binary not found");
|
QSKIP("clangd binary not found");
|
||||||
settings->setUseClangd(true);
|
CppTools::ClangdSettings::setUseClangd(true);
|
||||||
|
|
||||||
// Find suitable kit.
|
// Find suitable kit.
|
||||||
m_kit = Utils::findOr(KitManager::kits(), nullptr, [](const Kit *k) {
|
m_kit = Utils::findOr(KitManager::kits(), nullptr, [](const Kit *k) {
|
||||||
|
|||||||
@@ -78,19 +78,19 @@ bool TestDocument::hasAnchorMarker() const { return m_anchorPosition != -1; }
|
|||||||
|
|
||||||
TestCase::TestCase(bool runGarbageCollector)
|
TestCase::TestCase(bool runGarbageCollector)
|
||||||
: CppTools::Tests::TestCase(runGarbageCollector),
|
: CppTools::Tests::TestCase(runGarbageCollector),
|
||||||
m_prevUseClangd(CppTools::codeModelSettings()->useClangd())
|
m_prevUseClangd(CppTools::ClangdSettings::useClangd())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
TestCase::~TestCase()
|
TestCase::~TestCase()
|
||||||
{
|
{
|
||||||
CppTools::codeModelSettings()->setUseClangd(m_prevUseClangd);
|
CppTools::ClangdSettings::setUseClangd(m_prevUseClangd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestCase::setUseClangd()
|
void TestCase::setUseClangd()
|
||||||
{
|
{
|
||||||
if (CppEditorPlugin::instance()->m_testKit)
|
if (CppEditorPlugin::instance()->m_testKit)
|
||||||
CppTools::codeModelSettings()->setUseClangd(true);
|
CppTools::ClangdSettings::setUseClangd(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TestCase::openCppEditor(const QString &fileName, CppEditor **editor, CppEditorWidget **editorWidget)
|
bool TestCase::openCppEditor(const QString &fileName, CppEditor **editor, CppEditorWidget **editorWidget)
|
||||||
|
|||||||
@@ -285,7 +285,7 @@ F2TestCase::F2TestCase(CppEditorAction action,
|
|||||||
|
|
||||||
const QString curTestName = QLatin1String(QTest::currentTestFunction());
|
const QString curTestName = QLatin1String(QTest::currentTestFunction());
|
||||||
const QString tag = QLatin1String(QTest::currentDataTag());
|
const QString tag = QLatin1String(QTest::currentDataTag());
|
||||||
const bool useClangd = CppTools::codeModelSettings()->useClangd();
|
const bool useClangd = CppTools::ClangdSettings::useClangd();
|
||||||
if (useClangd) {
|
if (useClangd) {
|
||||||
if (curTestName == "test_FollowSymbolUnderCursor_QObject_connect"
|
if (curTestName == "test_FollowSymbolUnderCursor_QObject_connect"
|
||||||
|| curTestName == "test_FollowSymbolUnderCursor_QObject_oldStyleConnect") {
|
|| curTestName == "test_FollowSymbolUnderCursor_QObject_oldStyleConnect") {
|
||||||
@@ -475,7 +475,7 @@ F2TestCase::F2TestCase(CppEditorAction action,
|
|||||||
// qDebug() << "Expected line:" << expectedLine;
|
// qDebug() << "Expected line:" << expectedLine;
|
||||||
// qDebug() << "Expected column:" << expectedColumn;
|
// qDebug() << "Expected column:" << expectedColumn;
|
||||||
|
|
||||||
if (!CppTools::codeModelSettings()->useClangd()) {
|
if (!CppTools::ClangdSettings::useClangd()) {
|
||||||
QEXPECT_FAIL("globalVarFromEnum", "Contributor works on a fix.", Abort);
|
QEXPECT_FAIL("globalVarFromEnum", "Contributor works on a fix.", Abort);
|
||||||
QEXPECT_FAIL("matchFunctionSignature_Follow_5", "foo(int) resolved as CallAST", Abort);
|
QEXPECT_FAIL("matchFunctionSignature_Follow_5", "foo(int) resolved as CallAST", Abort);
|
||||||
}
|
}
|
||||||
@@ -541,12 +541,11 @@ namespace Internal {
|
|||||||
|
|
||||||
void CppEditorPlugin::initTestCase()
|
void CppEditorPlugin::initTestCase()
|
||||||
{
|
{
|
||||||
const auto settings = CppTools::codeModelSettings();
|
|
||||||
const QString clangdFromEnv = qEnvironmentVariable("QTC_CLANGD");
|
const QString clangdFromEnv = qEnvironmentVariable("QTC_CLANGD");
|
||||||
if (clangdFromEnv.isEmpty())
|
if (clangdFromEnv.isEmpty())
|
||||||
return;
|
return;
|
||||||
settings->setClangdFilePath(Utils::FilePath::fromString(clangdFromEnv));
|
ClangdSettings::setClangdFilePath(Utils::FilePath::fromString(clangdFromEnv));
|
||||||
const auto clangd = settings->clangdFilePath();
|
const auto clangd = ClangdSettings::clangdFilePath();
|
||||||
if (clangd.isEmpty() || !clangd.exists())
|
if (clangd.isEmpty() || !clangd.exists())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,8 @@
|
|||||||
#include "cpptoolsconstants.h"
|
#include "cpptoolsconstants.h"
|
||||||
#include "cpptoolsreuse.h"
|
#include "cpptoolsreuse.h"
|
||||||
|
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
@@ -172,9 +174,6 @@ void CppCodeModelSettings::fromSettings(QSettings *s)
|
|||||||
const QVariant indexerFileSizeLimit = s->value(indexerFileSizeLimitKey(), 5);
|
const QVariant indexerFileSizeLimit = s->value(indexerFileSizeLimitKey(), 5);
|
||||||
setIndexerFileSizeLimitInMb(indexerFileSizeLimit.toInt());
|
setIndexerFileSizeLimitInMb(indexerFileSizeLimit.toInt());
|
||||||
|
|
||||||
setUseClangd(s->value(useClangdKey(), false).toBool());
|
|
||||||
setClangdFilePath(FilePath::fromString(s->value(clangdPathKey()).toString()));
|
|
||||||
|
|
||||||
s->endGroup();
|
s->endGroup();
|
||||||
|
|
||||||
if (write)
|
if (write)
|
||||||
@@ -198,8 +197,6 @@ void CppCodeModelSettings::toSettings(QSettings *s)
|
|||||||
s->setValue(interpretAmbiguousHeadersAsCHeadersKey(), interpretAmbigiousHeadersAsCHeaders());
|
s->setValue(interpretAmbiguousHeadersAsCHeadersKey(), interpretAmbigiousHeadersAsCHeaders());
|
||||||
s->setValue(skipIndexingBigFilesKey(), skipIndexingBigFiles());
|
s->setValue(skipIndexingBigFilesKey(), skipIndexingBigFiles());
|
||||||
s->setValue(indexerFileSizeLimitKey(), indexerFileSizeLimitInMb());
|
s->setValue(indexerFileSizeLimitKey(), indexerFileSizeLimitInMb());
|
||||||
s->setValue(useClangdKey(), useClangd());
|
|
||||||
s->setValue(clangdPathKey(), m_clangdFilePath.toString());
|
|
||||||
|
|
||||||
s->endGroup();
|
s->endGroup();
|
||||||
|
|
||||||
@@ -300,14 +297,60 @@ void CppCodeModelSettings::setEnableLowerClazyLevels(bool yesno)
|
|||||||
m_enableLowerClazyLevels = yesno;
|
m_enableLowerClazyLevels = yesno;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppCodeModelSettings::setDefaultClangdPath(const Utils::FilePath &filePath)
|
|
||||||
|
static bool operator==(const ClangdSettings::Data &s1, const ClangdSettings::Data &s2)
|
||||||
|
{
|
||||||
|
return s1.useClangd == s2.useClangd && s1.executableFilePath == s2.executableFilePath;
|
||||||
|
}
|
||||||
|
static bool operator!=(const ClangdSettings::Data &s1, const ClangdSettings::Data &s2)
|
||||||
|
{
|
||||||
|
return !(s1 == s2);
|
||||||
|
}
|
||||||
|
|
||||||
|
ClangdSettings &ClangdSettings::instance()
|
||||||
|
{
|
||||||
|
static ClangdSettings settings;
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClangdSettings::setDefaultClangdPath(const Utils::FilePath &filePath)
|
||||||
{
|
{
|
||||||
g_defaultClangdFilePath = filePath;
|
g_defaultClangdFilePath = filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath CppCodeModelSettings::clangdFilePath() const
|
FilePath ClangdSettings::clangdFilePath()
|
||||||
{
|
{
|
||||||
if (!m_clangdFilePath.isEmpty())
|
if (!instance().m_data.executableFilePath.isEmpty())
|
||||||
return m_clangdFilePath;
|
return instance().m_data.executableFilePath;
|
||||||
return fallbackClangdFilePath();
|
return fallbackClangdFilePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClangdSettings::setData(const Data &data)
|
||||||
|
{
|
||||||
|
if (data != instance().m_data) {
|
||||||
|
instance().m_data = data;
|
||||||
|
instance().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());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClangdSettings::saveSettings()
|
||||||
|
{
|
||||||
|
QSettings * const s = Core::ICore::settings();
|
||||||
|
s->setValue(useClangdKey(), useClangd());
|
||||||
|
s->setValue(clangdPathKey(), m_data.executableFilePath.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef WITH_TESTS
|
||||||
|
void ClangdSettings::setUseClangd(bool use) { instance().m_data.useClangd = use; }
|
||||||
|
void ClangdSettings::setClangdFilePath(const Utils::FilePath &filePath)
|
||||||
|
{
|
||||||
|
instance().m_data.executableFilePath = filePath;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -78,13 +78,6 @@ public:
|
|||||||
int indexerFileSizeLimitInMb() const;
|
int indexerFileSizeLimitInMb() const;
|
||||||
void setIndexerFileSizeLimitInMb(int sizeInMB);
|
void setIndexerFileSizeLimitInMb(int sizeInMB);
|
||||||
|
|
||||||
void setUseClangd(bool use) { m_useClangd = use; }
|
|
||||||
bool useClangd() const { return m_useClangd; }
|
|
||||||
|
|
||||||
static void setDefaultClangdPath(const Utils::FilePath &filePath);
|
|
||||||
void setClangdFilePath(const Utils::FilePath &filePath) { m_clangdFilePath = filePath; }
|
|
||||||
Utils::FilePath clangdFilePath() const;
|
|
||||||
|
|
||||||
void setCategorizeFindReferences(bool categorize) { m_categorizeFindReferences = categorize; }
|
void setCategorizeFindReferences(bool categorize) { m_categorizeFindReferences = categorize; }
|
||||||
bool categorizeFindReferences() const { return m_categorizeFindReferences; }
|
bool categorizeFindReferences() const { return m_categorizeFindReferences; }
|
||||||
|
|
||||||
@@ -100,9 +93,40 @@ private:
|
|||||||
ClangDiagnosticConfigs m_clangCustomDiagnosticConfigs;
|
ClangDiagnosticConfigs m_clangCustomDiagnosticConfigs;
|
||||||
Utils::Id m_clangDiagnosticConfigId;
|
Utils::Id m_clangDiagnosticConfigId;
|
||||||
bool m_enableLowerClazyLevels = true; // For UI behavior only
|
bool m_enableLowerClazyLevels = true; // For UI behavior only
|
||||||
Utils::FilePath m_clangdFilePath;
|
|
||||||
bool m_useClangd = false;
|
|
||||||
bool m_categorizeFindReferences = false; // Ephemeral!
|
bool m_categorizeFindReferences = false; // Ephemeral!
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CPPTOOLS_EXPORT ClangdSettings
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
class Data
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool useClangd = false;
|
||||||
|
Utils::FilePath executableFilePath;
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool useClangd() { return instance().m_data.useClangd; }
|
||||||
|
|
||||||
|
static void setDefaultClangdPath(const Utils::FilePath &filePath);
|
||||||
|
static Utils::FilePath clangdFilePath();
|
||||||
|
|
||||||
|
static void setData(const Data &data);
|
||||||
|
static Data data() { return instance().m_data; }
|
||||||
|
|
||||||
|
#ifdef WITH_TESTS
|
||||||
|
static void setUseClangd(bool use);
|
||||||
|
static void setClangdFilePath(const Utils::FilePath &filePath);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
ClangdSettings() { loadSettings(); }
|
||||||
|
static ClangdSettings &instance();
|
||||||
|
|
||||||
|
void loadSettings();
|
||||||
|
void saveSettings();
|
||||||
|
|
||||||
|
Data m_data;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace CppTools
|
} // namespace CppTools
|
||||||
|
|||||||
@@ -33,7 +33,9 @@
|
|||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
|
#include <utils/pathchooser.h>
|
||||||
|
|
||||||
|
#include <QFormLayout>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
@@ -100,8 +102,6 @@ void CppCodeModelSettingsWidget::setupClangCodeModelWidgets()
|
|||||||
const bool isClangActive = CppModelManager::instance()->isClangCodeModelActive();
|
const bool isClangActive = CppModelManager::instance()->isClangCodeModelActive();
|
||||||
m_ui->clangCodeModelIsDisabledHint->setVisible(!isClangActive);
|
m_ui->clangCodeModelIsDisabledHint->setVisible(!isClangActive);
|
||||||
m_ui->clangCodeModelIsEnabledHint->setVisible(isClangActive);
|
m_ui->clangCodeModelIsEnabledHint->setVisible(isClangActive);
|
||||||
m_ui->clangdCheckBox->setVisible(isClangActive);
|
|
||||||
m_ui->clangdChooser->setVisible(isClangActive);
|
|
||||||
|
|
||||||
for (int i = 0; i < m_ui->clangDiagnosticConfigsSelectionWidget->layout()->count(); ++i) {
|
for (int i = 0; i < m_ui->clangDiagnosticConfigsSelectionWidget->layout()->count(); ++i) {
|
||||||
QWidget *widget = m_ui->clangDiagnosticConfigsSelectionWidget->layout()->itemAt(i)->widget();
|
QWidget *widget = m_ui->clangDiagnosticConfigsSelectionWidget->layout()->itemAt(i)->widget();
|
||||||
@@ -120,16 +120,6 @@ void CppCodeModelSettingsWidget::setupGeneralWidgets()
|
|||||||
|
|
||||||
const bool ignorePch = m_settings->pchUsage() == CppCodeModelSettings::PchUse_None;
|
const bool ignorePch = m_settings->pchUsage() == CppCodeModelSettings::PchUse_None;
|
||||||
m_ui->ignorePCHCheckBox->setChecked(ignorePch);
|
m_ui->ignorePCHCheckBox->setChecked(ignorePch);
|
||||||
|
|
||||||
m_ui->clangdCheckBox->setChecked(m_settings->useClangd());
|
|
||||||
m_ui->clangdCheckBox->setToolTip(tr("Use clangd for locators and \"Find References\".\n"
|
|
||||||
"Changing this option does not affect projects that are already open."));
|
|
||||||
m_ui->clangdChooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
|
|
||||||
m_ui->clangdChooser->setFilePath(codeModelSettings()->clangdFilePath());
|
|
||||||
m_ui->clangdChooser->setEnabled(m_ui->clangdCheckBox->isChecked());
|
|
||||||
connect(m_ui->clangdCheckBox, &QCheckBox::toggled, m_ui->clangdChooser, [this](bool checked) {
|
|
||||||
m_ui->clangdChooser->setEnabled(checked);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CppCodeModelSettingsWidget::applyClangCodeModelWidgetsToSettings() const
|
bool CppCodeModelSettingsWidget::applyClangCodeModelWidgetsToSettings() const
|
||||||
@@ -176,16 +166,6 @@ bool CppCodeModelSettingsWidget::applyGeneralWidgetsToSettings() const
|
|||||||
m_settings->setIndexerFileSizeLimitInMb(newFileSizeLimit);
|
m_settings->setIndexerFileSizeLimitInMb(newFileSizeLimit);
|
||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
}
|
}
|
||||||
const bool newUseClangd = m_ui->clangdCheckBox->isChecked();
|
|
||||||
if (m_settings->useClangd() != newUseClangd) {
|
|
||||||
m_settings->setUseClangd(newUseClangd);
|
|
||||||
settingsChanged = true;
|
|
||||||
}
|
|
||||||
const Utils::FilePath newClangdPath = m_ui->clangdChooser->rawFilePath();
|
|
||||||
if (m_settings->clangdFilePath() != newClangdPath) {
|
|
||||||
m_settings->setClangdFilePath(newClangdPath);
|
|
||||||
settingsChanged = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const bool newIgnorePch = m_ui->ignorePCHCheckBox->isChecked();
|
const bool newIgnorePch = m_ui->ignorePCHCheckBox->isChecked();
|
||||||
const bool previousIgnorePch = m_settings->pchUsage() == CppCodeModelSettings::PchUse_None;
|
const bool previousIgnorePch = m_settings->pchUsage() == CppCodeModelSettings::PchUse_None;
|
||||||
@@ -210,5 +190,60 @@ CppCodeModelSettingsPage::CppCodeModelSettingsPage(CppCodeModelSettings *setting
|
|||||||
setWidgetCreator([settings] { return new CppCodeModelSettingsWidget(settings); });
|
setWidgetCreator([settings] { return new CppCodeModelSettingsWidget(settings); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class ClangdSettingsWidget final : public Core::IOptionsPageWidget
|
||||||
|
{
|
||||||
|
Q_DECLARE_TR_FUNCTIONS(CppTools::Internal::ClangdSettingsWidget)
|
||||||
|
|
||||||
|
public:
|
||||||
|
ClangdSettingsWidget()
|
||||||
|
{
|
||||||
|
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());
|
||||||
|
|
||||||
|
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);
|
||||||
|
layout->addLayout(formLayout);
|
||||||
|
layout->addStretch(1);
|
||||||
|
|
||||||
|
const auto toggleEnabled = [=](const bool checked) {
|
||||||
|
chooserLabel->setEnabled(checked);
|
||||||
|
m_clangdChooser.setEnabled(checked);
|
||||||
|
};
|
||||||
|
connect(&m_useClangdCheckBox, &QCheckBox::toggled, toggleEnabled);
|
||||||
|
toggleEnabled(m_useClangdCheckBox.isChecked());
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void apply() final
|
||||||
|
{
|
||||||
|
ClangdSettings::Data data;
|
||||||
|
data.useClangd = m_useClangdCheckBox.isChecked();
|
||||||
|
data.executableFilePath = m_clangdChooser.filePath();
|
||||||
|
ClangdSettings::setData(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
QCheckBox m_useClangdCheckBox;
|
||||||
|
Utils::PathChooser m_clangdChooser;
|
||||||
|
};
|
||||||
|
|
||||||
|
ClangdSettingsPage::ClangdSettingsPage()
|
||||||
|
{
|
||||||
|
setId("K.Clangd");
|
||||||
|
setDisplayName(ClangdSettingsWidget::tr("Clangd"));
|
||||||
|
setCategory(Constants::CPP_SETTINGS_CATEGORY);
|
||||||
|
setWidgetCreator([] { return new ClangdSettingsWidget; });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // Internal
|
} // Internal
|
||||||
} // CppTools
|
} // CppTools
|
||||||
|
|||||||
@@ -38,5 +38,11 @@ public:
|
|||||||
explicit CppCodeModelSettingsPage(CppCodeModelSettings *settings);
|
explicit CppCodeModelSettingsPage(CppCodeModelSettings *settings);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ClangdSettingsPage final : public Core::IOptionsPage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit ClangdSettingsPage();
|
||||||
|
};
|
||||||
|
|
||||||
} // Internal namespace
|
} // Internal namespace
|
||||||
} // CppTools namespace
|
} // CppTools namespace
|
||||||
|
|||||||
@@ -81,31 +81,7 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
<layout class="QHBoxLayout" name="horizontalLayout_3"/>
|
||||||
<item>
|
|
||||||
<widget class="QCheckBox" name="clangdCheckBox">
|
|
||||||
<property name="text">
|
|
||||||
<string>Use clangd (EXPERIMENTAL)</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="Utils::PathChooser" name="clangdChooser"/>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer name="horizontalSpacer_3">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
@@ -174,11 +150,6 @@
|
|||||||
<extends>QWidget</extends>
|
<extends>QWidget</extends>
|
||||||
<header>cpptools/clangdiagnosticconfigsselectionwidget.h</header>
|
<header>cpptools/clangdiagnosticconfigsselectionwidget.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
|
||||||
<class>Utils::PathChooser</class>
|
|
||||||
<extends>QLineEdit</extends>
|
|
||||||
<header location="global">utils/pathchooser.h</header>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ public:
|
|||||||
~CppToolsPluginPrivate()
|
~CppToolsPluginPrivate()
|
||||||
{
|
{
|
||||||
ExtensionSystem::PluginManager::removeObject(&m_cppProjectUpdaterFactory);
|
ExtensionSystem::PluginManager::removeObject(&m_cppProjectUpdaterFactory);
|
||||||
|
delete m_clangdSettingsPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringTable stringTable;
|
StringTable stringTable;
|
||||||
@@ -95,6 +96,7 @@ public:
|
|||||||
CppFileSettings m_fileSettings;
|
CppFileSettings m_fileSettings;
|
||||||
CppFileSettingsPage m_cppFileSettingsPage{&m_fileSettings};
|
CppFileSettingsPage m_cppFileSettingsPage{&m_fileSettings};
|
||||||
CppCodeModelSettingsPage m_cppCodeModelSettingsPage{&m_codeModelSettings};
|
CppCodeModelSettingsPage m_cppCodeModelSettingsPage{&m_codeModelSettings};
|
||||||
|
ClangdSettingsPage *m_clangdSettingsPage = nullptr;
|
||||||
CppCodeStyleSettingsPage m_cppCodeStyleSettingsPage;
|
CppCodeStyleSettingsPage m_cppCodeStyleSettingsPage;
|
||||||
CppProjectUpdaterFactory m_cppProjectUpdaterFactory;
|
CppProjectUpdaterFactory m_cppProjectUpdaterFactory;
|
||||||
};
|
};
|
||||||
@@ -218,6 +220,8 @@ void CppToolsPlugin::extensionsInitialized()
|
|||||||
d->m_fileSettings.fromSettings(ICore::settings());
|
d->m_fileSettings.fromSettings(ICore::settings());
|
||||||
if (!d->m_fileSettings.applySuffixesToMimeDB())
|
if (!d->m_fileSettings.applySuffixesToMimeDB())
|
||||||
qWarning("Unable to apply cpp suffixes to mime database (cpp mime types not found).\n");
|
qWarning("Unable to apply cpp suffixes to mime database (cpp mime types not found).\n");
|
||||||
|
if (CppModelManager::instance()->isClangCodeModelActive())
|
||||||
|
d->m_clangdSettingsPage = new ClangdSettingsPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
CppCodeModelSettings *CppToolsPlugin::codeModelSettings()
|
CppCodeModelSettings *CppToolsPlugin::codeModelSettings()
|
||||||
|
|||||||
Reference in New Issue
Block a user