diff options
author | Sam McCall <sam.mccall@gmail.com> | 2018-10-16 16:29:41 +0000 |
---|---|---|
committer | Sam McCall <sam.mccall@gmail.com> | 2018-10-16 16:29:41 +0000 |
commit | 20841d41e762293b319b1a69b9f3cf72052fd9ee (patch) | |
tree | c08b2bc9593ed00b7cd395cbcfafb37b862ff84d /clang-tools-extra/clangd/Protocol.cpp | |
parent | 69067f2bfddb027e7a69ba8a5ab399f08fe1dd80 (diff) | |
download | bcm5719-llvm-20841d41e762293b319b1a69b9f3cf72052fd9ee.tar.gz bcm5719-llvm-20841d41e762293b319b1a69b9f3cf72052fd9ee.zip |
[clangd] Send CodeAction responses to textDocument/codeAction (LSP 3.8)
Summary:
I don't bother mirroring the full capabilities struct, just parse the
bits we care about. I'll send a new patch to use this approach elsewhere too.
Reviewers: kadircet
Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits
Differential Revision: https://reviews.llvm.org/D53213
llvm-svn: 344617
Diffstat (limited to 'clang-tools-extra/clangd/Protocol.cpp')
-rw-r--r-- | clang-tools-extra/clangd/Protocol.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/Protocol.cpp b/clang-tools-extra/clangd/Protocol.cpp index ced7cf264a9..daab1328c4c 100644 --- a/clang-tools-extra/clangd/Protocol.cpp +++ b/clang-tools-extra/clangd/Protocol.cpp @@ -251,6 +251,9 @@ bool fromJSON(const json::Value &Params, TextDocumentClientCapabilities &R) { return false; O.map("completion", R.completion); O.map("publishDiagnostics", R.publishDiagnostics); + if (auto *CodeAction = Params.getAsObject()->getObject("codeAction")) + if (CodeAction->getObject("codeActionLiteralSupport")) + R.codeActionLiteralSupport = true; return true; } @@ -360,6 +363,17 @@ bool fromJSON(const json::Value &Params, DocumentSymbolParams &R) { return O && O.map("textDocument", R.textDocument); } +llvm::json::Value toJSON(const Diagnostic &D) { + json::Object Diag{ + {"range", D.range}, + {"severity", D.severity}, + {"message", D.message}, + }; + // FIXME: this should be used for publishDiagnostics. + // FIXME: send category and fixes when appropriate. + return std::move(Diag); +} + bool fromJSON(const json::Value &Params, Diagnostic &R) { json::ObjectMapper O(Params); if (!O || !O.map("range", R.range) || !O.map("message", R.message)) @@ -448,6 +462,21 @@ json::Value toJSON(const Command &C) { return std::move(Cmd); } +const llvm::StringLiteral CodeAction::QUICKFIX_KIND = "quickfix"; + +llvm::json::Value toJSON(const CodeAction &CA) { + auto CodeAction = json::Object{{"title", CA.title}}; + if (CA.kind) + CodeAction["kind"] = *CA.kind; + if (CA.diagnostics) + CodeAction["diagnostics"] = json::Array(*CA.diagnostics); + if (CA.edit) + CodeAction["edit"] = *CA.edit; + if (CA.command) + CodeAction["command"] = *CA.command; + return std::move(CodeAction); +} + json::Value toJSON(const WorkspaceEdit &WE) { if (!WE.changes) return json::Object{}; |