clangd: add setting for document update timeout

Change-Id: I4fae2cdff022f6f29566c0316a8ade51d3482466
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
David Schulz
2021-08-12 12:00:58 +02:00
parent 68313a1e27
commit fdd3b03ba9
6 changed files with 31 additions and 2 deletions

View File

@@ -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); };

View File

@@ -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();
}

View File

@@ -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)
{

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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);