blob: cdee9e572e7290ca6c3c73b609ec13d35ffc64e3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#pragma once
#include "lsRequestId.h"
#include "LibLsp/JsonRpc/message.h"
// NotificationInMessage does not have |id|.
struct NotificationInMessage : public LspMessage {
Kind GetKid() override
{
return NOTIFICATION_MESSAGE;
}
MethodType GetMethodType() const override
{
return method.c_str();
}
void SetMethodType(MethodType _t) override
{
method = _t;
}
std::string method;
};
template <class T, class TDerived >
struct lsNotificationInMessage : NotificationInMessage {
void ReflectWriter(Writer& writer) override {
Reflect(writer, static_cast<TDerived&>(*this));
}
lsNotificationInMessage(MethodType _method)
{
method = _method;
}
static std::unique_ptr<LspMessage> ReflectReader(Reader& visitor) {
TDerived* temp = new TDerived();
std::unique_ptr<TDerived> message = std::unique_ptr<TDerived>(temp);
// Reflect may throw and *message will be partially deserialized.
Reflect(visitor, static_cast<TDerived&>(*temp));
return message;
}
void swap(lsNotificationInMessage& arg) noexcept
{
method.swap(method);
std::swap(params, arg.params);
}
T params;
};
#define DEFINE_NOTIFICATION_TYPE(MSG,paramType,methodInfo)\
namespace MSG {\
struct notify : public lsNotificationInMessage< paramType , notify >{\
static constexpr MethodType kMethodInfo = methodInfo;\
notify():lsNotificationInMessage(kMethodInfo){} \
};\
};\
MAKE_REFLECT_STRUCT(MSG::notify, jsonrpc,method, params)
|