Add {Request,Notification}Message

This commit is contained in:
Fangrui Song 2018-01-19 00:47:52 -08:00
parent 162f995344
commit 148a8b3f20
4 changed files with 17 additions and 7 deletions

View File

@ -5,6 +5,8 @@
#include <string> #include <string>
using lsRequestId = std::variant<std::monostate, int64_t, std::string>;
enum class IpcId : int { enum class IpcId : int {
// Language server specific requests. // Language server specific requests.
CancelRequest = 0, CancelRequest = 0,
@ -84,3 +86,16 @@ template <typename T>
struct IpcMessage : public BaseIpcMessage { struct IpcMessage : public BaseIpcMessage {
IpcMessage() : BaseIpcMessage(T::kIpcId) {} IpcMessage() : BaseIpcMessage(T::kIpcId) {}
}; };
template <typename T>
struct RequestMessage : public BaseIpcMessage {
// number | string, actually no null
lsRequestId id;
RequestMessage() : BaseIpcMessage(T::kIpcId) {}
};
// NotificationMessage does not have |id|.
template <typename T>
struct NotificationMessage : public BaseIpcMessage {
NotificationMessage() : BaseIpcMessage(T::kIpcId) {}
};

View File

@ -24,8 +24,6 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
using lsRequestId = std::variant<std::monostate, int64_t, std::string>;
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////

View File

@ -9,10 +9,8 @@ void PushBack(std::vector<lsLocation>* result, optional<lsLocation> location) {
} }
struct Ipc_TextDocumentDefinition struct Ipc_TextDocumentDefinition
: public IpcMessage<Ipc_TextDocumentDefinition> { : public RequestMessage<Ipc_TextDocumentDefinition> {
const static IpcId kIpcId = IpcId::TextDocumentDefinition; const static IpcId kIpcId = IpcId::TextDocumentDefinition;
lsRequestId id;
lsTextDocumentPositionParams params; lsTextDocumentPositionParams params;
}; };
MAKE_REFLECT_STRUCT(Ipc_TextDocumentDefinition, id, params); MAKE_REFLECT_STRUCT(Ipc_TextDocumentDefinition, id, params);

View File

@ -6,7 +6,7 @@
namespace { namespace {
struct Ipc_TextDocumentReferences struct Ipc_TextDocumentReferences
: public IpcMessage<Ipc_TextDocumentReferences> { : public RequestMessage<Ipc_TextDocumentReferences> {
struct lsReferenceContext { struct lsReferenceContext {
// Include the declaration of the current symbol. // Include the declaration of the current symbol.
bool includeDeclaration; bool includeDeclaration;
@ -19,7 +19,6 @@ struct Ipc_TextDocumentReferences
const static IpcId kIpcId = IpcId::TextDocumentReferences; const static IpcId kIpcId = IpcId::TextDocumentReferences;
lsRequestId id;
lsReferenceParams params; lsReferenceParams params;
}; };
MAKE_REFLECT_STRUCT(Ipc_TextDocumentReferences::lsReferenceContext, MAKE_REFLECT_STRUCT(Ipc_TextDocumentReferences::lsReferenceContext,