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 <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2021-10-07 16:15:08 +02:00
parent a40b7867f6
commit 0a2b504663

View File

@@ -33,11 +33,14 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/infolabel.h>
#include <utils/pathchooser.h> #include <utils/pathchooser.h>
#include <utils/qtcprocess.h>
#include <QFormLayout> #include <QFormLayout>
#include <QSpinBox> #include <QSpinBox>
#include <QTextStream> #include <QTextStream>
#include <QVersionNumber>
namespace CppEditor::Internal { namespace CppEditor::Internal {
@@ -197,6 +200,7 @@ public:
QSpinBox threadLimitSpinBox; QSpinBox threadLimitSpinBox;
QSpinBox documentUpdateThreshold; QSpinBox documentUpdateThreshold;
Utils::PathChooser clangdChooser; Utils::PathChooser clangdChooser;
Utils::InfoLabel versionWarningLabel;
}; };
ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsData) ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsData)
@@ -230,6 +234,7 @@ ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsD
const auto formLayout = new QFormLayout; const auto formLayout = new QFormLayout;
const auto chooserLabel = new QLabel(tr("Path to executable:")); const auto chooserLabel = new QLabel(tr("Path to executable:"));
formLayout->addRow(chooserLabel, &d->clangdChooser); formLayout->addRow(chooserLabel, &d->clangdChooser);
formLayout->addRow(QString(), &d->versionWarningLabel);
const auto indexingLabel = new QLabel(tr("Enable background indexing:")); const auto indexingLabel = new QLabel(tr("Enable background indexing:"));
formLayout->addRow(indexingLabel, &d->indexingCheckBox); formLayout->addRow(indexingLabel, &d->indexingCheckBox);
const auto threadLimitLayout = new QHBoxLayout; const auto threadLimitLayout = new QHBoxLayout;
@@ -251,11 +256,58 @@ ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsD
indexingLabel->setEnabled(checked); indexingLabel->setEnabled(checked);
d->indexingCheckBox.setEnabled(checked); d->indexingCheckBox.setEnabled(checked);
d->threadLimitSpinBox.setEnabled(checked); d->threadLimitSpinBox.setEnabled(checked);
d->versionWarningLabel.setEnabled(checked);
}; };
connect(&d->useClangdCheckBox, &QCheckBox::toggled, toggleEnabled); connect(&d->useClangdCheckBox, &QCheckBox::toggled, toggleEnabled);
toggleEnabled(d->useClangdCheckBox.isChecked()); toggleEnabled(d->useClangdCheckBox.isChecked());
d->threadLimitSpinBox.setEnabled(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, connect(&d->useClangdCheckBox, &QCheckBox::toggled,
this, &ClangdSettingsWidget::settingsDataChanged); this, &ClangdSettingsWidget::settingsDataChanged);
connect(&d->indexingCheckBox, &QCheckBox::toggled, connect(&d->indexingCheckBox, &QCheckBox::toggled,