diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2022-05-16 16:40:29 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2022-05-17 08:56:32 +0000 |
commit | affa2cda9e2aa707526181f642148e101e81401f (patch) | |
tree | c9b6b344dc5b947ead7c99017aa251c12fabb847 /src | |
parent | a5dc6f84349aac245023c44ee0ec94e895569dab (diff) |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/clangcodemodel/clangdclient.cpp | 6 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppcodemodelsettings.cpp | 8 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppcodemodelsettings.h | 1 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppcodemodelsettingspage.cpp | 21 |
4 files changed, 32 insertions, 4 deletions
diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index 1b862a53b2..8dc641e3c4 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -88,7 +88,6 @@ #include <QPair> #include <QPointer> #include <QRegularExpression> -#include <QStandardPaths> #include <QVBoxLayout> #include <QWidget> #include <QtConcurrent> @@ -603,10 +602,9 @@ public: void setupClangdConfigFile() { - const Utils::FilePath baseDir = Utils::FilePath::fromString( - QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)) / "clangd"; + const Utils::FilePath targetConfigFile = CppEditor::ClangdSettings::clangdUserConfigFilePath(); + const Utils::FilePath baseDir = targetConfigFile.parentDir(); baseDir.ensureWritableDir(); - const Utils::FilePath targetConfigFile = baseDir / "config.yaml"; Utils::FileReader configReader; const QByteArray firstLine = "# This file was generated by Qt Creator and will be overwritten " "unless you remove this line."; diff --git a/src/plugins/cppeditor/cppcodemodelsettings.cpp b/src/plugins/cppeditor/cppcodemodelsettings.cpp index 66069f5759..f30469abfe 100644 --- a/src/plugins/cppeditor/cppcodemodelsettings.cpp +++ b/src/plugins/cppeditor/cppcodemodelsettings.cpp @@ -42,6 +42,7 @@ #include <QHash> #include <QPair> #include <QSettings> +#include <QStandardPaths> using namespace Utils; @@ -418,6 +419,13 @@ FilePath ClangdSettings::clangdIncludePath() const return includePath; } +FilePath ClangdSettings::clangdUserConfigFilePath() +{ + return FilePath::fromString( + QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)) + / "clangd/config.yaml"; +} + void ClangdSettings::loadSettings() { Utils::fromSettings(clangdSettingsKey(), {}, Core::ICore::settings(), &m_data); diff --git a/src/plugins/cppeditor/cppcodemodelsettings.h b/src/plugins/cppeditor/cppcodemodelsettings.h index 483b3d0100..1e0750d861 100644 --- a/src/plugins/cppeditor/cppcodemodelsettings.h +++ b/src/plugins/cppeditor/cppcodemodelsettings.h @@ -156,6 +156,7 @@ public: static QVersionNumber clangdVersion(const Utils::FilePath &clangdFilePath); QVersionNumber clangdVersion() const { return clangdVersion(clangdFilePath()); } Utils::FilePath clangdIncludePath() const; + static Utils::FilePath clangdUserConfigFilePath(); #ifdef WITH_TESTS static void setUseClangd(bool use); diff --git a/src/plugins/cppeditor/cppcodemodelsettingspage.cpp b/src/plugins/cppeditor/cppcodemodelsettingspage.cpp index 8ec443337b..390c50a367 100644 --- a/src/plugins/cppeditor/cppcodemodelsettingspage.cpp +++ b/src/plugins/cppeditor/cppcodemodelsettingspage.cpp @@ -39,6 +39,7 @@ #include <utils/pathchooser.h> #include <utils/qtcassert.h> +#include <QDesktopServices> #include <QFormLayout> #include <QGroupBox> #include <QHBoxLayout> @@ -341,6 +342,26 @@ ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsD // TODO: Remove once the concept is functional. 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); static const auto setWidgetsEnabled = [](QLayout *layout, bool enabled, const auto &f) -> void { |