summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHaojian Wu <hokein@google.com>2019-07-01 08:05:53 +0000
committerHaojian Wu <hokein@google.com>2019-07-01 08:05:53 +0000
commitb739b91cd3a46c61f91a98c44cac8c9594e7094e (patch)
treec8911df522d589fd8f40f97ec672c5f14bb6c104
parentfcda45a9eb88b2bd0500c71554f560700f59dedd (diff)
downloadbcm5719-llvm-b739b91cd3a46c61f91a98c44cac8c9594e7094e.tar.gz
bcm5719-llvm-b739b91cd3a46c61f91a98c44cac8c9594e7094e.zip
[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
-rw-r--r--clang-tools-extra/clangd/Diagnostics.cpp2
-rw-r--r--clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp22
2 files changed, 18 insertions, 6 deletions
diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp
index 5263a33c857..0bc3bae3d96 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -418,6 +418,8 @@ std::vector<Diag> 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 00e77f79963..939cd5e8e5e 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) {
OpenPOWER on IntegriCloud