[clang-tools-extra] r344363 - [clangd] Return Command objects from onCodeAction, rather than ad-hoc JSON. NFC

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 12 09:51:49 PDT 2018


Author: sammccall
Date: Fri Oct 12 09:51:48 2018
New Revision: 344363

URL: http://llvm.org/viewvc/llvm-project?rev=344363&view=rev
Log:
[clangd] Return Command objects from onCodeAction, rather than ad-hoc JSON. NFC

Modified:
    clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
    clang-tools-extra/trunk/clangd/Protocol.h

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=344363&r1=344362&r2=344363&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Fri Oct 12 09:51:48 2018
@@ -339,20 +339,21 @@ void ClangdLSPServer::onCodeAction(CodeA
     return replyError(ErrorCode::InvalidParams,
                       "onCodeAction called for non-added file");
 
-  json::Array Commands;
+  std::vector<Command> Commands;
   for (Diagnostic &D : Params.context.diagnostics) {
     for (auto &F : getFixes(Params.textDocument.uri.file(), D)) {
       WorkspaceEdit WE;
       std::vector<TextEdit> 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) {

Modified: clang-tools-extra/trunk/clangd/Protocol.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.h?rev=344363&r1=344362&r2=344363&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/Protocol.h (original)
+++ clang-tools-extra/trunk/clangd/Protocol.h Fri Oct 12 09:51:48 2018
@@ -673,7 +673,6 @@ bool fromJSON(const llvm::json::Value &,
 struct Command : public ExecuteCommandParams {
   std::string title;
 };
-
 llvm::json::Value toJSON(const Command &C);
 
 /// Represents information about programming constructs like variables, classes,




More information about the cfe-commits mailing list