mirror of
https://github.com/MaskRay/ccls.git
synced 2025-02-19 15:10:47 +00:00
Add workspace/executeCommand
This commit is contained in:
parent
8fcf60e3bc
commit
8de44e3b95
46
src/lsp_code_action.h
Normal file
46
src/lsp_code_action.h
Normal 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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
@ -162,7 +162,7 @@ struct lsServerCapabilities {
|
|||||||
// The server provides document link support.
|
// The server provides document link support.
|
||||||
lsDocumentLinkOptions documentLinkProvider;
|
lsDocumentLinkOptions documentLinkProvider;
|
||||||
// The server provides execute command support.
|
// The server provides execute command support.
|
||||||
optional<lsExecuteCommandOptions> executeCommandProvider;
|
lsExecuteCommandOptions executeCommandProvider;
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(lsServerCapabilities,
|
MAKE_REFLECT_STRUCT(lsServerCapabilities,
|
||||||
textDocumentSync,
|
textDocumentSync,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "include_complete.h"
|
#include "include_complete.h"
|
||||||
#include "lex_utils.h"
|
#include "lex_utils.h"
|
||||||
|
#include "lsp_code_action.h"
|
||||||
#include "message_handler.h"
|
#include "message_handler.h"
|
||||||
#include "query_utils.h"
|
#include "query_utils.h"
|
||||||
#include "queue_manager.h"
|
#include "queue_manager.h"
|
||||||
@ -286,18 +287,11 @@ REGISTER_IPC_MESSAGE(Ipc_TextDocumentCodeAction);
|
|||||||
|
|
||||||
struct Out_TextDocumentCodeAction
|
struct Out_TextDocumentCodeAction
|
||||||
: public lsOutMessage<Out_TextDocumentCodeAction> {
|
: public lsOutMessage<Out_TextDocumentCodeAction> {
|
||||||
struct CommandArgs {
|
|
||||||
lsDocumentUri textDocumentUri;
|
|
||||||
std::vector<lsTextEdit> edits;
|
|
||||||
};
|
|
||||||
using Command = lsCommand<CommandArgs>;
|
using Command = lsCommand<CommandArgs>;
|
||||||
|
|
||||||
lsRequestId id;
|
lsRequestId id;
|
||||||
std::vector<Command> result;
|
std::vector<Command> result;
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT_WRITER_AS_ARRAY(Out_TextDocumentCodeAction::CommandArgs,
|
|
||||||
textDocumentUri,
|
|
||||||
edits);
|
|
||||||
MAKE_REFLECT_STRUCT(Out_TextDocumentCodeAction, jsonrpc, id, result);
|
MAKE_REFLECT_STRUCT(Out_TextDocumentCodeAction, jsonrpc, id, result);
|
||||||
|
|
||||||
struct TextDocumentCodeActionHandler
|
struct TextDocumentCodeActionHandler
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "clang_complete.h"
|
#include "clang_complete.h"
|
||||||
|
#include "lsp_code_action.h"
|
||||||
#include "message_handler.h"
|
#include "message_handler.h"
|
||||||
#include "query_utils.h"
|
#include "query_utils.h"
|
||||||
#include "queue_manager.h"
|
#include "queue_manager.h"
|
||||||
@ -9,32 +10,6 @@ struct lsDocumentCodeLensParams {
|
|||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(lsDocumentCodeLensParams, textDocument);
|
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>;
|
using TCodeLens = lsCodeLens<lsCodeLensUserData, lsCodeLensCommandArguments>;
|
||||||
struct Ipc_TextDocumentCodeLens
|
struct Ipc_TextDocumentCodeLens
|
||||||
: public RequestMessage<Ipc_TextDocumentCodeLens> {
|
: public RequestMessage<Ipc_TextDocumentCodeLens> {
|
||||||
@ -52,23 +27,6 @@ struct Out_TextDocumentCodeLens
|
|||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(Out_TextDocumentCodeLens, jsonrpc, id, result);
|
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 {
|
struct CommonCodeLensParams {
|
||||||
std::vector<TCodeLens>* result;
|
std::vector<TCodeLens>* result;
|
||||||
QueryDatabase* db;
|
QueryDatabase* db;
|
||||||
|
49
src/messages/workspace_execute_command.cc
Normal file
49
src/messages/workspace_execute_command.cc
Normal 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
|
@ -25,6 +25,7 @@ CASE(TextDocumentSignatureHelp, "textDocument/signatureHelp")
|
|||||||
CASE(TextDocumentTypeDefinition, "textDocument/typeDefinition")
|
CASE(TextDocumentTypeDefinition, "textDocument/typeDefinition")
|
||||||
CASE(WorkspaceDidChangeConfiguration, "workspace/didChangeConfiguration")
|
CASE(WorkspaceDidChangeConfiguration, "workspace/didChangeConfiguration")
|
||||||
CASE(WorkspaceDidChangeWatchedFiles, "workspace/didChangeWatchedFiles")
|
CASE(WorkspaceDidChangeWatchedFiles, "workspace/didChangeWatchedFiles")
|
||||||
|
CASE(WorkspaceExecuteCommand, "workspace/executeCommand")
|
||||||
CASE(WorkspaceSymbol, "workspace/symbol")
|
CASE(WorkspaceSymbol, "workspace/symbol")
|
||||||
|
|
||||||
// Notification extensions
|
// Notification extensions
|
||||||
|
Loading…
Reference in New Issue
Block a user