From 148a8b3f20a82a12b660c5dd6f1e30dc555cfafa Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 19 Jan 2018 00:47:52 -0800 Subject: [PATCH] Add {Request,Notification}Message --- src/ipc.h | 15 +++++++++++++++ src/language_server_api.h | 2 -- src/messages/text_document_definition.cc | 4 +--- src/messages/text_document_references.cc | 3 +-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/ipc.h b/src/ipc.h index 3ea9618a..98cc4555 100644 --- a/src/ipc.h +++ b/src/ipc.h @@ -5,6 +5,8 @@ #include +using lsRequestId = std::variant; + enum class IpcId : int { // Language server specific requests. CancelRequest = 0, @@ -84,3 +86,16 @@ template struct IpcMessage : public BaseIpcMessage { IpcMessage() : BaseIpcMessage(T::kIpcId) {} }; + +template +struct RequestMessage : public BaseIpcMessage { + // number | string, actually no null + lsRequestId id; + RequestMessage() : BaseIpcMessage(T::kIpcId) {} +}; + +// NotificationMessage does not have |id|. +template +struct NotificationMessage : public BaseIpcMessage { + NotificationMessage() : BaseIpcMessage(T::kIpcId) {} +}; diff --git a/src/language_server_api.h b/src/language_server_api.h index cadb8d24..896060e1 100644 --- a/src/language_server_api.h +++ b/src/language_server_api.h @@ -24,8 +24,6 @@ ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// -using lsRequestId = std::variant; - ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// diff --git a/src/messages/text_document_definition.cc b/src/messages/text_document_definition.cc index ccee686f..488ee8cc 100644 --- a/src/messages/text_document_definition.cc +++ b/src/messages/text_document_definition.cc @@ -9,10 +9,8 @@ void PushBack(std::vector* result, optional location) { } struct Ipc_TextDocumentDefinition - : public IpcMessage { + : public RequestMessage { const static IpcId kIpcId = IpcId::TextDocumentDefinition; - - lsRequestId id; lsTextDocumentPositionParams params; }; MAKE_REFLECT_STRUCT(Ipc_TextDocumentDefinition, id, params); diff --git a/src/messages/text_document_references.cc b/src/messages/text_document_references.cc index 86616ee7..6f4fa4d7 100644 --- a/src/messages/text_document_references.cc +++ b/src/messages/text_document_references.cc @@ -6,7 +6,7 @@ namespace { struct Ipc_TextDocumentReferences - : public IpcMessage { + : public RequestMessage { struct lsReferenceContext { // Include the declaration of the current symbol. bool includeDeclaration; @@ -19,7 +19,6 @@ struct Ipc_TextDocumentReferences const static IpcId kIpcId = IpcId::TextDocumentReferences; - lsRequestId id; lsReferenceParams params; }; MAKE_REFLECT_STRUCT(Ipc_TextDocumentReferences::lsReferenceContext,