mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-19 12:05:50 +00:00
Enable global/static registration for IpcMessage.
This commit is contained in:
parent
9a3e040bf8
commit
ad550f3f2c
@ -85,42 +85,39 @@ void EmitDiagnostics(WorkingFiles* working_files,
|
||||
});
|
||||
}
|
||||
|
||||
void RegisterMessageTypes() {
|
||||
// TODO: use automatic registration similar to MessageHandler.
|
||||
MessageRegistry::instance()->Register<Ipc_CancelRequest>();
|
||||
MessageRegistry::instance()->Register<Ipc_InitializeRequest>();
|
||||
MessageRegistry::instance()->Register<Ipc_InitializedNotification>();
|
||||
MessageRegistry::instance()->Register<Ipc_Exit>();
|
||||
MessageRegistry::instance()->Register<Ipc_TextDocumentDidOpen>();
|
||||
MessageRegistry::instance()->Register<Ipc_CqueryTextDocumentDidView>();
|
||||
MessageRegistry::instance()->Register<Ipc_TextDocumentDidChange>();
|
||||
MessageRegistry::instance()->Register<Ipc_TextDocumentDidClose>();
|
||||
MessageRegistry::instance()->Register<Ipc_TextDocumentDidSave>();
|
||||
MessageRegistry::instance()->Register<Ipc_TextDocumentRename>();
|
||||
MessageRegistry::instance()->Register<Ipc_TextDocumentComplete>();
|
||||
MessageRegistry::instance()->Register<Ipc_TextDocumentSignatureHelp>();
|
||||
MessageRegistry::instance()->Register<Ipc_TextDocumentDefinition>();
|
||||
MessageRegistry::instance()->Register<Ipc_TextDocumentDocumentHighlight>();
|
||||
MessageRegistry::instance()->Register<Ipc_TextDocumentHover>();
|
||||
MessageRegistry::instance()->Register<Ipc_TextDocumentReferences>();
|
||||
MessageRegistry::instance()->Register<Ipc_TextDocumentDocumentSymbol>();
|
||||
MessageRegistry::instance()->Register<Ipc_TextDocumentDocumentLink>();
|
||||
MessageRegistry::instance()->Register<Ipc_TextDocumentCodeAction>();
|
||||
MessageRegistry::instance()->Register<Ipc_TextDocumentCodeLens>();
|
||||
MessageRegistry::instance()->Register<Ipc_CodeLensResolve>();
|
||||
MessageRegistry::instance()->Register<Ipc_WorkspaceSymbol>();
|
||||
MessageRegistry::instance()->Register<Ipc_CqueryFreshenIndex>();
|
||||
MessageRegistry::instance()->Register<Ipc_CqueryTypeHierarchyTree>();
|
||||
MessageRegistry::instance()->Register<Ipc_CqueryCallTreeInitial>();
|
||||
MessageRegistry::instance()->Register<Ipc_CqueryCallTreeExpand>();
|
||||
MessageRegistry::instance()->Register<Ipc_CqueryVars>();
|
||||
MessageRegistry::instance()->Register<Ipc_CqueryCallers>();
|
||||
MessageRegistry::instance()->Register<Ipc_CqueryBase>();
|
||||
MessageRegistry::instance()->Register<Ipc_CqueryDerived>();
|
||||
MessageRegistry::instance()->Register<Ipc_CqueryIndexFile>();
|
||||
MessageRegistry::instance()->Register<Ipc_CqueryQueryDbWaitForIdleIndexer>();
|
||||
MessageRegistry::instance()->Register<Ipc_CqueryExitWhenIdle>();
|
||||
}
|
||||
REGISTER_IPC_MESSAGE(Ipc_CancelRequest);
|
||||
REGISTER_IPC_MESSAGE(Ipc_InitializeRequest);
|
||||
REGISTER_IPC_MESSAGE(Ipc_InitializedNotification);
|
||||
REGISTER_IPC_MESSAGE(Ipc_Exit);
|
||||
REGISTER_IPC_MESSAGE(Ipc_TextDocumentDidOpen);
|
||||
REGISTER_IPC_MESSAGE(Ipc_CqueryTextDocumentDidView);
|
||||
REGISTER_IPC_MESSAGE(Ipc_TextDocumentDidChange);
|
||||
REGISTER_IPC_MESSAGE(Ipc_TextDocumentDidClose);
|
||||
REGISTER_IPC_MESSAGE(Ipc_TextDocumentDidSave);
|
||||
REGISTER_IPC_MESSAGE(Ipc_TextDocumentRename);
|
||||
REGISTER_IPC_MESSAGE(Ipc_TextDocumentComplete);
|
||||
REGISTER_IPC_MESSAGE(Ipc_TextDocumentSignatureHelp);
|
||||
REGISTER_IPC_MESSAGE(Ipc_TextDocumentDefinition);
|
||||
REGISTER_IPC_MESSAGE(Ipc_TextDocumentDocumentHighlight);
|
||||
REGISTER_IPC_MESSAGE(Ipc_TextDocumentHover);
|
||||
REGISTER_IPC_MESSAGE(Ipc_TextDocumentReferences);
|
||||
REGISTER_IPC_MESSAGE(Ipc_TextDocumentDocumentSymbol);
|
||||
REGISTER_IPC_MESSAGE(Ipc_TextDocumentDocumentLink);
|
||||
REGISTER_IPC_MESSAGE(Ipc_TextDocumentCodeAction);
|
||||
REGISTER_IPC_MESSAGE(Ipc_TextDocumentCodeLens);
|
||||
REGISTER_IPC_MESSAGE(Ipc_CodeLensResolve);
|
||||
REGISTER_IPC_MESSAGE(Ipc_WorkspaceSymbol);
|
||||
REGISTER_IPC_MESSAGE(Ipc_CqueryFreshenIndex);
|
||||
REGISTER_IPC_MESSAGE(Ipc_CqueryTypeHierarchyTree);
|
||||
REGISTER_IPC_MESSAGE(Ipc_CqueryCallTreeInitial);
|
||||
REGISTER_IPC_MESSAGE(Ipc_CqueryCallTreeExpand);
|
||||
REGISTER_IPC_MESSAGE(Ipc_CqueryVars);
|
||||
REGISTER_IPC_MESSAGE(Ipc_CqueryCallers);
|
||||
REGISTER_IPC_MESSAGE(Ipc_CqueryBase);
|
||||
REGISTER_IPC_MESSAGE(Ipc_CqueryDerived);
|
||||
REGISTER_IPC_MESSAGE(Ipc_CqueryIndexFile);
|
||||
REGISTER_IPC_MESSAGE(Ipc_CqueryQueryDbWaitForIdleIndexer);
|
||||
REGISTER_IPC_MESSAGE(Ipc_CqueryExitWhenIdle);
|
||||
|
||||
// Send indexing progress to client if reporting is enabled.
|
||||
void EmitProgress(Config* config, QueueManager* queue) {
|
||||
@ -1038,8 +1035,6 @@ int main(int argc, char** argv) {
|
||||
PlatformInit();
|
||||
IndexInit();
|
||||
|
||||
RegisterMessageTypes();
|
||||
|
||||
std::unordered_map<std::string, std::string> options =
|
||||
ParseOptions(argc, argv);
|
||||
|
||||
|
@ -40,6 +40,9 @@ void Reflect(Reader& visitor, lsRequestId& id);
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define REGISTER_IPC_MESSAGE(type) \
|
||||
static MessageRegistryRegister<type> type##message_handler_instance_;
|
||||
|
||||
struct MessageRegistry {
|
||||
static MessageRegistry* instance_;
|
||||
static MessageRegistry* instance();
|
||||
@ -48,19 +51,21 @@ struct MessageRegistry {
|
||||
std::function<std::unique_ptr<BaseIpcMessage>(Reader& visitor)>;
|
||||
std::unordered_map<std::string, Allocator> allocators;
|
||||
|
||||
template <typename T>
|
||||
void Register() {
|
||||
std::unique_ptr<BaseIpcMessage> ReadMessageFromStdin(
|
||||
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);
|
||||
allocators[method_name] = [](Reader& visitor) {
|
||||
MessageRegistry::instance()->allocators[method_name] = [](Reader& visitor) {
|
||||
auto result = MakeUnique<T>();
|
||||
Reflect(visitor, *result);
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
std::unique_ptr<BaseIpcMessage> ReadMessageFromStdin(
|
||||
bool log_stdin_to_stderr);
|
||||
std::unique_ptr<BaseIpcMessage> Parse(Reader& visitor);
|
||||
};
|
||||
|
||||
struct lsBaseOutMessage {
|
||||
|
Loading…
Reference in New Issue
Block a user