[clangd] Drop fixes if replying with tweaks resulted in an error

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
This commit is contained in:
Ilya Biryukov 2019-01-30 14:24:17 +00:00
parent 4b4899b0ae
commit c6ed77812b
2 changed files with 3 additions and 9 deletions

View 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());

View 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": [