Enable global/static registration for IpcMessage.

This commit is contained in:
Jacob Dufault 2017-12-05 20:05:01 -08:00
parent 9a3e040bf8
commit ad550f3f2c
2 changed files with 45 additions and 45 deletions

View File

@ -85,42 +85,39 @@ void EmitDiagnostics(WorkingFiles* working_files,
}); });
} }
void RegisterMessageTypes() { REGISTER_IPC_MESSAGE(Ipc_CancelRequest);
// TODO: use automatic registration similar to MessageHandler. REGISTER_IPC_MESSAGE(Ipc_InitializeRequest);
MessageRegistry::instance()->Register<Ipc_CancelRequest>(); REGISTER_IPC_MESSAGE(Ipc_InitializedNotification);
MessageRegistry::instance()->Register<Ipc_InitializeRequest>(); REGISTER_IPC_MESSAGE(Ipc_Exit);
MessageRegistry::instance()->Register<Ipc_InitializedNotification>(); REGISTER_IPC_MESSAGE(Ipc_TextDocumentDidOpen);
MessageRegistry::instance()->Register<Ipc_Exit>(); REGISTER_IPC_MESSAGE(Ipc_CqueryTextDocumentDidView);
MessageRegistry::instance()->Register<Ipc_TextDocumentDidOpen>(); REGISTER_IPC_MESSAGE(Ipc_TextDocumentDidChange);
MessageRegistry::instance()->Register<Ipc_CqueryTextDocumentDidView>(); REGISTER_IPC_MESSAGE(Ipc_TextDocumentDidClose);
MessageRegistry::instance()->Register<Ipc_TextDocumentDidChange>(); REGISTER_IPC_MESSAGE(Ipc_TextDocumentDidSave);
MessageRegistry::instance()->Register<Ipc_TextDocumentDidClose>(); REGISTER_IPC_MESSAGE(Ipc_TextDocumentRename);
MessageRegistry::instance()->Register<Ipc_TextDocumentDidSave>(); REGISTER_IPC_MESSAGE(Ipc_TextDocumentComplete);
MessageRegistry::instance()->Register<Ipc_TextDocumentRename>(); REGISTER_IPC_MESSAGE(Ipc_TextDocumentSignatureHelp);
MessageRegistry::instance()->Register<Ipc_TextDocumentComplete>(); REGISTER_IPC_MESSAGE(Ipc_TextDocumentDefinition);
MessageRegistry::instance()->Register<Ipc_TextDocumentSignatureHelp>(); REGISTER_IPC_MESSAGE(Ipc_TextDocumentDocumentHighlight);
MessageRegistry::instance()->Register<Ipc_TextDocumentDefinition>(); REGISTER_IPC_MESSAGE(Ipc_TextDocumentHover);
MessageRegistry::instance()->Register<Ipc_TextDocumentDocumentHighlight>(); REGISTER_IPC_MESSAGE(Ipc_TextDocumentReferences);
MessageRegistry::instance()->Register<Ipc_TextDocumentHover>(); REGISTER_IPC_MESSAGE(Ipc_TextDocumentDocumentSymbol);
MessageRegistry::instance()->Register<Ipc_TextDocumentReferences>(); REGISTER_IPC_MESSAGE(Ipc_TextDocumentDocumentLink);
MessageRegistry::instance()->Register<Ipc_TextDocumentDocumentSymbol>(); REGISTER_IPC_MESSAGE(Ipc_TextDocumentCodeAction);
MessageRegistry::instance()->Register<Ipc_TextDocumentDocumentLink>(); REGISTER_IPC_MESSAGE(Ipc_TextDocumentCodeLens);
MessageRegistry::instance()->Register<Ipc_TextDocumentCodeAction>(); REGISTER_IPC_MESSAGE(Ipc_CodeLensResolve);
MessageRegistry::instance()->Register<Ipc_TextDocumentCodeLens>(); REGISTER_IPC_MESSAGE(Ipc_WorkspaceSymbol);
MessageRegistry::instance()->Register<Ipc_CodeLensResolve>(); REGISTER_IPC_MESSAGE(Ipc_CqueryFreshenIndex);
MessageRegistry::instance()->Register<Ipc_WorkspaceSymbol>(); REGISTER_IPC_MESSAGE(Ipc_CqueryTypeHierarchyTree);
MessageRegistry::instance()->Register<Ipc_CqueryFreshenIndex>(); REGISTER_IPC_MESSAGE(Ipc_CqueryCallTreeInitial);
MessageRegistry::instance()->Register<Ipc_CqueryTypeHierarchyTree>(); REGISTER_IPC_MESSAGE(Ipc_CqueryCallTreeExpand);
MessageRegistry::instance()->Register<Ipc_CqueryCallTreeInitial>(); REGISTER_IPC_MESSAGE(Ipc_CqueryVars);
MessageRegistry::instance()->Register<Ipc_CqueryCallTreeExpand>(); REGISTER_IPC_MESSAGE(Ipc_CqueryCallers);
MessageRegistry::instance()->Register<Ipc_CqueryVars>(); REGISTER_IPC_MESSAGE(Ipc_CqueryBase);
MessageRegistry::instance()->Register<Ipc_CqueryCallers>(); REGISTER_IPC_MESSAGE(Ipc_CqueryDerived);
MessageRegistry::instance()->Register<Ipc_CqueryBase>(); REGISTER_IPC_MESSAGE(Ipc_CqueryIndexFile);
MessageRegistry::instance()->Register<Ipc_CqueryDerived>(); REGISTER_IPC_MESSAGE(Ipc_CqueryQueryDbWaitForIdleIndexer);
MessageRegistry::instance()->Register<Ipc_CqueryIndexFile>(); REGISTER_IPC_MESSAGE(Ipc_CqueryExitWhenIdle);
MessageRegistry::instance()->Register<Ipc_CqueryQueryDbWaitForIdleIndexer>();
MessageRegistry::instance()->Register<Ipc_CqueryExitWhenIdle>();
}
// Send indexing progress to client if reporting is enabled. // Send indexing progress to client if reporting is enabled.
void EmitProgress(Config* config, QueueManager* queue) { void EmitProgress(Config* config, QueueManager* queue) {
@ -1038,8 +1035,6 @@ int main(int argc, char** argv) {
PlatformInit(); PlatformInit();
IndexInit(); IndexInit();
RegisterMessageTypes();
std::unordered_map<std::string, std::string> options = std::unordered_map<std::string, std::string> options =
ParseOptions(argc, argv); ParseOptions(argc, argv);

View File

@ -40,6 +40,9 @@ void Reflect(Reader& visitor, lsRequestId& id);
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#define REGISTER_IPC_MESSAGE(type) \
static MessageRegistryRegister<type> type##message_handler_instance_;
struct MessageRegistry { struct MessageRegistry {
static MessageRegistry* instance_; static MessageRegistry* instance_;
static MessageRegistry* instance(); static MessageRegistry* instance();
@ -48,19 +51,21 @@ struct MessageRegistry {
std::function<std::unique_ptr<BaseIpcMessage>(Reader& visitor)>; std::function<std::unique_ptr<BaseIpcMessage>(Reader& visitor)>;
std::unordered_map<std::string, Allocator> allocators; std::unordered_map<std::string, Allocator> allocators;
template <typename T> std::unique_ptr<BaseIpcMessage> ReadMessageFromStdin(
void Register() { bool log_stdin_to_stderr);
std::unique_ptr<BaseIpcMessage> Parse(Reader& visitor);
};
template <typename T>
struct MessageRegistryRegister {
MessageRegistryRegister() {
std::string method_name = IpcIdToString(T::kIpcId); std::string method_name = IpcIdToString(T::kIpcId);
allocators[method_name] = [](Reader& visitor) { MessageRegistry::instance()->allocators[method_name] = [](Reader& visitor) {
auto result = MakeUnique<T>(); auto result = MakeUnique<T>();
Reflect(visitor, *result); Reflect(visitor, *result);
return result; return result;
}; };
} }
std::unique_ptr<BaseIpcMessage> ReadMessageFromStdin(
bool log_stdin_to_stderr);
std::unique_ptr<BaseIpcMessage> Parse(Reader& visitor);
}; };
struct lsBaseOutMessage { struct lsBaseOutMessage {