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