loom
52 строки · 2.3 Кб
1#include "SemanticTokens.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 SemanticTokens::work()
13{
14if (_jsonrpc.is_valid()) {
15const variable::Value & params_value = _jsonrpc.params();
16if (params_value.type() == variable::ValueType::Object) {
17std::string uri;
18std::shared_ptr<variable::Object> params_object = params_value.getObject();
19const variable::Value & textDocument_value = params_object->find(u"textDocument");
20if (textDocument_value.type() == variable::ValueType::Object) {
21const variable::Value & uri_value = textDocument_value.getObject()->find(u"uri");
22if (uri_value.type() == variable::ValueType::String)
23uri = inout::toU8(uri_value.getString());
24}
25
26if (!uri.empty()) {
27DocumentContext * doc = _server.findDocument(uri);
28if (doc) {
29variable::Value result = doc->produceSemanticTokensResponse();
30_server.sending().push(variable::JsonRpc(result, _jsonrpc.id()));
31return;
32}
33_server.log().error("'textDocument/semanticTokens' command: uri '" + uri + "' don't loaded yet",
34variable::toJson(_jsonrpc.value()));
35_server.sending().push(
36/// @todo Скорректировать коды (и тексты) ошибок
37variable::JsonRpc(-1,
38u"'textDocument/semanticTokens' command: uri '" + inout::toU16(uri) + u"' don't loaded yet",
39_jsonrpc.id()));
40return;
41}
42}
43}
44_server.log().error("There are wrong parameter structure of 'textDocument/semanticTokens' command",
45variable::toJson(_jsonrpc.value()));
46_server.sending().push(
47/// @todo Скорректировать коды (и тексты) ошибок
48variable::JsonRpc(-1,u"There are wrong parameter structure of 'textDocument/semanticTokens' command",
49_jsonrpc.id()));
50}
51
52}