Use X macros

This commit is contained in:
Fangrui Song 2018-03-01 19:07:44 -08:00
parent 0ba8f2a42c
commit 3e3bf885eb
5 changed files with 97 additions and 169 deletions

View File

@ -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);

View File

@ -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";

View File

@ -10,59 +10,12 @@ using lsRequestId = std::variant<std::monostate, int64_t, std::string>;
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,

View File

@ -0,0 +1,29 @@
#include "message_handler.h"
#include "query_utils.h"
#include "queue_manager.h"
namespace {
struct Ipc_TextDocumentTypeDefinition
: public RequestMessage<Ipc_TextDocumentTypeDefinition> {
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<Out_TextDocumentTypeDefinition> {
lsRequestId id;
std::vector<lsLocationEx> result;
};
MAKE_REFLECT_STRUCT(Out_TextDocumentTypeDefinition, jsonrpc, id, result);
struct TextDocumentTypeDefinitionHandler
: BaseMessageHandler<Ipc_TextDocumentTypeDefinition> {
void Run(Ipc_TextDocumentTypeDefinition* request) override {
}
};
REGISTER_MESSAGE_HANDLER(TextDocumentTypeDefinitionHandler);
} // namespace

59
src/methods.inc Normal file
View File

@ -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")