diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index 7768da70334..26721c84219 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -387,6 +387,8 @@ static BaseClientInterface *clientInterface(const Utils::FilePath &jsonDbDir) 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())); if (!jsonDbDir.isEmpty()) cmd.addArg("--compile-commands-dir=" + jsonDbDir.toString()); if (clangdLog().isDebugEnabled()) diff --git a/src/plugins/cpptools/cppcodemodelsettings.cpp b/src/plugins/cpptools/cppcodemodelsettings.cpp index 4c717801608..6fd9a15b534 100644 --- a/src/plugins/cpptools/cppcodemodelsettings.cpp +++ b/src/plugins/cpptools/cppcodemodelsettings.cpp @@ -66,6 +66,7 @@ static QString indexerFileSizeLimitKey() 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 FilePath g_defaultClangdFilePath; static FilePath fallbackClangdFilePath() @@ -303,6 +304,7 @@ static bool operator==(const ClangdSettings::Data &s1, const ClangdSettings::Dat { return s1.useClangd == s2.useClangd && s1.executableFilePath == s2.executableFilePath + && s1.workerThreadLimit == s2.workerThreadLimit && s1.enableIndexing == s2.enableIndexing; } static bool operator!=(const ClangdSettings::Data &s1, const ClangdSettings::Data &s2) @@ -342,6 +344,7 @@ void ClangdSettings::loadSettings() 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(); } void ClangdSettings::saveSettings() @@ -350,6 +353,7 @@ void ClangdSettings::saveSettings() s->setValue(useClangdKey(), useClangd()); s->setValue(clangdPathKey(), m_data.executableFilePath.toString()); s->setValue(clangdIndexingKey(), m_data.enableIndexing); + s->setValue(clangdThreadLimitKey(), m_data.workerThreadLimit); } #ifdef WITH_TESTS diff --git a/src/plugins/cpptools/cppcodemodelsettings.h b/src/plugins/cpptools/cppcodemodelsettings.h index 4cc37a0dcba..eb4abe4537e 100644 --- a/src/plugins/cpptools/cppcodemodelsettings.h +++ b/src/plugins/cpptools/cppcodemodelsettings.h @@ -102,9 +102,10 @@ public: class Data { public: + Utils::FilePath executableFilePath; + int workerThreadLimit = 0; bool useClangd = false; bool enableIndexing = true; - Utils::FilePath executableFilePath; }; static bool useClangd() { return instance().m_data.useClangd; } @@ -112,6 +113,7 @@ public: 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; } static void setData(const Data &data); static Data data() { return instance().m_data; } diff --git a/src/plugins/cpptools/cppcodemodelsettingspage.cpp b/src/plugins/cpptools/cppcodemodelsettingspage.cpp index d3a75af0cb9..f48f639d16a 100644 --- a/src/plugins/cpptools/cppcodemodelsettingspage.cpp +++ b/src/plugins/cpptools/cppcodemodelsettingspage.cpp @@ -36,6 +36,7 @@ #include #include +#include #include namespace CppTools { @@ -210,6 +211,10 @@ public: "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_threadLimitCheckBox.setText(tr("Set worker thread count limit")); + m_threadLimitCheckBox.setChecked(ClangdSettings::workerThreadLimit() != 0); + m_threadLimitSpinBox.setMinimum(1); + m_threadLimitSpinBox.setValue(ClangdSettings::workerThreadLimit()); const auto layout = new QVBoxLayout(this); layout->addWidget(&m_useClangdCheckBox); @@ -218,6 +223,10 @@ public: 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); + formLayout->addRow(&m_threadLimitCheckBox, threadLimitLayout); layout->addLayout(formLayout); layout->addStretch(1); @@ -226,9 +235,15 @@ public: m_clangdChooser.setEnabled(checked); indexingLabel->setEnabled(checked); m_indexingCheckBox.setEnabled(checked); + m_threadLimitCheckBox.setEnabled(checked); + m_threadLimitSpinBox.setEnabled(checked && m_threadLimitCheckBox.isChecked()); }; connect(&m_useClangdCheckBox, &QCheckBox::toggled, toggleEnabled); + connect(&m_threadLimitCheckBox, &QCheckBox::toggled, + &m_threadLimitSpinBox, &QSpinBox::setEnabled); toggleEnabled(m_useClangdCheckBox.isChecked()); + m_threadLimitSpinBox.setEnabled(m_useClangdCheckBox.isChecked() + && m_threadLimitCheckBox.isChecked()); } private: @@ -238,11 +253,15 @@ private: data.useClangd = m_useClangdCheckBox.isChecked(); data.executableFilePath = m_clangdChooser.filePath(); data.enableIndexing = m_indexingCheckBox.isChecked(); + data.workerThreadLimit = m_threadLimitCheckBox.isChecked() + ? m_threadLimitSpinBox.value() : 0; ClangdSettings::setData(data); } QCheckBox m_useClangdCheckBox; QCheckBox m_indexingCheckBox; + QCheckBox m_threadLimitCheckBox; + QSpinBox m_threadLimitSpinBox; Utils::PathChooser m_clangdChooser; }; @@ -254,7 +273,5 @@ ClangdSettingsPage::ClangdSettingsPage() setWidgetCreator([] { return new ClangdSettingsWidget; }); } - - } // Internal } // CppTools