Skip to content

Commit b739b91

Browse files
committed
[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
1 parent fcda45a commit b739b91

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

clang-tools-extra/clangd/Diagnostics.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ std::vector<Diag> StoreDiags::take(const clang::tidy::ClangTidyContext *Tidy) {
418418
CleanMessage(Diag.Message);
419419
for (auto &Note : Diag.Notes)
420420
CleanMessage(Note.Message);
421+
for (auto &Fix : Diag.Fixes)
422+
CleanMessage(Fix.Message);
421423
continue;
422424
}
423425
}

clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ MATCHER_P3(Fix, Range, Replacement, Message,
6060
arg.Edits[0].range == Range && arg.Edits[0].newText == Replacement;
6161
}
6262

63+
MATCHER_P(FixMessage, Message, "") {
64+
return arg.Message == Message;
65+
}
66+
6367
MATCHER_P(EqualToLSPDiag, LSPDiag,
6468
"LSP diagnostic " + llvm::to_string(LSPDiag)) {
6569
if (toJSON(arg) != toJSON(LSPDiag)) {
@@ -180,19 +184,17 @@ TEST(DiagnosticsTest, ClangTidy) {
180184
#include $deprecated[["assert.h"]]
181185
182186
#define $macrodef[[SQUARE]](X) (X)*(X)
183-
int main() {
184-
return $doubled[[sizeof]](sizeof(int));
185-
}
186-
int square() {
187+
int $main[[main]]() {
187188
int y = 4;
188189
return SQUARE($macroarg[[++]]y);
190+
return $doubled[[sizeof]](sizeof(int));
189191
}
190192
)cpp");
191193
auto TU = TestTU::withCode(Test.code());
192194
TU.HeaderFilename = "assert.h"; // Suppress "not found" error.
193195
TU.ClangTidyChecks =
194196
"-*, bugprone-sizeof-expression, bugprone-macro-repeated-side-effects, "
195-
"modernize-deprecated-headers";
197+
"modernize-deprecated-headers, modernize-use-trailing-return-type";
196198
EXPECT_THAT(
197199
TU.build().getDiagnostics(),
198200
UnorderedElementsAre(
@@ -214,7 +216,15 @@ TEST(DiagnosticsTest, ClangTidy) {
214216
WithNote(
215217
Diag(Test.range("macrodef"), "macro 'SQUARE' defined here"))),
216218
Diag(Test.range("macroarg"),
217-
"multiple unsequenced modifications to 'y'")));
219+
"multiple unsequenced modifications to 'y'"),
220+
AllOf(
221+
Diag(Test.range("main"),
222+
"use a trailing return type for this function"),
223+
DiagSource(Diag::ClangTidy),
224+
DiagName("modernize-use-trailing-return-type"),
225+
// Verify that we don't have "[check-name]" suffix in the message.
226+
WithFix(FixMessage("use a trailing return type for this function")))
227+
));
218228
}
219229

220230
TEST(DiagnosticTest, ClangTidySuppressionComment) {

0 commit comments

Comments
 (0)