Add workspace/executeCommand

This commit is contained in:
Fangrui Song 2018-03-01 20:33:21 -08:00
parent 8fcf60e3bc
commit 8de44e3b95
6 changed files with 99 additions and 51 deletions

46
src/lsp_code_action.h Normal file
View File

@ -0,0 +1,46 @@
#pragma once
#include "lsp.h"
// codeAction
struct CommandArgs {
lsDocumentUri textDocumentUri;
std::vector<lsTextEdit> edits;
};
MAKE_REFLECT_STRUCT_WRITER_AS_ARRAY(CommandArgs, textDocumentUri, edits);
// codeLens
struct lsCodeLensUserData {};
MAKE_REFLECT_EMPTY_STRUCT(lsCodeLensUserData);
struct lsCodeLensCommandArguments {
lsDocumentUri uri;
lsPosition position;
std::vector<lsLocation> locations;
};
// FIXME Don't use array in vscode-cquery
inline void Reflect(Writer& visitor, lsCodeLensCommandArguments& value) {
visitor.StartArray(3);
Reflect(visitor, value.uri);
Reflect(visitor, value.position);
Reflect(visitor, value.locations);
visitor.EndArray();
}
inline void Reflect(Reader& visitor, lsCodeLensCommandArguments& value) {
int i = 0;
visitor.IterArray([&](Reader& visitor) {
switch (i++) {
case 0:
Reflect(visitor, value.uri);
break;
case 1:
Reflect(visitor, value.position);
break;
case 2:
Reflect(visitor, value.locations);
break;
}
});
}

View File

