loom
38 строк · 1.4 Кб
1#include "Initialize.h"
2#include "simodo/lsp/server/ServerContext.h"
3#include "simodo/lsp/client/ClientParamsParsers.h"
4
5#include "simodo/variable/json/Rpc.h"
6#include "simodo/variable/json/Serialization.h"
7
8namespace simodo::lsp
9{
10
11void Initialize::work()
12{
13if (_server.state() != ServerState::None || _jsonrpc.id() <= 0) {
14_server.log().critical("There are wrong parameter structure of 'initialize' command", variable::toJson(_jsonrpc.value()));
15/// @todo Скорректировать коды (и тексты) ошибок
16_server.sending().push(variable::JsonRpc(1, u"Invalid request", _jsonrpc.id()));
17return;
18}
19
20if (_jsonrpc.params().type() == variable::ValueType::Object) {
21const std::shared_ptr<variable::Object> params_object = _jsonrpc.params().getObject();
22
23_params = lsp::parseClientParams(params_object);
24}
25
26variable::JsonRpc server_response = _server.initialize(_params, _jsonrpc.id());
27
28if (!server_response.is_valid()) {
29_server.log().critical("Unable to create initialization structure", variable::toJson(_jsonrpc.value()));
30/// @todo Скорректировать коды (и тексты) ошибок
31_server.sending().push(variable::JsonRpc(3, u"Unable to create initialization structure", _jsonrpc.id()));
32return;
33}
34
35_server.sending().push(server_response);
36}
37
38}