Author: ioeric Date: Thu Jan 31 08:09:25 2019 New Revision: 352764 URL: http://llvm.org/viewvc/llvm-project?rev=352764&view=rev Log: [clangd] Append "(fix available)" to diagnostic message when fixes are present.
Summary: This would make diagnostic fixits more discoverable, especially for plugins like YCM. Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D57509 Modified: clang-tools-extra/trunk/clangd/Diagnostics.cpp clang-tools-extra/trunk/test/clangd/diagnostic-category.test clang-tools-extra/trunk/test/clangd/diagnostics.test clang-tools-extra/trunk/test/clangd/did-change-configuration-params.test clang-tools-extra/trunk/test/clangd/execute-command.test clang-tools-extra/trunk/test/clangd/fixits-codeaction.test clang-tools-extra/trunk/test/clangd/fixits-command.test clang-tools-extra/trunk/test/clangd/fixits-embed-in-diagnostic.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=352764&r1=352763&r2=352764&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/Diagnostics.cpp (original) +++ clang-tools-extra/trunk/clangd/Diagnostics.cpp Thu Jan 31 08:09:25 2019 @@ -165,6 +165,8 @@ std::string mainMessage(const Diag &D) { std::string Result; llvm::raw_string_ostream OS(Result); OS << D.Message; + if (!D.Fixes.empty()) + OS << " (" << (D.Fixes.size() > 1 ? "fixes" : "fix") << " available)"; for (auto &Note : D.Notes) { OS << "\n\n"; printDiag(OS, Note); Modified: clang-tools-extra/trunk/test/clangd/diagnostic-category.test URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/diagnostic-category.test?rev=352764&r1=352763&r2=352764&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clangd/diagnostic-category.test (original) +++ clang-tools-extra/trunk/test/clangd/diagnostic-category.test Thu Jan 31 08:09:25 2019 @@ -7,7 +7,7 @@ # CHECK-NEXT: "diagnostics": [ # CHECK-NEXT: { # CHECK-NEXT: "category": "Semantic Issue", -# CHECK-NEXT: "message": "Use of 'Point' with tag type that does not match previous declaration\n\nfoo.c:1:8: note: previous use is here", +# CHECK-NEXT: "message": "Use of 'Point' with tag type that does not match previous declaration (fix available)\n\nfoo.c:1:8: note: previous use is here", # CHECK-NEXT: "range": { # CHECK-NEXT: "end": { # CHECK-NEXT: "character": 22, 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=352764&r1=352763&r2=352764&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clangd/diagnostics.test (original) +++ clang-tools-extra/trunk/test/clangd/diagnostics.test Thu Jan 31 08:09:25 2019 @@ -6,7 +6,7 @@ # CHECK-NEXT: "params": { # CHECK-NEXT: "diagnostics": [ # CHECK-NEXT: { -# CHECK-NEXT: "message": "Return type of 'main' is not 'int'", +# CHECK-NEXT: "message": "Return type of 'main' is not 'int' (fix available)", # CHECK-NEXT: "range": { # CHECK-NEXT: "end": { # CHECK-NEXT: "character": 4, Modified: clang-tools-extra/trunk/test/clangd/did-change-configuration-params.test URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/did-change-configuration-params.test?rev=352764&r1=352763&r2=352764&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clangd/did-change-configuration-params.test (original) +++ clang-tools-extra/trunk/test/clangd/did-change-configuration-params.test Thu Jan 31 08:09:25 2019 @@ -24,7 +24,7 @@ # CHECK-NEXT: "params": { # CHECK-NEXT: "diagnostics": [ # CHECK-NEXT: { -# CHECK-NEXT: "message": "Variable 'i' is uninitialized when used here", +# CHECK-NEXT: "message": "Variable 'i' is uninitialized when used here (fix available)", # CHECK-NEXT: "range": { # CHECK-NEXT: "end": { # CHECK-NEXT: "character": 28, Modified: clang-tools-extra/trunk/test/clangd/execute-command.test URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/execute-command.test?rev=352764&r1=352763&r2=352764&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clangd/execute-command.test (original) +++ clang-tools-extra/trunk/test/clangd/execute-command.test Thu Jan 31 08:09:25 2019 @@ -6,7 +6,7 @@ # CHECK-NEXT: "params": { # CHECK-NEXT: "diagnostics": [ # CHECK-NEXT: { -# CHECK-NEXT: "message": "Using the result of an assignment as a condition without parentheses", +# CHECK-NEXT: "message": "Using the result of an assignment as a condition without parentheses (fixes available)", # CHECK-NEXT: "range": { # CHECK-NEXT: "end": { # CHECK-NEXT: "character": 37, Modified: clang-tools-extra/trunk/test/clangd/fixits-codeaction.test URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/fixits-codeaction.test?rev=352764&r1=352763&r2=352764&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clangd/fixits-codeaction.test (original) +++ clang-tools-extra/trunk/test/clangd/fixits-codeaction.test Thu Jan 31 08:09:25 2019 @@ -6,7 +6,7 @@ # CHECK-NEXT: "params": { # CHECK-NEXT: "diagnostics": [ # CHECK-NEXT: { -# CHECK-NEXT: "message": "Using the result of an assignment as a condition without parentheses", +# CHECK-NEXT: "message": "Using the result of an assignment as a condition without parentheses (fixes available)", # CHECK-NEXT: "range": { # CHECK-NEXT: "end": { # CHECK-NEXT: "character": 37, @@ -23,14 +23,14 @@ # CHECK-NEXT: "uri": "file://{{.*}}/foo.c" # CHECK-NEXT: } --- -{"jsonrpc":"2.0","id":2,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///foo.c"},"range":{"start":{"line":0,"character":13},"end":{"line":0,"character":35}},"context":{"diagnostics":[{"range":{"start": {"line": 0, "character": 32}, "end": {"line": 0, "character": 37}},"severity":2,"message":"Using the result of an assignment as a condition without parentheses"}]}}} +{"jsonrpc":"2.0","id":2,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///foo.c"},"range":{"start":{"line":0,"character":13},"end":{"line":0,"character":35}},"context":{"diagnostics":[{"range":{"start": {"line": 0, "character": 32}, "end": {"line": 0, "character": 37}},"severity":2,"message":"Using the result of an assignment as a condition without parentheses (fixes available)"}]}}} # CHECK: "id": 2, # CHECK-NEXT: "jsonrpc": "2.0", # CHECK-NEXT: "result": [ # CHECK-NEXT: { # CHECK-NEXT: "diagnostics": [ # CHECK-NEXT: { -# CHECK-NEXT: "message": "Using the result of an assignment as a condition without parentheses", +# CHECK-NEXT: "message": "Using the result of an assignment as a condition without parentheses (fixes available)", # CHECK-NEXT: "range": { # CHECK-NEXT: "end": { # CHECK-NEXT: "character": 37, @@ -82,7 +82,7 @@ # CHECK-NEXT: { # CHECK-NEXT: "diagnostics": [ # CHECK-NEXT: { -# CHECK-NEXT: "message": "Using the result of an assignment as a condition without parentheses", +# CHECK-NEXT: "message": "Using the result of an assignment as a condition without parentheses (fixes available)", # CHECK-NEXT: "range": { # CHECK-NEXT: "end": { # CHECK-NEXT: "character": 37, Modified: clang-tools-extra/trunk/test/clangd/fixits-command.test URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/fixits-command.test?rev=352764&r1=352763&r2=352764&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clangd/fixits-command.test (original) +++ clang-tools-extra/trunk/test/clangd/fixits-command.test Thu Jan 31 08:09:25 2019 @@ -6,7 +6,7 @@ # CHECK-NEXT: "params": { # CHECK-NEXT: "diagnostics": [ # CHECK-NEXT: { -# CHECK-NEXT: "message": "Using the result of an assignment as a condition without parentheses", +# CHECK-NEXT: "message": "Using the result of an assignment as a condition without parentheses (fixes available)", # CHECK-NEXT: "range": { # CHECK-NEXT: "end": { # CHECK-NEXT: "character": 37, @@ -23,7 +23,7 @@ # CHECK-NEXT: "uri": "file://{{.*}}/foo.c" # CHECK-NEXT: } --- -{"jsonrpc":"2.0","id":2,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///foo.c"},"range":{"start":{"line":0,"character":13},"end":{"line":0,"character":35}},"context":{"diagnostics":[{"range":{"start": {"line": 0, "character": 32}, "end": {"line": 0, "character": 37}},"severity":2,"message":"Using the result of an assignment as a condition without parentheses"}]}}} +{"jsonrpc":"2.0","id":2,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///foo.c"},"range":{"start":{"line":0,"character":13},"end":{"line":0,"character":35}},"context":{"diagnostics":[{"range":{"start": {"line": 0, "character": 32}, "end": {"line": 0, "character": 37}},"severity":2,"message":"Using the result of an assignment as a condition without parentheses (fixes available)"}]}}} # CHECK: "id": 2, # CHECK-NEXT: "jsonrpc": "2.0", # CHECK-NEXT: "result": [ @@ -92,7 +92,7 @@ # CHECK-NEXT: } # CHECK-NEXT: ] --- -{"jsonrpc":"2.0","id":3,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///foo.c"},"range":{"start":{"line":0,"character":13},"end":{"line":0,"character":35}},"context":{"diagnostics":[{"range":{"start": {"line": 0, "character": 32}, "end": {"line": 0, "character": 37}},"severity":2,"message":"Using the result of an assignment as a condition without parentheses"}]}}} +{"jsonrpc":"2.0","id":3,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///foo.c"},"range":{"start":{"line":0,"character":13},"end":{"line":0,"character":35}},"context":{"diagnostics":[{"range":{"start": {"line": 0, "character": 32}, "end": {"line": 0, "character": 37}},"severity":2,"message":"Using the result of an assignment as a condition without parentheses (fixes available)"}]}}} # Make sure unused "code" and "source" fields ignored gracefully # CHECK: "id": 3, # CHECK-NEXT: "jsonrpc": "2.0", Modified: clang-tools-extra/trunk/test/clangd/fixits-embed-in-diagnostic.test URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/fixits-embed-in-diagnostic.test?rev=352764&r1=352763&r2=352764&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clangd/fixits-embed-in-diagnostic.test (original) +++ clang-tools-extra/trunk/test/clangd/fixits-embed-in-diagnostic.test Thu Jan 31 08:09:25 2019 @@ -31,7 +31,7 @@ # CHECK-NEXT: "title": "change 'union' to 'struct'" # CHECK-NEXT: } # CHECK-NEXT: ], -# CHECK-NEXT: "message": "Use of 'Point' with tag type that does not match previous declaration\n\nfoo.c:1:8: note: previous use is here", +# CHECK-NEXT: "message": "Use of 'Point' with tag type that does not match previous declaration (fix available)\n\nfoo.c:1:8: note: previous use is here", # CHECK-NEXT: "range": { # CHECK-NEXT: "end": { # CHECK-NEXT: "character": 22, 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=352764&r1=352763&r2=352764&view=diff ============================================================================== --- clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp Thu Jan 31 08:09:25 2019 @@ -246,7 +246,8 @@ TEST(DiagnosticsTest, ToLSP) { }; // Diagnostics should turn into these: - clangd::Diagnostic MainLSP = MatchingLSP(D, R"(Something terrible happened + clangd::Diagnostic MainLSP = + MatchingLSP(D, R"(Something terrible happened (fix available) main.cpp:6:7: remark: declared somewhere in the main file _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits