diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index cb1d17556b0..55c5cf713c4 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -759,6 +759,7 @@ ClangdClient::ClangdClient(Project *project, const Utils::FilePath &jsonDbDir) setAutoRequestCodeActions(false); // clangd sends code actions inside diagnostics setProgressTitleForToken(indexingToken(), tr("Parsing C/C++ Files (clangd)")); setCurrentProject(project); + setDocumentChangeUpdateThreshold(d->settings.documentUpdateThreshold); const auto textMarkCreator = [this](const Utils::FilePath &filePath, const Diagnostic &diag) { return new ClangdTextMark(filePath, diag, this); }; diff --git a/src/plugins/cpptools/cppcodemodelsettings.cpp b/src/plugins/cpptools/cppcodemodelsettings.cpp index c7cfc2d0cb8..e62cec22c87 100644 --- a/src/plugins/cpptools/cppcodemodelsettings.cpp +++ b/src/plugins/cpptools/cppcodemodelsettings.cpp @@ -69,6 +69,7 @@ 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 clangdDocumentThresholdKey() { return QLatin1String("ClangdDocumentThreshold"); } static QString clangdUseGlobalSettingsKey() { return QLatin1String("useGlobalSettings"); } static FilePath g_defaultClangdFilePath; @@ -402,6 +403,7 @@ QVariantMap ClangdSettings::Data::toMap() const map.insert(clangdPathKey(), executableFilePath.toString()); map.insert(clangdIndexingKey(), enableIndexing); map.insert(clangdThreadLimitKey(), workerThreadLimit); + map.insert(clangdDocumentThresholdKey(), documentUpdateThreshold); return map; } @@ -411,4 +413,5 @@ void ClangdSettings::Data::fromMap(const QVariantMap &map) executableFilePath = FilePath::fromString(map.value(clangdPathKey()).toString()); enableIndexing = map.value(clangdIndexingKey(), true).toBool(); workerThreadLimit = map.value(clangdThreadLimitKey(), 0).toInt(); + documentUpdateThreshold = map.value(clangdDocumentThresholdKey(), 500).toInt(); } diff --git a/src/plugins/cpptools/cppcodemodelsettings.h b/src/plugins/cpptools/cppcodemodelsettings.h index d4da25f3b09..c229638d958 100644 --- a/src/plugins/cpptools/cppcodemodelsettings.h +++ b/src/plugins/cpptools/cppcodemodelsettings.h @@ -112,6 +112,7 @@ public: int workerThreadLimit = 0; bool useClangd = false; bool enableIndexing = true; + int documentUpdateThreshold = 500; }; ClangdSettings(const Data &data) : m_data(data) {} @@ -123,6 +124,7 @@ public: Utils::FilePath clangdFilePath() const; bool indexingEnabled() const { return m_data.enableIndexing; } int workerThreadLimit() const { return m_data.workerThreadLimit; } + int documentUpdateThreshold() const { return m_data.documentUpdateThreshold; } void setData(const Data &data); Data data() const { return m_data; } @@ -149,7 +151,8 @@ inline 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; + && s1.enableIndexing == s2.enableIndexing + && s1.documentUpdateThreshold == s2.documentUpdateThreshold; } inline bool operator!=(const ClangdSettings::Data &s1, const ClangdSettings::Data &s2) { diff --git a/src/plugins/cpptools/cppcodemodelsettingspage.cpp b/src/plugins/cpptools/cppcodemodelsettingspage.cpp index dc04dc3cb89..f591a9c8b32 100644 --- a/src/plugins/cpptools/cppcodemodelsettingspage.cpp +++ b/src/plugins/cpptools/cppcodemodelsettingspage.cpp @@ -197,6 +197,7 @@ public: QCheckBox useClangdCheckBox; QCheckBox indexingCheckBox; QSpinBox threadLimitSpinBox; + QSpinBox documentUpdateThreshold; Utils::PathChooser clangdChooser; }; @@ -216,6 +217,15 @@ ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsD "the project is first opened.")); d->threadLimitSpinBox.setValue(settings.workerThreadLimit()); d->threadLimitSpinBox.setSpecialValueText("Automatic"); + d->documentUpdateThreshold.setMinimum(50); + d->documentUpdateThreshold.setMaximum(10000); + d->documentUpdateThreshold.setValue(settings.documentUpdateThreshold()); + d->documentUpdateThreshold.setSingleStep(100); + d->documentUpdateThreshold.setSuffix(" ms"); + d->documentUpdateThreshold.setToolTip( + tr("Defines the amount of time Qt Creator waits before sending document changes to the " + "server.\n" + "If the document changes again while waiting, this timeout resets.\n")); const auto layout = new QVBoxLayout(this); layout->addWidget(&d->useClangdCheckBox); @@ -227,8 +237,13 @@ ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsD const auto threadLimitLayout = new QHBoxLayout; threadLimitLayout->addWidget(&d->threadLimitSpinBox); threadLimitLayout->addStretch(1); - const auto threadLimitLabel = new QLabel(tr("Set worker thread count:")); + const auto threadLimitLabel = new QLabel(tr("Worker thread count:")); formLayout->addRow(threadLimitLabel, threadLimitLayout); + const auto documentUpdateThresholdLayout = new QHBoxLayout; + documentUpdateThresholdLayout->addWidget(&d->documentUpdateThreshold); + documentUpdateThresholdLayout->addStretch(1); + const auto documentUpdateThresholdLabel = new QLabel(tr("Document update threshold:")); + formLayout->addRow(documentUpdateThresholdLabel, documentUpdateThresholdLayout); layout->addLayout(formLayout); layout->addStretch(1); @@ -265,6 +280,7 @@ ClangdSettings::Data ClangdSettingsWidget::settingsData() const data.executableFilePath = d->clangdChooser.filePath(); data.enableIndexing = d->indexingCheckBox.isChecked(); data.workerThreadLimit = d->threadLimitSpinBox.value(); + data.documentUpdateThreshold = d->documentUpdateThreshold.value(); return data; } diff --git a/src/plugins/languageclient/client.cpp b/src/plugins/languageclient/client.cpp index a2a61f12244..1852cda7486 100644 --- a/src/plugins/languageclient/client.cpp +++ b/src/plugins/languageclient/client.cpp @@ -1381,6 +1381,11 @@ int Client::documentVersion(const Utils::FilePath &filePath) const return m_documentVersions.value(filePath); } +void Client::setDocumentChangeUpdateThreshold(int msecs) +{ + m_documentUpdateTimer.setInterval(msecs); +} + void Client::initializeCallback(const InitializeRequest::Response &initResponse) { QTC_ASSERT(m_state == InitializeRequested, return); diff --git a/src/plugins/languageclient/client.h b/src/plugins/languageclient/client.h index d046064e30a..c4ca395465d 100644 --- a/src/plugins/languageclient/client.h +++ b/src/plugins/languageclient/client.h @@ -151,6 +151,7 @@ public: void cursorPositionChanged(TextEditor::TextEditorWidget *widget); bool documentUpdatePostponed(const Utils::FilePath &fileName) const; int documentVersion(const Utils::FilePath &filePath) const; + void setDocumentChangeUpdateThreshold(int msecs); // workspace control virtual void setCurrentProject(ProjectExplorer::Project *project);