From 0a2b5046639bd3d3c318a7f1c9e8ac64bc3cfc76 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Thu, 7 Oct 2021 16:15:08 +0200 Subject: CppEditor: Add warning label to clangd settings page So people with older installations know right away that they can't expect full functionality. Change-Id: I8cceb2c88ba1622fa37fb88fc0b96253b6c13a06 Reviewed-by: David Schulz --- src/plugins/cppeditor/cppcodemodelsettingspage.cpp | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/plugins/cppeditor/cppcodemodelsettingspage.cpp b/src/plugins/cppeditor/cppcodemodelsettingspage.cpp index 2c775e3843..1c6621e070 100644 --- a/src/plugins/cppeditor/cppcodemodelsettingspage.cpp +++ b/src/plugins/cppeditor/cppcodemodelsettingspage.cpp @@ -33,11 +33,14 @@ #include #include +#include #include +#include #include #include #include +#include namespace CppEditor::Internal { @@ -197,6 +200,7 @@ public: QSpinBox threadLimitSpinBox; QSpinBox documentUpdateThreshold; Utils::PathChooser clangdChooser; + Utils::InfoLabel versionWarningLabel; }; ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsData) @@ -230,6 +234,7 @@ ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsD const auto formLayout = new QFormLayout; const auto chooserLabel = new QLabel(tr("Path to executable:")); formLayout->addRow(chooserLabel, &d->clangdChooser); + formLayout->addRow(QString(), &d->versionWarningLabel); const auto indexingLabel = new QLabel(tr("Enable background indexing:")); formLayout->addRow(indexingLabel, &d->indexingCheckBox); const auto threadLimitLayout = new QHBoxLayout; @@ -251,11 +256,58 @@ ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsD indexingLabel->setEnabled(checked); d->indexingCheckBox.setEnabled(checked); d->threadLimitSpinBox.setEnabled(checked); + d->versionWarningLabel.setEnabled(checked); }; connect(&d->useClangdCheckBox, &QCheckBox::toggled, toggleEnabled); toggleEnabled(d->useClangdCheckBox.isChecked()); d->threadLimitSpinBox.setEnabled(d->useClangdCheckBox.isChecked()); + d->versionWarningLabel.setType(Utils::InfoLabel::Warning); + const auto updateWarningLabel = [this] { + class WarningLabelSetter { + public: + WarningLabelSetter(QLabel &label) : m_label(label) { m_label.clear(); } + ~WarningLabelSetter() { m_label.setVisible(!m_label.text().isEmpty()); } + void setWarning(const QString &text) { m_label.setText(text); } + private: + QLabel &m_label; + }; + WarningLabelSetter labelSetter(d->versionWarningLabel); + + if (!d->clangdChooser.isValid()) + return; + const Utils::FilePath clangdPath = d->clangdChooser.filePath(); + Utils::QtcProcess clangdProc; + clangdProc.setCommand({clangdPath, {"--version"}}); + clangdProc.start(); + if (!clangdProc.waitForStarted() || !clangdProc.waitForFinished()) { + labelSetter.setWarning(tr("Failed to retrieve clangd version: %1") + .arg(clangdProc.exitMessage())); + return; + } + const QString output = clangdProc.allOutput(); + static const QString versionPrefix = "clangd version "; + const int prefixOffset = output.indexOf(versionPrefix); + QVersionNumber clangdVersion; + if (prefixOffset != -1) { + clangdVersion = QVersionNumber::fromString(output.mid(prefixOffset + + versionPrefix.length())); + } + if (clangdVersion.isNull()) { + labelSetter.setWarning(tr("Failed to retrieve clangd version: " + "Unexpected clangd output.")); + return; + } + if (clangdVersion < QVersionNumber(13)) { + labelSetter.setWarning(tr("The clangd version is %1, but %2 or greater is " + "recommended for full functionality.") + .arg(clangdVersion.toString()).arg(13)); + return; + } + }; + connect(&d->clangdChooser, &Utils::PathChooser::pathChanged, this, updateWarningLabel); + updateWarningLabel(); + connect(&d->useClangdCheckBox, &QCheckBox::toggled, this, &ClangdSettingsWidget::settingsDataChanged); connect(&d->indexingCheckBox, &QCheckBox::toggled, -- cgit v1.2.1