forked from qt-creator/qt-creator
ClangCodeModel: Allow users to set a file size threshold for clangd
With huge source files it might not be so useful to continuously recompile them while editing, which is basically what clangd does. Let users opt out. Change-Id: If3e95c1e286090606a84961d071179f8b40f9180 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -367,8 +367,11 @@ void ClangModelManagerSupport::updateLanguageClient(
|
|||||||
|
|
||||||
// Acquaint the client with all open C++ documents for this project.
|
// Acquaint the client with all open C++ documents for this project.
|
||||||
bool hasDocuments = false;
|
bool hasDocuments = false;
|
||||||
|
const ClangdSettings settings(ClangdProjectSettings(project).settings());
|
||||||
for (TextEditor::TextDocument * const doc : allCppDocuments()) {
|
for (TextEditor::TextDocument * const doc : allCppDocuments()) {
|
||||||
const Client * const currentClient = LanguageClientManager::clientForDocument(doc);
|
const Client * const currentClient = LanguageClientManager::clientForDocument(doc);
|
||||||
|
if (!settings.sizeIsOkay(doc->filePath()))
|
||||||
|
continue;
|
||||||
if (!currentClient || !currentClient->project()
|
if (!currentClient || !currentClient->project()
|
||||||
|| currentClient->state() != Client::Initialized
|
|| currentClient->state() != Client::Initialized
|
||||||
|| project->isKnownFile(doc->filePath())) {
|
|| project->isKnownFile(doc->filePath())) {
|
||||||
@@ -466,6 +469,8 @@ void ClangModelManagerSupport::claimNonProjectSources(ClangdClient *client)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ClangEditorDocumentProcessor::clearTextMarks(doc->filePath());
|
ClangEditorDocumentProcessor::clearTextMarks(doc->filePath());
|
||||||
|
if (!ClangdSettings::instance().sizeIsOkay(doc->filePath()))
|
||||||
|
continue;
|
||||||
client->openDocument(doc);
|
client->openDocument(doc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -568,6 +573,9 @@ void ClangModelManagerSupport::onEditorOpened(Core::IEditor *editor)
|
|||||||
|
|
||||||
ProjectExplorer::Project * project
|
ProjectExplorer::Project * project
|
||||||
= ProjectExplorer::SessionManager::projectForFile(document->filePath());
|
= ProjectExplorer::SessionManager::projectForFile(document->filePath());
|
||||||
|
const ClangdSettings settings(ClangdProjectSettings(project).settings());
|
||||||
|
if (!settings.sizeIsOkay(textDocument->filePath()))
|
||||||
|
return;
|
||||||
if (!project)
|
if (!project)
|
||||||
project = fallbackProject();
|
project = fallbackProject();
|
||||||
if (ClangdClient * const client = clientForProject(project))
|
if (ClangdClient * const client = clientForProject(project))
|
||||||
|
@@ -78,6 +78,8 @@ static QString clangdIndexingKey() { return QLatin1String("ClangdIndexing"); }
|
|||||||
static QString clangdHeaderInsertionKey() { return QLatin1String("ClangdHeaderInsertion"); }
|
static QString clangdHeaderInsertionKey() { return QLatin1String("ClangdHeaderInsertion"); }
|
||||||
static QString clangdThreadLimitKey() { return QLatin1String("ClangdThreadLimit"); }
|
static QString clangdThreadLimitKey() { return QLatin1String("ClangdThreadLimit"); }
|
||||||
static QString clangdDocumentThresholdKey() { return QLatin1String("ClangdDocumentThreshold"); }
|
static QString clangdDocumentThresholdKey() { return QLatin1String("ClangdDocumentThreshold"); }
|
||||||
|
static QString clangdSizeThresholdEnabledKey() { return QLatin1String("ClangdSizeThresholdEnabled"); }
|
||||||
|
static QString clangdSizeThresholdKey() { return QLatin1String("ClangdSizeThreshold"); }
|
||||||
static QString clangdUseGlobalSettingsKey() { return QLatin1String("useGlobalSettings"); }
|
static QString clangdUseGlobalSettingsKey() { return QLatin1String("useGlobalSettings"); }
|
||||||
static QString sessionsWithOneClangdKey() { return QLatin1String("SessionsWithOneClangd"); }
|
static QString sessionsWithOneClangdKey() { return QLatin1String("SessionsWithOneClangd"); }
|
||||||
|
|
||||||
@@ -350,6 +352,11 @@ FilePath ClangdSettings::clangdFilePath() const
|
|||||||
return fallbackClangdFilePath();
|
return fallbackClangdFilePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ClangdSettings::sizeIsOkay(const Utils::FilePath &fp) const
|
||||||
|
{
|
||||||
|
return !sizeThresholdEnabled() || sizeThresholdInKb() * 1024 >= fp.fileSize();
|
||||||
|
}
|
||||||
|
|
||||||
ClangdSettings::Granularity ClangdSettings::granularity() const
|
ClangdSettings::Granularity ClangdSettings::granularity() const
|
||||||
{
|
{
|
||||||
if (m_data.sessionsWithOneClangd.contains(ProjectExplorer::SessionManager::activeSession()))
|
if (m_data.sessionsWithOneClangd.contains(ProjectExplorer::SessionManager::activeSession()))
|
||||||
@@ -479,6 +486,8 @@ QVariantMap ClangdSettings::Data::toMap() const
|
|||||||
map.insert(clangdHeaderInsertionKey(), autoIncludeHeaders);
|
map.insert(clangdHeaderInsertionKey(), autoIncludeHeaders);
|
||||||
map.insert(clangdThreadLimitKey(), workerThreadLimit);
|
map.insert(clangdThreadLimitKey(), workerThreadLimit);
|
||||||
map.insert(clangdDocumentThresholdKey(), documentUpdateThreshold);
|
map.insert(clangdDocumentThresholdKey(), documentUpdateThreshold);
|
||||||
|
map.insert(clangdSizeThresholdEnabledKey(), sizeThresholdEnabled);
|
||||||
|
map.insert(clangdSizeThresholdKey(), sizeThresholdInKb);
|
||||||
map.insert(sessionsWithOneClangdKey(), sessionsWithOneClangd);
|
map.insert(sessionsWithOneClangdKey(), sessionsWithOneClangd);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
@@ -491,6 +500,8 @@ void ClangdSettings::Data::fromMap(const QVariantMap &map)
|
|||||||
autoIncludeHeaders = map.value(clangdHeaderInsertionKey(), false).toBool();
|
autoIncludeHeaders = map.value(clangdHeaderInsertionKey(), false).toBool();
|
||||||
workerThreadLimit = map.value(clangdThreadLimitKey(), 0).toInt();
|
workerThreadLimit = map.value(clangdThreadLimitKey(), 0).toInt();
|
||||||
documentUpdateThreshold = map.value(clangdDocumentThresholdKey(), 500).toInt();
|
documentUpdateThreshold = map.value(clangdDocumentThresholdKey(), 500).toInt();
|
||||||
|
sizeThresholdEnabled = map.value(clangdSizeThresholdEnabledKey(), false).toBool();
|
||||||
|
sizeThresholdInKb = map.value(clangdSizeThresholdKey(), 1024).toLongLong();
|
||||||
sessionsWithOneClangd = map.value(sessionsWithOneClangdKey()).toStringList();
|
sessionsWithOneClangd = map.value(sessionsWithOneClangdKey()).toStringList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -115,17 +115,21 @@ public:
|
|||||||
&& s1.workerThreadLimit == s2.workerThreadLimit
|
&& s1.workerThreadLimit == s2.workerThreadLimit
|
||||||
&& s1.enableIndexing == s2.enableIndexing
|
&& s1.enableIndexing == s2.enableIndexing
|
||||||
&& s1.autoIncludeHeaders == s2.autoIncludeHeaders
|
&& s1.autoIncludeHeaders == s2.autoIncludeHeaders
|
||||||
&& s1.documentUpdateThreshold == s2.documentUpdateThreshold;
|
&& s1.documentUpdateThreshold == s2.documentUpdateThreshold
|
||||||
|
&& s1.sizeThresholdEnabled == s2.sizeThresholdEnabled
|
||||||
|
&& s1.sizeThresholdInKb == s2.sizeThresholdInKb;
|
||||||
}
|
}
|
||||||
friend bool operator!=(const Data &s1, const Data &s2) { return !(s1 == s2); }
|
friend bool operator!=(const Data &s1, const Data &s2) { return !(s1 == s2); }
|
||||||
|
|
||||||
Utils::FilePath executableFilePath;
|
Utils::FilePath executableFilePath;
|
||||||
QStringList sessionsWithOneClangd;
|
QStringList sessionsWithOneClangd;
|
||||||
int workerThreadLimit = 0;
|
int workerThreadLimit = 0;
|
||||||
|
int documentUpdateThreshold = 500;
|
||||||
|
qint64 sizeThresholdInKb = 1024;
|
||||||
bool useClangd = true;
|
bool useClangd = true;
|
||||||
bool enableIndexing = true;
|
bool enableIndexing = true;
|
||||||
bool autoIncludeHeaders = false;
|
bool autoIncludeHeaders = false;
|
||||||
int documentUpdateThreshold = 500;
|
bool sizeThresholdEnabled = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
ClangdSettings(const Data &data) : m_data(data) {}
|
ClangdSettings(const Data &data) : m_data(data) {}
|
||||||
@@ -139,6 +143,9 @@ public:
|
|||||||
bool autoIncludeHeaders() const { return m_data.autoIncludeHeaders; }
|
bool autoIncludeHeaders() const { return m_data.autoIncludeHeaders; }
|
||||||
int workerThreadLimit() const { return m_data.workerThreadLimit; }
|
int workerThreadLimit() const { return m_data.workerThreadLimit; }
|
||||||
int documentUpdateThreshold() const { return m_data.documentUpdateThreshold; }
|
int documentUpdateThreshold() const { return m_data.documentUpdateThreshold; }
|
||||||
|
qint64 sizeThresholdInKb() const { return m_data.sizeThresholdInKb; }
|
||||||
|
bool sizeThresholdEnabled() const { return m_data.sizeThresholdEnabled; }
|
||||||
|
bool sizeIsOkay(const Utils::FilePath &fp) const;
|
||||||
|
|
||||||
enum class Granularity { Project, Session };
|
enum class Granularity { Project, Session };
|
||||||
Granularity granularity() const;
|
Granularity granularity() const;
|
||||||
|
@@ -50,6 +50,8 @@
|
|||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QVersionNumber>
|
#include <QVersionNumber>
|
||||||
|
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
namespace CppEditor::Internal {
|
namespace CppEditor::Internal {
|
||||||
|
|
||||||
class CppCodeModelSettingsWidget final : public Core::IOptionsPageWidget
|
class CppCodeModelSettingsWidget final : public Core::IOptionsPageWidget
|
||||||
@@ -206,8 +208,10 @@ public:
|
|||||||
QCheckBox useClangdCheckBox;
|
QCheckBox useClangdCheckBox;
|
||||||
QCheckBox indexingCheckBox;
|
QCheckBox indexingCheckBox;
|
||||||
QCheckBox autoIncludeHeadersCheckBox;
|
QCheckBox autoIncludeHeadersCheckBox;
|
||||||
|
QCheckBox sizeThresholdCheckBox;
|
||||||
QSpinBox threadLimitSpinBox;
|
QSpinBox threadLimitSpinBox;
|
||||||
QSpinBox documentUpdateThreshold;
|
QSpinBox documentUpdateThreshold;
|
||||||
|
QSpinBox sizeThresholdSpinBox;
|
||||||
Utils::PathChooser clangdChooser;
|
Utils::PathChooser clangdChooser;
|
||||||
Utils::InfoLabel versionWarningLabel;
|
Utils::InfoLabel versionWarningLabel;
|
||||||
QGroupBox *sessionsGroupBox = nullptr;
|
QGroupBox *sessionsGroupBox = nullptr;
|
||||||
@@ -243,6 +247,15 @@ ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsD
|
|||||||
tr("Defines the amount of time Qt Creator waits before sending document changes to the "
|
tr("Defines the amount of time Qt Creator waits before sending document changes to the "
|
||||||
"server.\n"
|
"server.\n"
|
||||||
"If the document changes again while waiting, this timeout resets.\n"));
|
"If the document changes again while waiting, this timeout resets.\n"));
|
||||||
|
d->sizeThresholdCheckBox.setText(tr("Ignore files greater than"));
|
||||||
|
d->sizeThresholdCheckBox.setChecked(settings.sizeThresholdEnabled());
|
||||||
|
d->sizeThresholdSpinBox.setMinimum(1);
|
||||||
|
d->sizeThresholdSpinBox.setMaximum(std::numeric_limits<int>::max());
|
||||||
|
d->sizeThresholdSpinBox.setSuffix(" KB");
|
||||||
|
d->sizeThresholdSpinBox.setValue(settings.sizeThresholdInKb());
|
||||||
|
d->sizeThresholdSpinBox.setToolTip(tr(
|
||||||
|
"Files greater than this will not be opened as documents in clangd.\n"
|
||||||
|
"The built-in code model will handle highlighting, completion and so on."));
|
||||||
|
|
||||||
const auto layout = new QVBoxLayout(this);
|
const auto layout = new QVBoxLayout(this);
|
||||||
layout->setContentsMargins(0, 0, 0, 0);
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
@@ -265,6 +278,10 @@ ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsD
|
|||||||
documentUpdateThresholdLayout->addStretch(1);
|
documentUpdateThresholdLayout->addStretch(1);
|
||||||
const auto documentUpdateThresholdLabel = new QLabel(tr("Document update threshold:"));
|
const auto documentUpdateThresholdLabel = new QLabel(tr("Document update threshold:"));
|
||||||
formLayout->addRow(documentUpdateThresholdLabel, documentUpdateThresholdLayout);
|
formLayout->addRow(documentUpdateThresholdLabel, documentUpdateThresholdLayout);
|
||||||
|
const auto sizeThresholdLayout = new QHBoxLayout;
|
||||||
|
sizeThresholdLayout->addWidget(&d->sizeThresholdSpinBox);
|
||||||
|
sizeThresholdLayout->addStretch(1);
|
||||||
|
formLayout->addRow(&d->sizeThresholdCheckBox, sizeThresholdLayout);
|
||||||
layout->addLayout(formLayout);
|
layout->addLayout(formLayout);
|
||||||
|
|
||||||
if (!isForProject) {
|
if (!isForProject) {
|
||||||
@@ -381,6 +398,10 @@ ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsD
|
|||||||
this, &ClangdSettingsWidget::settingsDataChanged);
|
this, &ClangdSettingsWidget::settingsDataChanged);
|
||||||
connect(&d->threadLimitSpinBox, qOverload<int>(&QSpinBox::valueChanged),
|
connect(&d->threadLimitSpinBox, qOverload<int>(&QSpinBox::valueChanged),
|
||||||
this, &ClangdSettingsWidget::settingsDataChanged);
|
this, &ClangdSettingsWidget::settingsDataChanged);
|
||||||
|
connect(&d->sizeThresholdCheckBox, &QCheckBox::toggled,
|
||||||
|
this, &ClangdSettingsWidget::settingsDataChanged);
|
||||||
|
connect(&d->sizeThresholdSpinBox, qOverload<int>(&QSpinBox::valueChanged),
|
||||||
|
this, &ClangdSettingsWidget::settingsDataChanged);
|
||||||
connect(&d->clangdChooser, &Utils::PathChooser::pathChanged,
|
connect(&d->clangdChooser, &Utils::PathChooser::pathChanged,
|
||||||
this, &ClangdSettingsWidget::settingsDataChanged);
|
this, &ClangdSettingsWidget::settingsDataChanged);
|
||||||
}
|
}
|
||||||
@@ -399,6 +420,8 @@ ClangdSettings::Data ClangdSettingsWidget::settingsData() const
|
|||||||
data.autoIncludeHeaders = d->autoIncludeHeadersCheckBox.isChecked();
|
data.autoIncludeHeaders = d->autoIncludeHeadersCheckBox.isChecked();
|
||||||
data.workerThreadLimit = d->threadLimitSpinBox.value();
|
data.workerThreadLimit = d->threadLimitSpinBox.value();
|
||||||
data.documentUpdateThreshold = d->documentUpdateThreshold.value();
|
data.documentUpdateThreshold = d->documentUpdateThreshold.value();
|
||||||
|
data.sizeThresholdEnabled = d->sizeThresholdCheckBox.isChecked();
|
||||||
|
data.sizeThresholdInKb = d->sizeThresholdSpinBox.value();
|
||||||
data.sessionsWithOneClangd = d->sessionsModel.stringList();
|
data.sessionsWithOneClangd = d->sessionsModel.stringList();
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user