diff --git a/src/lsp_code_action.h b/src/lsp_code_action.h new file mode 100644 index 00000000..30c049a8 --- /dev/null +++ b/src/lsp_code_action.h @@ -0,0 +1,46 @@ +#pragma once + +#include "lsp.h" + +// codeAction +struct CommandArgs { + lsDocumentUri textDocumentUri; + std::vector 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 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; + } + }); +} diff --git a/src/messages/initialize.cc b/src/messages/initialize.cc index f6233858..7e8869d3 100644 --- a/src/messages/initialize.cc +++ b/src/messages/initialize.cc @@ -162,7 +162,7 @@ struct lsServerCapabilities { // The server provides document link support. lsDocumentLinkOptions documentLinkProvider; // The server provides execute command support. - optional executeCommandProvider; + lsExecuteCommandOptions executeCommandProvider; }; MAKE_REFLECT_STRUCT(lsServerCapabilities, textDocumentSync, diff --git a/src/messages/text_document_code_action.cc b/src/messages/text_document_code_action.cc index cb0f3168..df569e5c 100644 --- a/src/messages/text_document_code_action.cc +++ b/src/messages/text_document_code_action.cc @@ -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 { - struct CommandArgs { - lsDocumentUri textDocumentUri; - std::vector edits; - }; using Command = lsCommand; lsRequestId id; std::vector result; }; -MAKE_REFLECT_STRUCT_WRITER_AS_ARRAY(Out_TextDocumentCodeAction::CommandArgs, - textDocumentUri, - edits); MAKE_REFLECT_STRUCT(Out_TextDocumentCodeAction, jsonrpc, id, result); struct TextDocumentCodeActionHandler diff --git a/src/messages/text_document_code_lens.cc b/src/messages/text_document_code_lens.cc index ea6f414a..792c8426 100644 --- a/src/messages/text_document_code_lens.cc +++ b/src/messages/text_document_code_lens.cc @@ -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 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; struct Ipc_TextDocumentCodeLens : public RequestMessage { @@ -52,23 +27,6 @@ struct Out_TextDocumentCodeLens }; MAKE_REFLECT_STRUCT(Out_TextDocumentCodeLens, jsonrpc, id, result); -#if false -struct Ipc_CodeLensResolve : public IpcMessage { - 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 { - lsRequestId id; - TCodeLens result; -}; -MAKE_REFLECT_STRUCT(Out_CodeLensResolve, jsonrpc, id, result); -#endif - struct CommonCodeLensParams { std::vector* result; QueryDatabase* db; diff --git a/src/messages/workspace_execute_command.cc b/src/messages/workspace_execute_command.cc new file mode 100644 index 00000000..adb405f4 --- /dev/null +++ b/src/messages/workspace_execute_command.cc @@ -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 { + const static IpcId kIpcId = IpcId::WorkspaceExecuteCommand; + lsCommand params; +}; +MAKE_REFLECT_STRUCT(Ipc_WorkspaceExecuteCommand, id, params); +REGISTER_IPC_MESSAGE(Ipc_WorkspaceExecuteCommand); + +struct Out_WorkspaceExecuteCommand + : public lsOutMessage { + lsRequestId id; + std::variant, 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 { + 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 diff --git a/src/methods.inc b/src/methods.inc index 6b6662e7..8298c0d6 100644 --- a/src/methods.inc +++ b/src/methods.inc @@ -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