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