| 1 |
#pragma once |
| 2 |
#include "serializer.h" |
| 3 |
#include "lsRequestId.h" |
| 4 |
#include "LibLsp/JsonRpc/message.h" |
| 5 |
#include "LibLsp/lsp/method_type.h" |
| 6 |
|
| 7 |
struct ResponseInMessage : public LspMessage |
| 8 |
{ |
| 9 |
|
| 10 |
lsRequestId id; |
| 11 |
std::string m_methodType; |
| 12 |
|
| 13 |
virtual MethodType GetMethodType() const override |
| 14 |
{ |
| 15 |
return m_methodType.data(); |
| 16 |
}; |
| 17 |
virtual void SetMethodType(MethodType _type) override |
| 18 |
{ |
| 19 |
m_methodType = _type; |
| 20 |
}; |
| 21 |
|
| 22 |
Kind GetKid() override |
| 23 |
{ |
| 24 |
return RESPONCE_MESSAGE; |
| 25 |
} |
| 26 |
virtual bool IsErrorType() |
| 27 |
{ |
| 28 |
return false; |
| 29 |
} |
| 30 |
}; |
| 31 |
template<class TDerived> |
| 32 |
struct BaseResponseMessage : ResponseInMessage |
| 33 |
{ |
| 34 |
|
| 35 |
void ReflectWriter(Writer& writer) override |
| 36 |
{ |
| 37 |
Reflect(writer, static_cast<TDerived&>(*this)); |
| 38 |
} |
| 39 |
static std::unique_ptr<LspMessage> ReflectReader(Reader& visitor) |
| 40 |
{ |
| 41 |
|
| 42 |
TDerived* temp = new TDerived(); |
| 43 |
std::unique_ptr<TDerived> message = std::unique_ptr<TDerived>(temp); |
| 44 |
// Reflect may throw and *message will be partially deserialized. |
| 45 |
Reflect(visitor, static_cast<TDerived&>(*temp)); |
| 46 |
return message; |
| 47 |
} |
| 48 |
}; |
| 49 |
|
| 50 |
template<class T, class TDerived> |
| 51 |
struct ResponseMessage : BaseResponseMessage<TDerived> |
| 52 |
{ |
| 53 |
T result; |
| 54 |
void swap(ResponseMessage<T, TDerived>& arg) noexcept |
| 55 |
{ |
| 56 |
std::swap(result, arg.result); |
| 57 |
this->id.swap(arg.id); |
| 58 |
this->m_methodType.swap(arg.m_methodType); |
| 59 |
} |
| 60 |
}; |
| 61 |
|
| 62 |
template<class T, class TDerived> |
| 63 |
struct ResponseError : BaseResponseMessage<TDerived> |
| 64 |
{ |
| 65 |
T error; |
| 66 |
bool IsErrorType() override |
| 67 |
{ |
| 68 |
return true; |
| 69 |
} |
| 70 |
void swap(ResponseError<T, TDerived>& arg) noexcept |
| 71 |
{ |
| 72 |
|
| 73 |
this->id.swap(arg.id); |
| 74 |
this->m_methodType.swap(arg.m_methodType); |
| 75 |
std::swap(error, arg.error); |
| 76 |
} |
| 77 |
}; |