loom
44 строки · 1.8 Кб
1#include "GotoDefinition.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 GotoDefinition::work()
13{
14if (_jsonrpc.is_valid()) {
15lsp::TextDocumentPositionParams doc_position;
16if (lsp::parseTextDocumentPositionParams(_jsonrpc.params(), doc_position)) {
17DocumentContext * doc = _server.findDocument(doc_position.textDocument.uri);
18if (doc) {
19variable::Value result = doc->produceGotoDefinitionResponse(doc_position.position);
20_server.sending().push(variable::JsonRpc(result, _jsonrpc.id()));
21return;
22}
23
24_server.log().error("'textDocument/definition' command: uri '"
25+ doc_position.textDocument.uri + "' don't loaded yet",
26variable::toJson(_jsonrpc.value()));
27_server.sending().push(
28/// @todo Скорректировать коды (и тексты) ошибок
29variable::JsonRpc(-1,
30u"'textDocument/definition' command: uri '"
31+ inout::toU16(doc_position.textDocument.uri) + u"' don't loaded yet",
32_jsonrpc.id()));
33return;
34}
35}
36_server.log().error("There are wrong parameter structure of 'textDocument/definition' command",
37variable::toJson(_jsonrpc.value()));
38_server.sending().push(
39/// @todo Скорректировать коды (и тексты) ошибок
40variable::JsonRpc(-1,u"There are wrong parameter structure of 'textDocument/definition' command",
41_jsonrpc.id()));
42}
43
44}