Skip to content
This repository has been archived by the owner on Jul 30, 2020. It is now read-only.

Commit

Permalink
Add workspace/executeCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Mar 2, 2018
1 parent 324aac3 commit f3e9e75
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 51 deletions.
46 changes: 46 additions & 0 deletions src/lsp_code_action.h
Original file line number Diff line number Diff line change
@@ -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;
}
});
}
2 changes: 1 addition & 1 deletion src/messages/initialize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 1 addition & 7 deletions src/messages/text_document_code_action.cc
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand Down
44 changes: 1 addition & 43 deletions src/messages/text_document_code_lens.cc
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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> {
Expand All @@ -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;
Expand Down
49 changes: 49 additions & 0 deletions src/messages/workspace_execute_command.cc
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions src/methods.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f3e9e75

Please sign in to comment.