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