Author: sammccall Date: Wed Apr 17 13:15:08 2019 New Revision: 358612 URL: http://llvm.org/viewvc/llvm-project?rev=358612&view=rev Log: [clangd] Strip the ' [some-check-name]' suffix from clang-tidy diagnostics. The check name is reported in Diagnostic.code.
Reviewers: kadircet Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60819 Modified: clang-tools-extra/trunk/clangd/Diagnostics.cpp clang-tools-extra/trunk/test/clangd/diagnostics.test clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp Modified: clang-tools-extra/trunk/clangd/Diagnostics.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Diagnostics.cpp?rev=358612&r1=358611&r2=358612&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/Diagnostics.cpp (original) +++ clang-tools-extra/trunk/clangd/Diagnostics.cpp Wed Apr 17 13:15:08 2019 @@ -350,6 +350,17 @@ std::vector<Diag> StoreDiags::take(const if (!TidyDiag.empty()) { Diag.Name = std::move(TidyDiag); Diag.Source = Diag::ClangTidy; + // clang-tidy bakes the name into diagnostic messages. Strip it out. + // It would be much nicer to make clang-tidy not do this. + auto CleanMessage = [&](std::string &Msg) { + StringRef Rest(Msg); + if (Rest.consume_back("]") && Rest.consume_back(Diag.Name) && + Rest.consume_back(" [")) + Msg.resize(Rest.size()); + }; + CleanMessage(Diag.Message); + for (auto& Note : Diag.Notes) + CleanMessage(Note.Message); continue; } } Modified: clang-tools-extra/trunk/test/clangd/diagnostics.test URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/diagnostics.test?rev=358612&r1=358611&r2=358612&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clangd/diagnostics.test (original) +++ clang-tools-extra/trunk/test/clangd/diagnostics.test Wed Apr 17 13:15:08 2019 @@ -23,7 +23,7 @@ # CHECK-NEXT: }, # CHECK-NEXT: { # CHECK-NEXT: "code": "bugprone-sizeof-expression", -# CHECK-NEXT: "message": "Suspicious usage of 'sizeof(K)'; did you mean 'K'? [bugprone-sizeof-expression]", +# CHECK-NEXT: "message": "Suspicious usage of 'sizeof(K)'; did you mean 'K'?", # CHECK-NEXT: "range": { # CHECK-NEXT: "end": { # CHECK-NEXT: "character": 12, Modified: clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp?rev=358612&r1=358611&r2=358612&view=diff ============================================================================== --- clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp Wed Apr 17 13:15:08 2019 @@ -176,23 +176,21 @@ TEST(DiagnosticsTest, ClangTidy) { UnorderedElementsAre( AllOf(Diag(Test.range("deprecated"), "inclusion of deprecated C++ header 'assert.h'; consider " - "using 'cassert' instead [modernize-deprecated-headers]"), + "using 'cassert' instead"), DiagSource(Diag::ClangTidy), DiagName("modernize-deprecated-headers"), WithFix(Fix(Test.range("deprecated"), "<cassert>", "change '\"assert.h\"' to '<cassert>'"))), Diag(Test.range("doubled"), - "suspicious usage of 'sizeof(sizeof(...))' " - "[bugprone-sizeof-expression]"), + "suspicious usage of 'sizeof(sizeof(...))'"), AllOf( Diag(Test.range("macroarg"), "side effects in the 1st macro argument 'X' are repeated in " - "macro expansion [bugprone-macro-repeated-side-effects]"), + "macro expansion"), DiagSource(Diag::ClangTidy), DiagName("bugprone-macro-repeated-side-effects"), - WithNote(Diag(Test.range("macrodef"), - "macro 'SQUARE' defined here " - "[bugprone-macro-repeated-side-effects]"))), + WithNote( + Diag(Test.range("macrodef"), "macro 'SQUARE' defined here"))), Diag(Test.range("macroarg"), "multiple unsequenced modifications to 'y'"))); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits