[clangd] Drop fixes if replying with tweaks resulted in an error
authorIlya Biryukov <ibiryukov@google.com>
Wed, 30 Jan 2019 14:24:17 +0000 (14:24 +0000)
committerIlya Biryukov <ibiryukov@google.com>
Wed, 30 Jan 2019 14:24:17 +0000 (14:24 +0000)
This should not happen in normal operation, as it implies that the diagnostics
with some available fixes were produced but the AST is invalid.
Moreover, the code had an error: always returned code actions ignoring the
SupportsCodeAction capability and writing a test for this is impossible,
since this can only happen due to programmer's error rather than invalid inputs.

llvm-svn: 352624

clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/test/clangd/fixits-codeaction.test

index 705777c..0671ee3 100644 (file)
@@ -672,14 +672,8 @@ void ClangdLSPServer::onCodeAction(const CodeActionParams &Params,
       [this](decltype(Reply) Reply, URIForFile File, std::string Code,
              Range Selection, std::vector<CodeAction> FixIts,
              llvm::Expected<std::vector<ClangdServer::TweakRef>> Tweaks) {
-        if (!Tweaks) {
-          auto Err = Tweaks.takeError();
-          if (Err.isA<CancelledError>())
-            return Reply(std::move(Err)); // do no logging, this is expected.
-          elog("error while getting semantic code actions: {0}",
-               std::move(Err));
-          return Reply(llvm::json::Array(FixIts));
-        }
+        if (!Tweaks)
+          return Reply(Tweaks.takeError());
 
         std::vector<CodeAction> Actions = std::move(FixIts);
         Actions.reserve(Actions.size() + Tweaks->size());
index 97dd4ff..253df99 100644 (file)
@@ -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":104,"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"}]}}}
 #      CHECK:  "id": 2,
 # CHECK-NEXT:  "jsonrpc": "2.0",
 # CHECK-NEXT:  "result": [