@ -162,7 +162,7 @@ struct lsServerCapabilities {
// The server provides document link support.
lsDocumentLinkOptions documentLinkProvider;
// The server provides execute command support.
optional<lsExecuteCommandOptions> executeCommandProvider;
lsExecuteCommandOptions executeCommandProvider;
};
MAKE_REFLECT_STRUCT(lsServerCapabilities,
textDocumentSync,

View File

@ -1,5 +1,6 @@
#include "include_complete.h"
#include "lex_utils.h"
#include "lsp_code_action.h"
#include "message_handler.h"
#include "query_utils.h"
#include "queue_manager.h"
@ -286,18 +287,11 @@ REGISTER_IPC_MESSAGE(Ipc_TextDocumentCodeAction);
struct Out_TextDocumentCodeAction
: public lsOutMessage<Out_TextDocumentCodeAction> {
struct CommandArgs {
lsDocumentUri textDocumentUri;
std::vector<lsTextEdit> edits;
};
using Command = lsCommand<CommandArgs>;
lsRequestId id;
std::vector<Command> result;
};
MAKE_REFLECT_STRUCT_WRITER_AS_ARRAY(Out_TextDocumentCodeAction::CommandArgs,
textDocumentUri,
edits);
MAKE_REFLECT_STRUCT(Out_TextDocumentCodeAction, jsonrpc, id, result);
struct TextDocumentCodeActionHandler

View File

@ -1,4 +1,5 @@
#include "clang_complete.h"
#include "lsp_code_action.h"
#include "message_handler.h"
#include "query_utils.h"
#include "queue_manager.h"
@ -9,32 +10,6 @@ struct lsDocumentCodeLensParams {
};
MAKE_REFLECT_STRUCT(lsDocumentCodeLensParams, textDocument);
struct lsCodeLensUserData {};
MAKE_REFLECT_EMPTY_STRUCT(lsCodeLensUserData);
struct lsCodeLensCommandArguments {
lsDocumentUri uri;
lsPosition position;
std::vector<lsLocation> locations;
};
void Reflect(Writer& visitor, lsCodeLensCommandArguments& value) {
visitor.StartArray(3);
Reflect(visitor, value.uri);
Reflect(visitor, value.position);
Reflect(visitor, value.locations);
visitor.EndArray();
}
#if false
void Reflect(Reader& visitor, lsCodeLensCommandArguments& value) {
auto it = visitor.Begin();
Reflect(*it, value.uri);
++it;
Reflect(*it, value.position);
++it;
Reflect(*it, value.locations);
}
#endif
using TCodeLens = lsCodeLens<lsCodeLensUserData, lsCodeLensCommandArguments>;
struct Ipc_TextDocumentCodeLens
: public RequestMessage<Ipc_TextDocumentCodeLens> {
@ -52,23 +27,6 @@ struct Out_TextDocumentCodeLens
};
MAKE_REFLECT_STRUCT(Out_TextDocumentCodeLens, jsonrpc, id, result);
#if false
struct Ipc_CodeLensResolve : public IpcMessage<Ipc_CodeLensResolve> {
const static IpcId kIpcId = IpcId::CodeLensResolve;
lsRequestId id;
TCodeLens params;
};
MAKE_REFLECT_STRUCT(Ipc_CodeLensResolve, id, params);
REGISTER_IPC_MESSAGE(Ipc_CodeLensResolve);
struct Out_CodeLensResolve : public lsOutMessage<Out_CodeLensResolve> {
lsRequestId id;
TCodeLens result;
};
MAKE_REFLECT_STRUCT(Out_CodeLensResolve, jsonrpc, id, result);
#endif
struct CommonCodeLensParams {
std::vector<TCodeLens>* result;
QueryDatabase* db;

View File

@ -0,0 +1,49 @@
#include "lsp_code_action.h"
#include "message_handler.h"
#include "query_utils.h"
#include "queue_manager.h"
namespace {
struct Ipc_WorkspaceExecuteCommand
: public RequestMessage<Ipc_WorkspaceExecuteCommand> {
const static IpcId kIpcId = IpcId::WorkspaceExecuteCommand;
lsCommand<lsCodeLensCommandArguments> params;
};
MAKE_REFLECT_STRUCT(Ipc_WorkspaceExecuteCommand, id, params);
REGISTER_IPC_MESSAGE(Ipc_WorkspaceExecuteCommand);
struct Out_WorkspaceExecuteCommand
: public lsOutMessage<Out_WorkspaceExecuteCommand> {
lsRequestId id;
std::variant<std::vector<lsLocation>, CommandArgs> result;
};
MAKE_REFLECT_STRUCT(Out_WorkspaceExecuteCommand, jsonrpc, id, result);
void Reflect(Writer& visitor, Out_WorkspaceExecuteCommand& value) {
REFLECT_MEMBER_START();
REFLECT_MEMBER(jsonrpc);
REFLECT_MEMBER(id);
REFLECT_MEMBER(result);
REFLECT_MEMBER_END();
}
struct WorkspaceExecuteCommandHandler
: BaseMessageHandler<Ipc_WorkspaceExecuteCommand> {
void Run(Ipc_WorkspaceExecuteCommand* request) override {
const auto& params = request->params;
Out_WorkspaceExecuteCommand out;
out.id = request->id;
if (params.command == "cquery._applyFixIt") {
} else if (params.command == "cquery._autoImplement") {
} else if (params.command == "cquery._insertInclude") {
} else if (params.command == "cquery.showReferences") {
out.result = params.arguments.locations;
}
QueueManager::WriteStdout(IpcId::WorkspaceExecuteCommand, out);
}
};
REGISTER_MESSAGE_HANDLER(WorkspaceExecuteCommandHandler);
} // namespace

View File

@ -25,6 +25,7 @@ CASE(TextDocumentSignatureHelp, "textDocument/signatureHelp")
CASE(TextDocumentTypeDefinition, "textDocument/typeDefinition")
CASE(WorkspaceDidChangeConfiguration, "workspace/didChangeConfiguration")
CASE(WorkspaceDidChangeWatchedFiles, "workspace/didChangeWatchedFiles")
CASE(WorkspaceExecuteCommand, "workspace/executeCommand")
CASE(WorkspaceSymbol, "workspace/symbol")
// Notification extensions