summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Liu <ioeric@google.com>2019-01-31 16:09:25 +0000
committerEric Liu <ioeric@google.com>2019-01-31 16:09:25 +0000
commit00eaf6732e9f8e311603cfe97c913d052424cfaa (patch)
tree121edbcc9884689f6ee9c4f0004231adb9070eb2
parent992b53fd1617be518489d3f890afff5f14d7adae (diff)
downloadbcm5719-llvm-00eaf6732e9f8e311603cfe97c913d052424cfaa.tar.gz
bcm5719-llvm-00eaf6732e9f8e311603cfe97c913d052424cfaa.zip
[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 llvm-svn: 352764
-rw-r--r--clang-tools-extra/clangd/Diagnostics.cpp2
-rw-r--r--clang-tools-extra/test/clangd/diagnostic-category.test2
-rw-r--r--clang-tools-extra/test/clangd/diagnostics.test2
-rw-r--r--clang-tools-extra/test/clangd/did-change-configuration-params.test2
-rw-r--r--clang-tools-extra/test/clangd/execute-command.test2
-rw-r--r--clang-tools-extra/test/clangd/fixits-codeaction.test8
-rw-r--r--clang-tools-extra/test/clangd/fixits-command.test6
-rw-r--r--clang-tools-extra/test/clangd/fixits-embed-in-diagnostic.test2
-rw-r--r--clang-tools-extra/unittests/clangd/DiagnosticsTests.cpp3
9 files changed, 16 insertions, 13 deletions
diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp
index f370caa8059..83876217b09 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -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);
diff --git a/clang-tools-extra/test/clangd/diagnostic-category.test b/clang-tools-extra/test/clangd/diagnostic-category.test
index 440afbb1e1f..08ad581cbfa 100644
--- a/clang-tools-extra/test/clangd/diagnostic-category.test
+++ b/clang-tools-extra/test/clangd/diagnostic-category.test
@@ -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,
diff --git a/clang-tools-extra/test/clangd/diagnostics.test b/clang-tools-extra/test/clangd/diagnostics.test
index a191c0822a9..ae662693a50 100644
--- a/clang-tools-extra/test/clangd/diagnostics.test
+++ b/clang-tools-extra/test/clangd/diagnostics.test
@@ -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,
diff --git a/clang-tools-extra/test/clangd/did-change-configuration-params.test b/clang-tools-extra/test/clangd/did-change-configuration-params.test
index 51b4a874741..5c216014518 100644
--- a/clang-tools-extra/test/clangd/did-change-configuration-params.test
+++ b/clang-tools-extra/test/clangd/did-change-configuration-params.test
@@ -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,
diff --git a/clang-tools-extra/test/clangd/execute-command.test b/clang-tools-extra/test/clangd/execute-command.test
index 85d4b9b88d9..3c9c45f8e18 100644
--- a/clang-tools-extra/test/clangd/execute-command.test
+++ b/clang-tools-extra/test/clangd/execute-command.test
@@ -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,
diff --git a/clang-tools-extra/test/clangd/fixits-codeaction.test b/clang-tools-extra/test/clangd/fixits-codeaction.test
index 253df992b32..47d75655157 100644
--- a/clang-tools-extra/test/clangd/fixits-codeaction.test
+++ b/clang-tools-extra/test/clangd/fixits-codeaction.test
@@ -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,
diff --git a/clang-tools-extra/test/clangd/fixits-command.test b/clang-tools-extra/test/clangd/fixits-command.test
index 369b34a9e08..da508321884 100644
--- a/clang-tools-extra/test/clangd/fixits-command.test
+++ b/clang-tools-extra/test/clangd/fixits-command.test
@@ -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",
diff --git a/clang-tools-extra/test/clangd/fixits-embed-in-diagnostic.test b/clang-tools-extra/test/clangd/fixits-embed-in-diagnostic.test
index f1aa1cfe56c..560fca6baf3 100644
--- a/clang-tools-extra/test/clangd/fixits-embed-in-diagnostic.test
+++ b/clang-tools-extra/test/clangd/fixits-embed-in-diagnostic.test
@@ -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,
diff --git a/clang-tools-extra/unittests/clangd/DiagnosticsTests.cpp b/clang-tools-extra/unittests/clangd/DiagnosticsTests.cpp
index ea1952e98ad..ca544013f1c 100644
--- a/clang-tools-extra/unittests/clangd/DiagnosticsTests.cpp
+++ b/clang-tools-extra/unittests/clangd/DiagnosticsTests.cpp
@@ -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
OpenPOWER on IntegriCloud