From b739b91cd3a46c61f91a98c44cac8c9594e7094e Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Mon, 1 Jul 2019 08:05:53 +0000 Subject: [PATCH] [clangd] Make FixIt message be consistent with the clang-tidy diagnostic message. Summary: We strip the "[clang-tidy-check]" suffix from the clang-tidy diagnostics, we should be consistent with the message in FixIt (strip the suffix as well). Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63926 llvm-svn: 364731 --- clang-tools-extra/clangd/Diagnostics.cpp | 2 ++ .../clangd/unittests/DiagnosticsTests.cpp | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp index 5263a33..0bc3bae 100644 --- a/clang-tools-extra/clangd/Diagnostics.cpp +++ b/clang-tools-extra/clangd/Diagnostics.cpp @@ -418,6 +418,8 @@ std::vector StoreDiags::take(const clang::tidy::ClangTidyContext *Tidy) { CleanMessage(Diag.Message); for (auto &Note : Diag.Notes) CleanMessage(Note.Message); + for (auto &Fix : Diag.Fixes) + CleanMessage(Fix.Message); continue; } } diff --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp index 00e77f7..939cd5e 100644 --- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp +++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp @@ -60,6 +60,10 @@ MATCHER_P3(Fix, Range, Replacement, Message, arg.Edits[0].range == Range && arg.Edits[0].newText == Replacement; } +MATCHER_P(FixMessage, Message, "") { + return arg.Message == Message; +} + MATCHER_P(EqualToLSPDiag, LSPDiag, "LSP diagnostic " + llvm::to_string(LSPDiag)) { if (toJSON(arg) != toJSON(LSPDiag)) { @@ -180,19 +184,17 @@ TEST(DiagnosticsTest, ClangTidy) { #include $deprecated[["assert.h"]] #define $macrodef[[SQUARE]](X) (X)*(X) - int main() { - return $doubled[[sizeof]](sizeof(int)); - } - int square() { + int $main[[main]]() { int y = 4; return SQUARE($macroarg[[++]]y); + return $doubled[[sizeof]](sizeof(int)); } )cpp"); auto TU = TestTU::withCode(Test.code()); TU.HeaderFilename = "assert.h"; // Suppress "not found" error. TU.ClangTidyChecks = "-*, bugprone-sizeof-expression, bugprone-macro-repeated-side-effects, " - "modernize-deprecated-headers"; + "modernize-deprecated-headers, modernize-use-trailing-return-type"; EXPECT_THAT( TU.build().getDiagnostics(), UnorderedElementsAre( @@ -214,7 +216,15 @@ TEST(DiagnosticsTest, ClangTidy) { WithNote( Diag(Test.range("macrodef"), "macro 'SQUARE' defined here"))), Diag(Test.range("macroarg"), - "multiple unsequenced modifications to 'y'"))); + "multiple unsequenced modifications to 'y'"), + AllOf( + Diag(Test.range("main"), + "use a trailing return type for this function"), + DiagSource(Diag::ClangTidy), + DiagName("modernize-use-trailing-return-type"), + // Verify that we don't have "[check-name]" suffix in the message. + WithFix(FixMessage("use a trailing return type for this function"))) + )); } TEST(DiagnosticTest, ClangTidySuppressionComment) { -- 2.7.4