Skip to content

Commit cbf497f

Browse files
committed
[clangd] Return Command objects from onCodeAction, rather than ad-hoc JSON. NFC
llvm-svn: 344363
1 parent 359544a commit cbf497f

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -339,20 +339,21 @@ void ClangdLSPServer::onCodeAction(CodeActionParams &Params) {
339339
return replyError(ErrorCode::InvalidParams,
340340
"onCodeAction called for non-added file");
341341

342-
json::Array Commands;
342+
std::vector<Command> Commands;
343343
for (Diagnostic &D : Params.context.diagnostics) {
344344
for (auto &F : getFixes(Params.textDocument.uri.file(), D)) {
345345
WorkspaceEdit WE;
346346
std::vector<TextEdit> Edits(F.Edits.begin(), F.Edits.end());
347-
WE.changes = {{Params.textDocument.uri.uri(), std::move(Edits)}};
348-
Commands.push_back(json::Object{
349-
{"title", llvm::formatv("Apply fix: {0}", F.Message)},
350-
{"command", ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND},
351-
{"arguments", {WE}},
352-
});
347+
Commands.emplace_back();
348+
Commands.back().title = llvm::formatv("Apply fix: {0}", F.Message);
349+
Commands.back().command = ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND;
350+
Commands.back().workspaceEdit.emplace();
351+
Commands.back().workspaceEdit->changes = {
352+
{Params.textDocument.uri.uri(), std::move(Edits)},
353+
};
353354
}
354355
}
355-
reply(std::move(Commands));
356+
reply(json::Array(Commands));
356357
}
357358

358359
void ClangdLSPServer::onCompletion(TextDocumentPositionParams &Params) {

clang-tools-extra/clangd/Protocol.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,6 @@ bool fromJSON(const llvm::json::Value &, ExecuteCommandParams &);
673673
struct Command : public ExecuteCommandParams {
674674
std::string title;
675675
};
676-
677676
llvm::json::Value toJSON(const Command &C);
678677

679678
/// Represents information about programming constructs like variables, classes,

0 commit comments

Comments
 (0)