From 3e3bf885eb5d656ca39b3d359878545543186b5e Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 1 Mar 2018 19:07:44 -0800 Subject: [PATCH] Use X macros --- src/command_line.cc | 40 +-------- src/ipc.cc | 85 +------------------ src/ipc.h | 53 +----------- src/messages/text_document_type_definition.cc | 29 +++++++ src/methods.inc | 59 +++++++++++++ 5 files changed, 97 insertions(+), 169 deletions(-) create mode 100644 src/messages/text_document_type_definition.cc create mode 100644 src/methods.inc diff --git a/src/command_line.cc b/src/command_line.cc index 837a9f61..020e8836 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -317,46 +317,12 @@ void LaunchStdinLoop(Config* config, break; } - case IpcId::Shutdown: case IpcId::Exit: - case IpcId::Initialize: - case IpcId::TextDocumentDidOpen: - case IpcId::CqueryTextDocumentDidView: - case IpcId::TextDocumentDidChange: - case IpcId::TextDocumentDidClose: - case IpcId::TextDocumentDidSave: - case IpcId::TextDocumentFormatting: - case IpcId::TextDocumentRangeFormatting: - case IpcId::TextDocumentOnTypeFormatting: - case IpcId::TextDocumentRename: - case IpcId::TextDocumentCompletion: - case IpcId::TextDocumentSignatureHelp: - case IpcId::TextDocumentDefinition: - case IpcId::TextDocumentDocumentHighlight: - case IpcId::TextDocumentHover: - case IpcId::TextDocumentReferences: - case IpcId::TextDocumentDocumentSymbol: - case IpcId::TextDocumentDocumentLink: - case IpcId::TextDocumentCodeAction: - case IpcId::TextDocumentCodeLens: - case IpcId::WorkspaceDidChangeConfiguration: - case IpcId::WorkspaceDidChangeWatchedFiles: - case IpcId::WorkspaceSymbol: - case IpcId::CqueryFileInfo: - case IpcId::CqueryFreshenIndex: - case IpcId::CqueryCallHierarchy: - case IpcId::CqueryInheritanceHierarchy: - case IpcId::CqueryMemberHierarchy: - case IpcId::CqueryVars: - case IpcId::CqueryCallers: - case IpcId::CqueryBase: - case IpcId::CqueryDerived: - case IpcId::CqueryIndexFile: - case IpcId::CqueryRandom: - case IpcId::CqueryWait: { +#define CASE(name, method) case IpcId::name: +#include "methods.inc" +#undef CASE queue->for_querydb.PushBack(std::move(message)); break; - } default: { LOG_S(ERROR) << "Unhandled IPC message " << IpcIdToString(method_id); diff --git a/src/ipc.cc b/src/ipc.cc index 0c86e432..27598672 100644 --- a/src/ipc.cc +++ b/src/ipc.cc @@ -6,93 +6,14 @@ const char* IpcIdToString(IpcId id) { switch (id) { case IpcId::CancelRequest: return "$/cancelRequest"; - case IpcId::Initialize: - return "initialize"; case IpcId::Initialized: return "initialized"; - case IpcId::Shutdown: - return "shutdown"; case IpcId::Exit: return "exit"; - case IpcId::CodeLensResolve: - return "codeLens/resolve"; - case IpcId::TextDocumentDidOpen: - return "textDocument/didOpen"; - case IpcId::TextDocumentDidChange: - return "textDocument/didChange"; - case IpcId::TextDocumentDidClose: - return "textDocument/didClose"; - case IpcId::TextDocumentDidSave: - return "textDocument/didSave"; - case IpcId::TextDocumentPublishDiagnostics: - return "textDocument/publishDiagnostics"; - case IpcId::TextDocumentRename: - return "textDocument/rename"; - case IpcId::TextDocumentCompletion: - return "textDocument/completion"; - case IpcId::TextDocumentSignatureHelp: - return "textDocument/signatureHelp"; - case IpcId::TextDocumentDefinition: - return "textDocument/definition"; - case IpcId::TextDocumentDocumentHighlight: - return "textDocument/documentHighlight"; - case IpcId::TextDocumentHover: - return "textDocument/hover"; - case IpcId::TextDocumentFormatting: - return "textDocument/formatting"; - case IpcId::TextDocumentRangeFormatting: - return "textDocument/rangeFormatting"; - case IpcId::TextDocumentOnTypeFormatting: - return "textDocument/onTypeFormatting"; - case IpcId::TextDocumentReferences: - return "textDocument/references"; - case IpcId::TextDocumentDocumentSymbol: - return "textDocument/documentSymbol"; - case IpcId::TextDocumentDocumentLink: - return "textDocument/documentLink"; - case IpcId::TextDocumentCodeAction: - return "textDocument/codeAction"; - case IpcId::TextDocumentCodeLens: - return "textDocument/codeLens"; - case IpcId::WorkspaceDidChangeConfiguration: - return "workspace/didChangeConfiguration"; - case IpcId::WorkspaceDidChangeWatchedFiles: - return "workspace/didChangeWatchedFiles"; - case IpcId::WorkspaceSymbol: - return "workspace/symbol"; - case IpcId::CqueryTextDocumentDidView: - return "$cquery/textDocumentDidView"; - case IpcId::CqueryPublishInactiveRegions: - return "$cquery/publishInactiveRegions"; - case IpcId::CqueryPublishSemanticHighlighting: - return "$cquery/publishSemanticHighlighting"; - - case IpcId::CqueryFileInfo: - return "$cquery/fileInfo"; - case IpcId::CqueryFreshenIndex: - return "$cquery/freshenIndex"; - case IpcId::CqueryCallHierarchy: - return "$cquery/callHierarchy"; - case IpcId::CqueryInheritanceHierarchy: - return "$cquery/inheritanceHierarchy"; - case IpcId::CqueryMemberHierarchy: - return "$cquery/memberHierarchy"; - case IpcId::CqueryVars: - return "$cquery/vars"; - case IpcId::CqueryCallers: - return "$cquery/callers"; - case IpcId::CqueryBase: - return "$cquery/base"; - case IpcId::CqueryDerived: - return "$cquery/derived"; - case IpcId::CqueryRandom: - return "$cquery/random"; - - case IpcId::CqueryIndexFile: - return "$cquery/indexFile"; - case IpcId::CqueryWait: - return "$cquery/wait"; +#define CASE(name, method) case IpcId::name: return method; + #include "methods.inc" +#undef CASE case IpcId::Unknown: return "$unknown"; diff --git a/src/ipc.h b/src/ipc.h index 97813fba..55a1139a 100644 --- a/src/ipc.h +++ b/src/ipc.h @@ -10,59 +10,12 @@ using lsRequestId = std::variant; enum class IpcId : int { // Language server specific requests. CancelRequest = 0, - Initialize, Initialized, Exit, - Shutdown, - CodeLensResolve, - TextDocumentDidOpen, - TextDocumentDidChange, - TextDocumentDidClose, - TextDocumentDidSave, - TextDocumentPublishDiagnostics, - TextDocumentRename, - TextDocumentCompletion, - TextDocumentSignatureHelp, - TextDocumentDefinition, - TextDocumentDocumentHighlight, - TextDocumentHover, - TextDocumentFormatting, - TextDocumentRangeFormatting, - TextDocumentOnTypeFormatting, - TextDocumentReferences, - TextDocumentDocumentSymbol, - TextDocumentDocumentLink, - TextDocumentCodeAction, - TextDocumentCodeLens, - WorkspaceDidChangeConfiguration, - WorkspaceDidChangeWatchedFiles, - WorkspaceSymbol, - - // Custom notifications - // Comes from the client. Does various things, like update semantic - // highlighting. - CqueryTextDocumentDidView, - CqueryPublishInactiveRegions, - CqueryPublishSemanticHighlighting, - - // Custom messages - CqueryFileInfo, - CqueryFreshenIndex, - // Messages used in tree views. - CqueryCallHierarchy, - CqueryInheritanceHierarchy, - CqueryMemberHierarchy, - // cquery cross reference extension. - CqueryVars, // Show all variables of a type. - CqueryCallers, // Show all callers of a function. - CqueryBase, // Show base types/method. - CqueryDerived, // Show all derived types/methods. - CqueryRandom, // Show random definition. - - // Messages for testing. - CqueryIndexFile, // Index the given file contents. - CqueryWait, // Wait until all cquery threads are idle. +#define CASE(x, _) x, + #include "methods.inc" +#undef CASE // Internal implementation detail. Unknown, diff --git a/src/messages/text_document_type_definition.cc b/src/messages/text_document_type_definition.cc new file mode 100644 index 00000000..7899394a --- /dev/null +++ b/src/messages/text_document_type_definition.cc @@ -0,0 +1,29 @@ +#include "message_handler.h" +#include "query_utils.h" +#include "queue_manager.h" + +namespace { + +struct Ipc_TextDocumentTypeDefinition + : public RequestMessage { + const static IpcId kIpcId = IpcId::TextDocumentTypeDefinition; + lsTextDocumentPositionParams params; +}; +MAKE_REFLECT_STRUCT(Ipc_TextDocumentTypeDefinition, id, params); +REGISTER_IPC_MESSAGE(Ipc_TextDocumentTypeDefinition); + +struct Out_TextDocumentTypeDefinition + : public lsOutMessage { + lsRequestId id; + std::vector result; +}; +MAKE_REFLECT_STRUCT(Out_TextDocumentTypeDefinition, jsonrpc, id, result); + +struct TextDocumentTypeDefinitionHandler + : BaseMessageHandler { + void Run(Ipc_TextDocumentTypeDefinition* request) override { + } +}; +REGISTER_MESSAGE_HANDLER(TextDocumentTypeDefinitionHandler); + +} // namespace diff --git a/src/methods.inc b/src/methods.inc new file mode 100644 index 00000000..6b6662e7 --- /dev/null +++ b/src/methods.inc @@ -0,0 +1,59 @@ +// General +CASE(Initialize, "initialize") +CASE(Shutdown, "shutdown") + +CASE(CodeLensResolve, "codeLens/resolve") +CASE(TextDocumentCodeAction, "textDocument/codeAction") +CASE(TextDocumentCodeLens, "textDocument/codeLens") +CASE(TextDocumentCompletion, "textDocument/completion") +CASE(TextDocumentDefinition, "textDocument/definition") +CASE(TextDocumentDidChange, "textDocument/didChange") +CASE(TextDocumentDidClose, "textDocument/didClose") +CASE(TextDocumentDidOpen, "textDocument/didOpen") +CASE(TextDocumentDidSave, "textDocument/didSave") +CASE(TextDocumentDocumentHighlight, "textDocument/documentHighlight") +CASE(TextDocumentDocumentLink, "textDocument/documentLink") +CASE(TextDocumentDocumentSymbol, "textDocument/documentSymbol") +CASE(TextDocumentFormatting, "textDocument/formatting") +CASE(TextDocumentHover, "textDocument/hover") +CASE(TextDocumentOnTypeFormatting, "textDocument/onTypeFormatting") +CASE(TextDocumentPublishDiagnostics, "textDocument/publishDiagnostics") +CASE(TextDocumentRangeFormatting, "textDocument/rangeFormatting") +CASE(TextDocumentReferences, "textDocument/references") +CASE(TextDocumentRename, "textDocument/rename") +CASE(TextDocumentSignatureHelp, "textDocument/signatureHelp") +CASE(TextDocumentTypeDefinition, "textDocument/typeDefinition") +CASE(WorkspaceDidChangeConfiguration, "workspace/didChangeConfiguration") +CASE(WorkspaceDidChangeWatchedFiles, "workspace/didChangeWatchedFiles") +CASE(WorkspaceSymbol, "workspace/symbol") + +// Notification extensions +CASE(CqueryTextDocumentDidView, "$cquery/textDocumentDidView") +CASE(CqueryPublishInactiveRegions, "$cquery/publishInactiveRegions") +CASE(CqueryPublishSemanticHighlighting, "$cquery/publishSemanticHighlighting") + +// Request extensions +CASE(CqueryFileInfo, "$cquery/fileInfo") +CASE(CqueryFreshenIndex, "$cquery/freshenIndex") + +CASE(CqueryCallHierarchy, "$cquery/callHierarchy") +CASE(CqueryInheritanceHierarchy, "$cquery/inheritanceHierarchy") +CASE(CqueryMemberHierarchy, "$cquery/memberHierarchy") + +// Cross reference extensions. +// Show all variables of a type. +CASE(CqueryVars, "$cquery/vars") +// Show all callers of a function. +CASE(CqueryCallers, "$cquery/callers") +// Show base types/method. +CASE(CqueryBase, "$cquery/base") +// Show all derived types/methods. +CASE(CqueryDerived, "$cquery/derived") +// Show random definition. +CASE(CqueryRandom, "$cquery/random") + +// Messages for testing. +// Index the given file contents. +CASE(CqueryIndexFile, "$cquery/indexFile") +// Wait until all cquery threads are idle. +CASE(CqueryWait, "$cquery/wait")