[PATCH] D63926: [clangd] Make FixIt message be consistent with the clang-tidy diagnostic message.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 28 04:59:14 PDT 2019


hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.

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).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63926

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -60,6 +60,10 @@
          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 @@
     #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 @@
               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) {
Index: clang-tools-extra/clangd/Diagnostics.cpp
===================================================================
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -418,6 +418,8 @@
         CleanMessage(Diag.Message);
         for (auto &Note : Diag.Notes)
           CleanMessage(Note.Message);
+        for (auto &Fix : Diag.Fixes)
+          CleanMessage(Fix.Message);
         continue;
       }
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63926.207038.patch
Type: text/x-patch
Size: 2532 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190628/81eae7df/attachment.bin>


More information about the cfe-commits mailing list