loom
41 строка · 1.6 Кб
1#include "SimodoCommand.h"
2#include "simodo/lsp-server/ServerContext.h"
3#include "simodo/lsp-server/DocumentContext.h"
4
5#include "simodo/variable/json/Rpc.h"
6#include "simodo/variable/json/Serialization.h"
7#include "simodo/inout/convert/functions.h"
8
9namespace simodo::lsp
10{
11
12void SimodoCommand::work()
13{
14if (_jsonrpc.is_valid()) {
15if (_jsonrpc.params().type() == variable::ValueType::Object) {
16
17std::shared_ptr<variable::Object> params_object = _jsonrpc.params().getObject();
18
19lsp::TextDocumentIdentifier doc_id;
20if (parseTextDocumentIdentifier(params_object->find(u"textDocument"), doc_id)) {
21DocumentContext * doc = _server.findDocument(doc_id.uri);
22if (doc) {
23const variable::Value & command_value = params_object->find(u"command");
24if (command_value.type() == variable::ValueType::String) {
25variable::Value result = doc->produceSimodoCommandResponse(command_value.getString());
26_server.sending().push(variable::JsonRpc(result, _jsonrpc.id()));
27return;
28}
29}
30}
31}
32}
33_server.log().error("There are wrong parameter structure of 'simodo/command' command",
34variable::toJson(_jsonrpc.value()));
35_server.sending().push(
36/// @todo Скорректировать коды (и тексты) ошибок
37variable::JsonRpc(-1,u"There are wrong parameter structure of 'simodo/command' command",
38_jsonrpc.id()));
39}
40
41}