loom
40 строк · 1.3 Кб
1#include "simodo/lsp/client/TextDocumentPositionParamsParsers.h"
2#include "simodo/lsp/client/LocationParsers.h"
3
4#include "simodo/inout/convert/functions.h"
5
6namespace simodo::lsp
7{
8bool parseTextDocumentIdentifier(const variable::Value & textDocument_value,
9TextDocumentIdentifier & textDocument)
10{
11if (textDocument_value.type() != variable::ValueType::Object)
12return false;
13
14const variable::Value & uri_value = textDocument_value.getObject()->find(u"uri");
15if (uri_value.type() != variable::ValueType::String)
16return false;
17
18textDocument.uri = inout::toU8(uri_value.getString());
19
20return !textDocument.uri.empty();
21}
22
23bool parseTextDocumentPositionParams(const variable::Value & params_value,
24TextDocumentPositionParams & documentPosition)
25{
26if (params_value.type() != variable::ValueType::Object)
27return false;
28
29std::shared_ptr<variable::Object> params_object = params_value.getObject();
30
31if (!parseTextDocumentIdentifier(params_object->find(u"textDocument"), documentPosition.textDocument))
32return false;
33
34if (!parsePosition(params_object->find(u"position"), documentPosition.position))
35return false;
36
37return true;
38}
39
40}
41