CppEditor: Tell users about clangd configuration files

It's not feasible to map every possible setting into our UI, so instead
teach people how to use the clangd configuration mechanism.

Change-Id: Id11e81e25b687a4f49af4e090203faca3a75722d
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2022-05-16 16:40:29 +02:00
parent a5dc6f8434
commit affa2cda9e
4 changed files with 32 additions and 4 deletions

View File

@@ -88,7 +88,6 @@
#include <QPair> #include <QPair>
#include <QPointer> #include <QPointer>
#include <QRegularExpression> #include <QRegularExpression>
#include <QStandardPaths>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QWidget> #include <QWidget>
#include <QtConcurrent> #include <QtConcurrent>
@@ -603,10 +602,9 @@ public:
void setupClangdConfigFile() void setupClangdConfigFile()
{ {
const Utils::FilePath baseDir = Utils::FilePath::fromString( const Utils::FilePath targetConfigFile = CppEditor::ClangdSettings::clangdUserConfigFilePath();
QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)) / "clangd"; const Utils::FilePath baseDir = targetConfigFile.parentDir();
baseDir.ensureWritableDir(); baseDir.ensureWritableDir();
const Utils::FilePath targetConfigFile = baseDir / "config.yaml";
Utils::FileReader configReader; Utils::FileReader configReader;
const QByteArray firstLine = "# This file was generated by Qt Creator and will be overwritten " const QByteArray firstLine = "# This file was generated by Qt Creator and will be overwritten "
"unless you remove this line."; "unless you remove this line.";

View File

@@ -42,6 +42,7 @@
#include <QHash> #include <QHash>
#include <QPair> #include <QPair>
#include <QSettings> #include <QSettings>
#include <QStandardPaths>
using namespace Utils; using namespace Utils;
@@ -418,6 +419,13 @@ FilePath ClangdSettings::clangdIncludePath() const
return includePath; return includePath;
} }
FilePath ClangdSettings::clangdUserConfigFilePath()
{
return FilePath::fromString(
QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation))
/ "clangd/config.yaml";
}
void ClangdSettings::loadSettings() void ClangdSettings::loadSettings()
{ {
Utils::fromSettings(clangdSettingsKey(), {}, Core::ICore::settings(), &m_data); Utils::fromSettings(clangdSettingsKey(), {}, Core::ICore::settings(), &m_data);

View File

@@ -156,6 +156,7 @@ public:
static QVersionNumber clangdVersion(const Utils::FilePath &clangdFilePath); static QVersionNumber clangdVersion(const Utils::FilePath &clangdFilePath);
QVersionNumber clangdVersion() const { return clangdVersion(clangdFilePath()); } QVersionNumber clangdVersion() const { return clangdVersion(clangdFilePath()); }
Utils::FilePath clangdIncludePath() const; Utils::FilePath clangdIncludePath() const;
static Utils::FilePath clangdUserConfigFilePath();
#ifdef WITH_TESTS #ifdef WITH_TESTS
static void setUseClangd(bool use); static void setUseClangd(bool use);

View File

@@ -39,6 +39,7 @@
#include <utils/pathchooser.h> #include <utils/pathchooser.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QDesktopServices>
#include <QFormLayout> #include <QFormLayout>
#include <QGroupBox> #include <QGroupBox>
#include <QHBoxLayout> #include <QHBoxLayout>
@@ -341,6 +342,26 @@ ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsD
// TODO: Remove once the concept is functional. // TODO: Remove once the concept is functional.
d->sessionsGroupBox->hide(); d->sessionsGroupBox->hide();
} }
const auto configFilesHelpLabel = new QLabel;
configFilesHelpLabel->setText(tr("Additional settings are available via "
"<a href=\"https://clangd.llvm.org/config\"> clangd configuration files</a>.<br>"
"General settings go <a href=\"%1\">here</a> "
"and can be overridden per project by putting a .clangd file into "
"the project source tree.")
.arg(ClangdSettings::clangdUserConfigFilePath().toUserOutput()));
connect(configFilesHelpLabel, &QLabel::linkHovered, configFilesHelpLabel, &QLabel::setToolTip);
connect(configFilesHelpLabel, &QLabel::linkActivated, [](const QString &link) {
if (link.startsWith("https"))
QDesktopServices::openUrl(link);
else
Core::EditorManager::openEditor(Utils::FilePath::fromString(link));
});
const auto separator = new QFrame;
separator->setFrameShape(QFrame::HLine);
layout->addWidget(separator);
layout->addWidget(configFilesHelpLabel);
layout->addStretch(1); layout->addStretch(1);
static const auto setWidgetsEnabled = [](QLayout *layout, bool enabled, const auto &f) -> void { static const auto setWidgetsEnabled = [](QLayout *layout, bool enabled, const auto &f) -> void {