From cbf497f4528f1a16429ef1d668c77a547923cda6 Mon Sep 17 00:00:00 2001 From: Sam McCall Date: Fri, 12 Oct 2018 16:51:48 +0000 Subject: [PATCH] [clangd] Return Command objects from onCodeAction, rather than ad-hoc JSON. NFC llvm-svn: 344363 --- clang-tools-extra/clangd/ClangdLSPServer.cpp | 17 +++++++++-------- clang-tools-extra/clangd/Protocol.h | 1 - 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp index ca898a1..02496ad 100644 --- a/clang-tools-extra/clangd/ClangdLSPServer.cpp +++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp @@ -339,20 +339,21 @@ void ClangdLSPServer::onCodeAction(CodeActionParams &Params) { return replyError(ErrorCode::InvalidParams, "onCodeAction called for non-added file"); - json::Array Commands; + std::vector Commands; for (Diagnostic &D : Params.context.diagnostics) { for (auto &F : getFixes(Params.textDocument.uri.file(), D)) { WorkspaceEdit WE; std::vector Edits(F.Edits.begin(), F.Edits.end()); - WE.changes = {{Params.textDocument.uri.uri(), std::move(Edits)}}; - Commands.push_back(json::Object{ - {"title", llvm::formatv("Apply fix: {0}", F.Message)}, - {"command", ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND}, - {"arguments", {WE}}, - }); + Commands.emplace_back(); + Commands.back().title = llvm::formatv("Apply fix: {0}", F.Message); + Commands.back().command = ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND; + Commands.back().workspaceEdit.emplace(); + Commands.back().workspaceEdit->changes = { + {Params.textDocument.uri.uri(), std::move(Edits)}, + }; } } - reply(std::move(Commands)); + reply(json::Array(Commands)); } void ClangdLSPServer::onCompletion(TextDocumentPositionParams &Params) { diff --git a/clang-tools-extra/clangd/Protocol.h b/clang-tools-extra/clangd/Protocol.h index 22da2e3..bd0973f 100644 --- a/clang-tools-extra/clangd/Protocol.h +++ b/clang-tools-extra/clangd/Protocol.h @@ -673,7 +673,6 @@ bool fromJSON(const llvm::json::Value &, ExecuteCommandParams &); struct Command : public ExecuteCommandParams { std::string title; }; - llvm::json::Value toJSON(const Command &C); /// Represents information about programming constructs like variables, classes, -- 2.7.4