forked from qt-creator/qt-creator
Clangd: add setting for index priority
Change-Id: I5f9ea8c31747d1cd1e1e6b77ab7c705a7f275cff Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -137,9 +137,12 @@ void setupClangdConfigFile()
|
||||
|
||||
static BaseClientInterface *clientInterface(Project *project, const Utils::FilePath &jsonDbDir)
|
||||
{
|
||||
using CppEditor::ClangdSettings;
|
||||
QString indexingOption = "--background-index";
|
||||
const CppEditor::ClangdSettings settings(CppEditor::ClangdProjectSettings(project).settings());
|
||||
if (!settings.indexingEnabled() || jsonDbDir.isEmpty())
|
||||
const ClangdSettings settings(CppEditor::ClangdProjectSettings(project).settings());
|
||||
const ClangdSettings::IndexingPriority indexingPriority = settings.indexingPriority();
|
||||
const bool indexingEnabled = indexingPriority != ClangdSettings::IndexingPriority::Off;
|
||||
if (!indexingEnabled)
|
||||
indexingOption += "=0";
|
||||
const QString headerInsertionOption = QString("--header-insertion=")
|
||||
+ (settings.autoIncludeHeaders() ? "iwyu" : "never");
|
||||
@@ -152,6 +155,10 @@ static BaseClientInterface *clientInterface(Project *project, const Utils::FileP
|
||||
"--clang-tidy=0"}};
|
||||
if (settings.workerThreadLimit() != 0)
|
||||
cmd.addArg("-j=" + QString::number(settings.workerThreadLimit()));
|
||||
if (indexingEnabled && settings.clangdVersion() >= QVersionNumber(15)) {
|
||||
cmd.addArg("--background-index-priority="
|
||||
+ ClangdSettings::priorityToString(indexingPriority));
|
||||
}
|
||||
if (!jsonDbDir.isEmpty())
|
||||
cmd.addArg("--compile-commands-dir=" + jsonDbDir.toString());
|
||||
if (clangdLogServer().isDebugEnabled())
|
||||
|
||||
@@ -55,6 +55,7 @@ static QString clangdSettingsKey() { return QLatin1String("ClangdSettings"); }
|
||||
static QString useClangdKey() { return QLatin1String("UseClangdV7"); }
|
||||
static QString clangdPathKey() { return QLatin1String("ClangdPath"); }
|
||||
static QString clangdIndexingKey() { return QLatin1String("ClangdIndexing"); }
|
||||
static QString clangdIndexingPriorityKey() { return QLatin1String("ClangdIndexingPriority"); }
|
||||
static QString clangdHeaderInsertionKey() { return QLatin1String("ClangdHeaderInsertion"); }
|
||||
static QString clangdThreadLimitKey() { return QLatin1String("ClangdThreadLimit"); }
|
||||
static QString clangdDocumentThresholdKey() { return QLatin1String("ClangdDocumentThreshold"); }
|
||||
@@ -168,6 +169,28 @@ void CppCodeModelSettings::setEnableLowerClazyLevels(bool yesno)
|
||||
}
|
||||
|
||||
|
||||
QString ClangdSettings::priorityToString(const IndexingPriority &priority)
|
||||
{
|
||||
switch (priority) {
|
||||
case IndexingPriority::Background: return "background";
|
||||
case IndexingPriority::Normal: return "normal";
|
||||
case IndexingPriority::Low: return "low";
|
||||
case IndexingPriority::Off: return {};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
QString ClangdSettings::priorityToDisplayString(const IndexingPriority &priority)
|
||||
{
|
||||
switch (priority) {
|
||||
case IndexingPriority::Background: return tr("Background Priority");
|
||||
case IndexingPriority::Normal: return tr("Normal Priority");
|
||||
case IndexingPriority::Low: return tr("Low Priority");
|
||||
case IndexingPriority::Off: return tr("Off");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ClangdSettings &ClangdSettings::instance()
|
||||
{
|
||||
static ClangdSettings settings;
|
||||
@@ -465,7 +488,8 @@ QVariantMap ClangdSettings::Data::toMap() const
|
||||
map.insert(clangdPathKey(),
|
||||
executableFilePath != fallbackClangdFilePath() ? executableFilePath.toString()
|
||||
: QString());
|
||||
map.insert(clangdIndexingKey(), enableIndexing);
|
||||
map.insert(clangdIndexingKey(), indexingPriority != IndexingPriority::Off);
|
||||
map.insert(clangdIndexingPriorityKey(), int(indexingPriority));
|
||||
map.insert(clangdHeaderInsertionKey(), autoIncludeHeaders);
|
||||
map.insert(clangdThreadLimitKey(), workerThreadLimit);
|
||||
map.insert(clangdDocumentThresholdKey(), documentUpdateThreshold);
|
||||
@@ -482,7 +506,11 @@ void ClangdSettings::Data::fromMap(const QVariantMap &map)
|
||||
{
|
||||
useClangd = map.value(useClangdKey(), true).toBool();
|
||||
executableFilePath = FilePath::fromString(map.value(clangdPathKey()).toString());
|
||||
enableIndexing = map.value(clangdIndexingKey(), true).toBool();
|
||||
indexingPriority = IndexingPriority(
|
||||
map.value(clangdIndexingPriorityKey(), int(this->indexingPriority)).toInt());
|
||||
const auto it = map.find(clangdIndexingKey());
|
||||
if (it != map.end() && !it->toBool())
|
||||
indexingPriority = IndexingPriority::Off;
|
||||
autoIncludeHeaders = map.value(clangdHeaderInsertionKey(), false).toBool();
|
||||
workerThreadLimit = map.value(clangdThreadLimitKey(), 0).toInt();
|
||||
documentUpdateThreshold = map.value(clangdDocumentThresholdKey(), 500).toInt();
|
||||
|
||||
@@ -75,6 +75,10 @@ class CPPEDITOR_EXPORT ClangdSettings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum class IndexingPriority { Off, Background, Normal, Low, };
|
||||
|
||||
static QString priorityToString(const IndexingPriority &priority);
|
||||
static QString priorityToDisplayString(const IndexingPriority &priority);
|
||||
|
||||
class CPPEDITOR_EXPORT Data
|
||||
{
|
||||
@@ -90,7 +94,7 @@ public:
|
||||
&& s1.customDiagnosticConfigs == s2.customDiagnosticConfigs
|
||||
&& s1.diagnosticConfigId == s2.diagnosticConfigId
|
||||
&& s1.workerThreadLimit == s2.workerThreadLimit
|
||||
&& s1.enableIndexing == s2.enableIndexing
|
||||
&& s1.indexingPriority == s2.indexingPriority
|
||||
&& s1.autoIncludeHeaders == s2.autoIncludeHeaders
|
||||
&& s1.documentUpdateThreshold == s2.documentUpdateThreshold
|
||||
&& s1.sizeThresholdEnabled == s2.sizeThresholdEnabled
|
||||
@@ -110,7 +114,7 @@ public:
|
||||
int documentUpdateThreshold = 500;
|
||||
qint64 sizeThresholdInKb = 1024;
|
||||
bool useClangd = true;
|
||||
bool enableIndexing = true;
|
||||
IndexingPriority indexingPriority = IndexingPriority::Low;
|
||||
bool autoIncludeHeaders = false;
|
||||
bool sizeThresholdEnabled = false;
|
||||
bool haveCheckedHardwareReqirements = false;
|
||||
@@ -129,7 +133,7 @@ public:
|
||||
static void setDefaultClangdPath(const Utils::FilePath &filePath);
|
||||
static void setCustomDiagnosticConfigs(const ClangDiagnosticConfigs &configs);
|
||||
Utils::FilePath clangdFilePath() const;
|
||||
bool indexingEnabled() const { return m_data.enableIndexing; }
|
||||
IndexingPriority indexingPriority() const { return m_data.indexingPriority; }
|
||||
bool autoIncludeHeaders() const { return m_data.autoIncludeHeaders; }
|
||||
int workerThreadLimit() const { return m_data.workerThreadLimit; }
|
||||
int documentUpdateThreshold() const { return m_data.documentUpdateThreshold; }
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QDesktopServices>
|
||||
#include <QFormLayout>
|
||||
#include <QGroupBox>
|
||||
@@ -164,7 +165,7 @@ class ClangdSettingsWidget::Private
|
||||
{
|
||||
public:
|
||||
QCheckBox useClangdCheckBox;
|
||||
QCheckBox indexingCheckBox;
|
||||
QComboBox indexingComboBox;
|
||||
QCheckBox autoIncludeHeadersCheckBox;
|
||||
QCheckBox sizeThresholdCheckBox;
|
||||
QSpinBox threadLimitSpinBox;
|
||||
@@ -190,7 +191,13 @@ ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsD
|
||||
"The indexing result is persisted in the project's build directory.\n"
|
||||
"\n"
|
||||
"If you disable background indexing, a faster, but less accurate,\n"
|
||||
"built-in indexer is used instead.");
|
||||
"built-in indexer is used instead.\n"
|
||||
"\n"
|
||||
"The thread priority for building the background index can be adjusted since clangd 15.\n"
|
||||
"Background Priority: Minimum priority, runs on idle CPUs. May leave 'performance' cores "
|
||||
"unused.\n"
|
||||
"Normal Priority: Reduced priority compared to interactive work.\n"
|
||||
"Low Priority: Same priority as other clangd work.");
|
||||
const QString workerThreadsToolTip = tr(
|
||||
"Number of worker threads used by clangd. Background indexing also uses this many "
|
||||
"worker threads.");
|
||||
@@ -211,9 +218,13 @@ ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsD
|
||||
d->clangdChooser.setExpectedKind(Utils::PathChooser::ExistingCommand);
|
||||
d->clangdChooser.setFilePath(settings.clangdFilePath());
|
||||
d->clangdChooser.setEnabled(d->useClangdCheckBox.isChecked());
|
||||
d->indexingCheckBox.setText(tr("Enable background indexing"));
|
||||
d->indexingCheckBox.setChecked(settings.indexingEnabled());
|
||||
d->indexingCheckBox.setToolTip(indexingToolTip);
|
||||
using Priority = ClangdSettings::IndexingPriority;
|
||||
for (Priority prio : {Priority::Off, Priority::Background, Priority::Low, Priority::Normal}) {
|
||||
d->indexingComboBox.addItem(ClangdSettings::priorityToDisplayString(prio), int(prio));
|
||||
if (prio == settings.indexingPriority())
|
||||
d->indexingComboBox.setCurrentIndex(d->indexingComboBox.count() - 1);
|
||||
}
|
||||
d->indexingComboBox.setToolTip(indexingToolTip);
|
||||
d->autoIncludeHeadersCheckBox.setText(tr("Insert header files on completion"));
|
||||
d->autoIncludeHeadersCheckBox.setChecked(settings.autoIncludeHeaders());
|
||||
d->autoIncludeHeadersCheckBox.setToolTip(autoIncludeToolTip);
|
||||
@@ -251,7 +262,14 @@ ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsD
|
||||
const auto chooserLabel = new QLabel(tr("Path to executable:"));
|
||||
formLayout->addRow(chooserLabel, &d->clangdChooser);
|
||||
formLayout->addRow(QString(), &d->versionWarningLabel);
|
||||
formLayout->addRow(QString(), &d->indexingCheckBox);
|
||||
|
||||
const auto indexingPriorityLayout = new QHBoxLayout;
|
||||
indexingPriorityLayout->addWidget(&d->indexingComboBox);
|
||||
indexingPriorityLayout->addStretch(1);
|
||||
const auto indexingPriorityLabel = new QLabel(tr("Background indexing:"));
|
||||
indexingPriorityLabel->setToolTip(indexingToolTip);
|
||||
formLayout->addRow(indexingPriorityLabel, indexingPriorityLayout);
|
||||
|
||||
const auto threadLimitLayout = new QHBoxLayout;
|
||||
threadLimitLayout->addWidget(&d->threadLimitSpinBox);
|
||||
threadLimitLayout->addStretch(1);
|
||||
@@ -413,7 +431,7 @@ ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsD
|
||||
|
||||
connect(&d->useClangdCheckBox, &QCheckBox::toggled,
|
||||
this, &ClangdSettingsWidget::settingsDataChanged);
|
||||
connect(&d->indexingCheckBox, &QCheckBox::toggled,
|
||||
connect(&d->indexingComboBox, &QComboBox::currentIndexChanged,
|
||||
this, &ClangdSettingsWidget::settingsDataChanged);
|
||||
connect(&d->autoIncludeHeadersCheckBox, &QCheckBox::toggled,
|
||||
this, &ClangdSettingsWidget::settingsDataChanged);
|
||||
@@ -443,7 +461,8 @@ ClangdSettings::Data ClangdSettingsWidget::settingsData() const
|
||||
ClangdSettings::Data data;
|
||||
data.useClangd = d->useClangdCheckBox.isChecked();
|
||||
data.executableFilePath = d->clangdChooser.filePath();
|
||||
data.enableIndexing = d->indexingCheckBox.isChecked();
|
||||
data.indexingPriority = ClangdSettings::IndexingPriority(
|
||||
d->indexingComboBox.currentData().toInt());
|
||||
data.autoIncludeHeaders = d->autoIncludeHeadersCheckBox.isChecked();
|
||||
data.workerThreadLimit = d->threadLimitSpinBox.value();
|
||||
data.documentUpdateThreshold = d->documentUpdateThreshold.value();
|
||||
|
||||
Reference in New Issue
Block a user