Debian Codegraph @

LspCpp/include/LibLsp/JsonRpc/RequestInMessage.h

raw
1 #pragma once
2
3 #include "serializer.h"
4 #include <atomic>
5 #include <mutex>
6 #include "lsRequestId.h"
7 #include "LibLsp/JsonRpc/message.h"
8 #include "LibLsp/lsp/method_type.h"
9 #include "lsResponseMessage.h"
10
11 struct RequestInMessage : public LspMessage
12 {
13 // number or string, actually no null
14 lsRequestId id;
15 std::string method;
16 Kind GetKid() override
17 {
18 return REQUEST_MESSAGE;
19 }
20 };
21
22 template<class T, class TDerived>
23 struct lsRequest : public RequestInMessage
24 {
25 lsRequest(MethodType _method)
26 {
27 method = _method;
28 }
29 MethodType GetMethodType() const override
30 {
31 return method.c_str();
32 }
33 void SetMethodType(MethodType _method) override
34 {
35 method = _method;
36 }
37 void ReflectWriter(Writer& writer) override
38 {
39 Reflect(writer, static_cast<TDerived&>(*this));
40 }
41
42 static std::unique_ptr<LspMessage> ReflectReader(Reader& visitor)
43 {
44
45 TDerived* temp = new TDerived();
46 std::unique_ptr<TDerived> message = std::unique_ptr<TDerived>(temp);
47 // Reflect may throw and *message will be partially deserialized.
48 Reflect(visitor, static_cast<TDerived&>(*temp));
49 return message;
50 }
51 void swap(lsRequest& arg) noexcept
52 {
53 id.swap(arg.id);
54 method.swap(method);
55 std::swap(params, arg.params);
56 }
57 T params;
58 };
59
60 #define DEFINE_REQUEST_RESPONSE_TYPE(MSG, request_param, response_result, methodInfo) \
61 namespace MSG \
62 { \
63 struct response : public ResponseMessage<response_result, response> \
64 { \
65 }; \
66 struct request : public lsRequest<request_param, request> \
67 { \
68 static constexpr MethodType kMethodInfo = methodInfo; \
69 request() : lsRequest(kMethodInfo) \
70 { \
71 } \
72 using Response = response; \
73 }; \
74 }; \
75 MAKE_REFLECT_STRUCT(MSG::request, jsonrpc, id, method, params); \
76 MAKE_REFLECT_STRUCT(MSG::response, jsonrpc, id, result);