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 63 64 65 66 67 68 69 70
|
#pragma once
#include "serializer.h"
#include <atomic>
#include <mutex>
#include "lsRequestId.h"
#include "LibLsp/JsonRpc/message.h"
#include "LibLsp/lsp/method_type.h"
#include "lsResponseMessage.h"
struct RequestInMessage : public LspMessage {
// number or string, actually no null
lsRequestId id;
std::string method;
Kind GetKid() override
{
return REQUEST_MESSAGE;
}
};
template <class T, class TDerived >
struct lsRequest : public RequestInMessage
{
lsRequest(MethodType _method)
{
method = _method;
}
MethodType GetMethodType() const override { return method.c_str(); }
void SetMethodType(MethodType _method) override
{
method = _method;
} \
void ReflectWriter(Writer& writer) override {
Reflect(writer, static_cast<TDerived&>(*this));
}
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(lsRequest& arg) noexcept
{
id.swap(arg.id);
method.swap(method);
std::swap(params, arg.params);
}
T params;
};
#define DEFINE_REQUEST_RESPONSE_TYPE(MSG,request_param,response_result,methodInfo)\
namespace MSG {\
struct response :public ResponseMessage< response_result, response> {}; \
struct request : public lsRequest< request_param , request >{\
static constexpr MethodType kMethodInfo = methodInfo;\
request():lsRequest(kMethodInfo){} \
using Response = response;\
};\
};\
MAKE_REFLECT_STRUCT(MSG::request, jsonrpc, id, method, params);\
MAKE_REFLECT_STRUCT(MSG::response, jsonrpc, id, result);
|