Clangd: Allow to switch off background indexing

It is conceivable that users don't want to spend the extra CPU time on
this.

Change-Id: Ic3611c8d17d201ae986fad08b344369a8728ce1b
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2021-06-25 17:40:20 +02:00
parent ba138a1855
commit 876cd8e975
4 changed files with 23 additions and 2 deletions

View File

@@ -65,6 +65,7 @@ static QString indexerFileSizeLimitKey()
static QString useClangdKey() { return QLatin1String("UseClangd"); }
static QString clangdPathKey() { return QLatin1String("ClangdPath"); }
static QString clangdIndexingKey() { return QLatin1String("ClangdIndexing"); }
static FilePath g_defaultClangdFilePath;
static FilePath fallbackClangdFilePath()
@@ -300,7 +301,9 @@ void CppCodeModelSettings::setEnableLowerClazyLevels(bool yesno)
static bool operator==(const ClangdSettings::Data &s1, const ClangdSettings::Data &s2)
{
return s1.useClangd == s2.useClangd && s1.executableFilePath == s2.executableFilePath;
return s1.useClangd == s2.useClangd
&& s1.executableFilePath == s2.executableFilePath
&& s1.enableIndexing == s2.enableIndexing;
}
static bool operator!=(const ClangdSettings::Data &s1, const ClangdSettings::Data &s2)
{
@@ -338,6 +341,7 @@ 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();
}
void ClangdSettings::saveSettings()
@@ -345,6 +349,7 @@ 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);
}
#ifdef WITH_TESTS

View File

@@ -103,6 +103,7 @@ public:
{
public:
bool useClangd = false;
bool enableIndexing = true;
Utils::FilePath executableFilePath;
};
@@ -110,6 +111,7 @@ public:
static void setDefaultClangdPath(const Utils::FilePath &filePath);
static Utils::FilePath clangdFilePath();
static bool indexingEnabled() { return instance().m_data.enableIndexing; }
static void setData(const Data &data);
static Data data() { return instance().m_data; }

View File

@@ -205,18 +205,27 @@ public:
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."));
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);
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);
};
connect(&m_useClangdCheckBox, &QCheckBox::toggled, toggleEnabled);
toggleEnabled(m_useClangdCheckBox.isChecked());
@@ -228,10 +237,12 @@ private:
ClangdSettings::Data data;
data.useClangd = m_useClangdCheckBox.isChecked();
data.executableFilePath = m_clangdChooser.filePath();
data.enableIndexing = m_indexingCheckBox.isChecked();
ClangdSettings::setData(data);
}
QCheckBox m_useClangdCheckBox;
QCheckBox m_indexingCheckBox;
Utils::PathChooser m_clangdChooser;
};