From a7fcb71b90be3bff1bcaccffe23ed5dc9a4a50d0 Mon Sep 17 00:00:00 2001 From: Artem Sokolovskii Date: Fri, 4 Aug 2023 14:06:39 +0200 Subject: [PATCH] ClangFormat: Add warning for clangformat version Added warning when current clangformat major version does not match with version what checks was generated for. Change-Id: I818c9a4f79385cba4e492ea5428bb051f329a9d4 Reviewed-by: Reviewed-by: Christian Kandeler --- .../clangformat/clangformatconfigwidget.cpp | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/plugins/clangformat/clangformatconfigwidget.cpp b/src/plugins/clangformat/clangformatconfigwidget.cpp index 26abaab009a..e736570058c 100644 --- a/src/plugins/clangformat/clangformatconfigwidget.cpp +++ b/src/plugins/clangformat/clangformatconfigwidget.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -39,9 +40,11 @@ #include #include #include +#include #include #include +#include #include #include @@ -62,6 +65,9 @@ public: clang::format::FormatStyle style; Utils::Guard ignoreChanges; QLabel *fallbackConfig; + QLabel *clangVersion; + QLabel *clangWarningText; + QLabel *clangWarningIcon; }; bool ClangFormatConfigWidget::eventFilter(QObject *object, QEvent *event) @@ -90,6 +96,28 @@ ClangFormatConfigWidget::ClangFormatConfigWidget(TextEditor::ICodeStylePreferenc d->checksWidget->setEnabled(!codeStyle->isReadOnly() && !codeStyle->isTemporarilyReadOnly() && !codeStyle->isAdditionalTabDisabled()); + + static const int expectedMajorVersion = 16; + d->clangVersion = new QLabel(Tr::tr("Current clang-format version: ") + LLVM_VERSION_STRING, + this); + d->clangWarningText + = new QLabel(Tr::tr("The widget was generated for ClangFormat %1. " + "If you use a different version, the widget may work incorrectly.") + .arg(expectedMajorVersion), + this); + + QPalette palette = d->clangWarningText->palette(); + palette.setColor(QPalette::WindowText, Qt::red); + d->clangWarningText->setPalette(palette); + + d->clangWarningIcon = new QLabel(this); + d->clangWarningIcon->setPixmap(Utils::Icons::WARNING.icon().pixmap(16, 16)); + + if (LLVM_VERSION_MAJOR == expectedMajorVersion) { + d->clangWarningText->hide(); + d->clangWarningIcon->hide(); + } + FilePath fileName; if (d->project) fileName = d->project->projectFilePath().pathAppended("snippet.cpp"); @@ -110,6 +138,8 @@ ClangFormatConfigWidget::ClangFormatConfigWidget(TextEditor::ICodeStylePreferenc Column { d->fallbackConfig, + Row {d->clangWarningIcon, d->clangWarningText, st}, + d->clangVersion, Row { d->checksScrollArea, d->preview }, }.attachTo(this);