aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorChristian Kandeler <[email protected]>2024-03-13 15:38:44 +0100
committerChristian Kandeler <[email protected]>2024-04-15 08:58:23 +0000
commit3b80da7117183235447ac2804c4e9c934fad89fa (patch)
treeaaf81633cf4152443b8f440523bb554731dedf29 /src/plugins
parentac4bf6901b2902789b13c0534426e9edfbb06f5a (diff)
ClangCodeModel: Make "live update" of dependent sources opt-in
Not everyone wants to invest the extra computing resources needed for this feature. Amends b33b99e2d9e4c343f7427bcf1ccdf652e7575557. See 6d805195f6d35df932d666f86af026c051c785f8 for the original motivation. Task-number: QTCREATORBUG-29943 Change-Id: I4c8cce5bb58b34d930a409ea3e0995377c90d4ab Reviewed-by: David Schulz <[email protected]> Reviewed-by: <[email protected]>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp9
-rw-r--r--src/plugins/clangcodemodel/test/clangdtests.cpp16
-rw-r--r--src/plugins/cppeditor/clangdsettings.cpp26
-rw-r--r--src/plugins/cppeditor/clangdsettings.h5
4 files changed, 51 insertions, 5 deletions
diff --git a/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp b/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp
index 83667dde05e..71ed49549df 100644
--- a/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp
+++ b/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp
@@ -18,6 +18,8 @@
#include <languageclient/languageclientmanager.h>
+#include <projectexplorer/projectmanager.h>
+
#include <texteditor/fontsettings.h>
#include <texteditor/texteditor.h>
#include <texteditor/texteditorconstants.h>
@@ -84,7 +86,12 @@ void ClangEditorDocumentProcessor::forceUpdate(TextEditor::TextDocument *doc)
{
if (const auto client = qobject_cast<ClangdClient *>(
LanguageClient::LanguageClientManager::clientForDocument(doc))) {
- client->documentContentsChanged(doc, 0, 0, 0);
+ const CppEditor::ClangdSettings settings(
+ CppEditor::ClangdProjectSettings(
+ ProjectExplorer::ProjectManager::projectForFile(doc->filePath()))
+ .settings());
+ if (settings.updateDependentSources())
+ client->documentContentsChanged(doc, 0, 0, 0);
}
}
diff --git a/src/plugins/clangcodemodel/test/clangdtests.cpp b/src/plugins/clangcodemodel/test/clangdtests.cpp
index ae92afb45ff..f18c1641559 100644
--- a/src/plugins/clangcodemodel/test/clangdtests.cpp
+++ b/src/plugins/clangcodemodel/test/clangdtests.cpp
@@ -2240,6 +2240,8 @@ public:
ClangdTestIndirectChanges();
private slots:
+ void initTestCase() override;
+ void cleanupTestCase();
void test();
};
@@ -2249,6 +2251,20 @@ ClangdTestIndirectChanges::ClangdTestIndirectChanges()
setSourceFileNames({"main.cpp", "directheader.h", "indirectheader.h", "unrelatedheader.h"});
}
+void ClangdTestIndirectChanges::initTestCase()
+{
+ CppEditor::ClangdSettings &settings = CppEditor::ClangdSettings::instance();
+ CppEditor::ClangdSettings::Data settingsData = settings.data();
+ settingsData.updateDependentSources = true;
+ settings.setData(settingsData, false);
+ ClangdTest::initTestCase();
+}
+
+void ClangdTestIndirectChanges::cleanupTestCase()
+{
+ CppEditor::ClangdSettings::instance().setData({}, false);
+}
+
void ClangdTestIndirectChanges::test()
{
// Initially, everything is fine.
diff --git a/src/plugins/cppeditor/clangdsettings.cpp b/src/plugins/cppeditor/clangdsettings.cpp
index 253914704a0..fe3bc84b23b 100644
--- a/src/plugins/cppeditor/clangdsettings.cpp
+++ b/src/plugins/cppeditor/clangdsettings.cpp
@@ -73,6 +73,7 @@ static Key sessionsWithOneClangdKey() { return "SessionsWithOneClangd"; }
static Key diagnosticConfigIdKey() { return "diagnosticConfigId"; }
static Key checkedHardwareKey() { return "checkedHardware"; }
static Key completionResultsKey() { return "completionResults"; }
+static Key updateDependentSourcesKey() { return "updateDependentSources"; }
QString ClangdSettings::priorityToString(const IndexingPriority &priority)
{
@@ -245,12 +246,14 @@ ClangdSettings::Granularity ClangdSettings::granularity() const
return Granularity::Project;
}
-void ClangdSettings::setData(const Data &data)
+void ClangdSettings::setData(const Data &data, bool saveAndEmitSignal)
{
if (this == &instance() && data != m_data) {
m_data = data;
- saveSettings();
- emit changed();
+ if (saveAndEmitSignal) {
+ saveSettings();
+ emit changed();
+ }
}
}
@@ -470,6 +473,7 @@ Store ClangdSettings::Data::toMap() const
map.insert(diagnosticConfigIdKey(), diagnosticConfigId.toSetting());
map.insert(checkedHardwareKey(), haveCheckedHardwareReqirements);
map.insert(completionResultsKey(), completionResults);
+ map.insert(updateDependentSourcesKey(), updateDependentSources);
return map;
}
@@ -499,6 +503,7 @@ void ClangdSettings::Data::fromMap(const Store &map)
diagnosticConfigId = Id::fromSetting(map.value(diagnosticConfigIdKey(),
initialClangDiagnosticConfigId().toSetting()));
haveCheckedHardwareReqirements = map.value(checkedHardwareKey(), false).toBool();
+ updateDependentSources = map.value(updateDependentSourcesKey(), false).toBool();
completionResults = map.value(completionResultsKey(), defaultCompletionResults()).toInt();
}
@@ -531,6 +536,7 @@ private:
QComboBox m_headerSourceSwitchComboBox;
QComboBox m_completionRankingModelComboBox;
QCheckBox m_autoIncludeHeadersCheckBox;
+ QCheckBox m_updateDependentSourcesCheckBox;
QCheckBox m_sizeThresholdCheckBox;
QSpinBox m_threadLimitSpinBox;
QSpinBox m_documentUpdateThreshold;
@@ -584,6 +590,13 @@ ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsD
"worker threads.");
const QString autoIncludeToolTip = Tr::tr(
"Controls whether clangd may insert header files as part of symbol completion.");
+ const QString updateDependentSourcesToolTip = Tr::tr(
+ "<p>Controls whether when editing a header file, clangd should re-parse all source files "
+ "including that header.</p>"
+ "<p>Note that enabling this option can cause considerable CPU load when editing widely "
+ "included headers.</p>"
+ "<p>If this option is disabled, the dependent source files are only re-parsed when the "
+ "header file is saved.</p>");
const QString documentUpdateToolTip
//: %1 is the application name (Qt Creator)
= Tr::tr("Defines the amount of time %1 waits before sending document changes to the "
@@ -634,6 +647,9 @@ ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsD
m_autoIncludeHeadersCheckBox.setText(Tr::tr("Insert header files on completion"));
m_autoIncludeHeadersCheckBox.setChecked(settings.autoIncludeHeaders());
m_autoIncludeHeadersCheckBox.setToolTip(autoIncludeToolTip);
+ m_updateDependentSourcesCheckBox.setText(Tr::tr("Update dependent sources"));
+ m_updateDependentSourcesCheckBox.setChecked(settings.updateDependentSources());
+ m_updateDependentSourcesCheckBox.setToolTip(updateDependentSourcesToolTip);
m_threadLimitSpinBox.setValue(settings.workerThreadLimit());
m_threadLimitSpinBox.setSpecialValueText(Tr::tr("Automatic"));
m_threadLimitSpinBox.setToolTip(workerThreadsToolTip);
@@ -718,6 +734,7 @@ ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsD
formLayout->addRow(threadLimitLabel, threadLimitLayout);
formLayout->addRow(QString(), &m_autoIncludeHeadersCheckBox);
+ formLayout->addRow(QString(), &m_updateDependentSourcesCheckBox);
const auto limitResultsLayout = new QHBoxLayout;
limitResultsLayout->addWidget(&m_completionResults);
limitResultsLayout->addStretch(1);
@@ -883,6 +900,8 @@ ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsD
this, &ClangdSettingsWidget::settingsDataChanged);
connect(&m_autoIncludeHeadersCheckBox, &QCheckBox::toggled,
this, &ClangdSettingsWidget::settingsDataChanged);
+ connect(&m_updateDependentSourcesCheckBox, &QCheckBox::toggled,
+ this, &ClangdSettingsWidget::settingsDataChanged);
connect(&m_threadLimitSpinBox, &QSpinBox::valueChanged,
this, &ClangdSettingsWidget::settingsDataChanged);
connect(&m_sizeThresholdCheckBox, &QCheckBox::toggled,
@@ -913,6 +932,7 @@ ClangdSettings::Data ClangdSettingsWidget::settingsData() const
data.completionRankingModel = ClangdSettings::CompletionRankingModel(
m_completionRankingModelComboBox.currentData().toInt());
data.autoIncludeHeaders = m_autoIncludeHeadersCheckBox.isChecked();
+ data.updateDependentSources = m_updateDependentSourcesCheckBox.isChecked();
data.workerThreadLimit = m_threadLimitSpinBox.value();
data.documentUpdateThreshold = m_documentUpdateThreshold.value();
data.sizeThresholdEnabled = m_sizeThresholdCheckBox.isChecked();
diff --git a/src/plugins/cppeditor/clangdsettings.h b/src/plugins/cppeditor/clangdsettings.h
index f3e66fb9f6b..e4fb22f5527 100644
--- a/src/plugins/cppeditor/clangdsettings.h
+++ b/src/plugins/cppeditor/clangdsettings.h
@@ -55,6 +55,7 @@ public:
&& s1.sizeThresholdEnabled == s2.sizeThresholdEnabled
&& s1.sizeThresholdInKb == s2.sizeThresholdInKb
&& s1.haveCheckedHardwareReqirements == s2.haveCheckedHardwareReqirements
+ && s1.updateDependentSources == s2.updateDependentSources
&& s1.completionResults == s2.completionResults;
}
friend bool operator!=(const Data &s1, const Data &s2) { return !(s1 == s2); }
@@ -76,6 +77,7 @@ public:
bool autoIncludeHeaders = false;
bool sizeThresholdEnabled = false;
bool haveCheckedHardwareReqirements = false;
+ bool updateDependentSources = false;
int completionResults = defaultCompletionResults();
private:
@@ -101,6 +103,7 @@ public:
HeaderSourceSwitchMode headerSourceSwitchMode() const { return m_data.headerSourceSwitchMode; }
CompletionRankingModel completionRankingModel() const { return m_data.completionRankingModel; }
bool autoIncludeHeaders() const { return m_data.autoIncludeHeaders; }
+ bool updateDependentSources() const { return m_data.updateDependentSources; }
int workerThreadLimit() const { return m_data.workerThreadLimit; }
int documentUpdateThreshold() const { return m_data.documentUpdateThreshold; }
qint64 sizeThresholdInKb() const { return m_data.sizeThresholdInKb; }
@@ -114,7 +117,7 @@ public:
enum class Granularity { Project, Session };
Granularity granularity() const;
- void setData(const Data &data);
+ void setData(const Data &data, bool saveAndEmitSignal = true);
Data data() const { return m_data; }
Utils::FilePath clangdIncludePath() const;