loom
61 строка · 2.0 Кб
1#include "simodo/lsp/client/LocationParsers.h"
2#include "simodo/variable/Variable.h"
3#include "simodo/inout/convert/functions.h"
4
5namespace simodo::lsp
6{
7bool parsePosition(const variable::Value & position_value, inout::Position & position)
8{
9if (position_value.type() != variable::ValueType::Object)
10return false;
11
12const variable::Value & line_value = position_value.getObject()->find(u"line");
13const variable::Value & character_value = position_value.getObject()->find(u"character");
14
15if (line_value.type() != variable::ValueType::Int
16|| character_value.type() != variable::ValueType::Int)
17return false;
18
19position = inout::Position(line_value.getInt(), character_value.getInt());
20
21return true;
22}
23
24bool parseRange(const variable::Value & range_value, inout::Range & range)
25{
26if (range_value.type() != variable::ValueType::Object)
27return false;
28
29inout::Position start, end;
30
31std::shared_ptr<variable::Object> range_object = range_value.getObject();
32if (!parsePosition(range_object->find(u"start"), start)
33|| !parsePosition(range_object->find(u"end"), end))
34return false;
35
36range = inout::Range(start, end);
37
38return true;
39}
40
41bool parseLocation(const variable::Value & location_value, inout::Location & location)
42{
43if (location_value.type() != variable::ValueType::Object)
44return false;
45
46std::shared_ptr<variable::Object> location_object = location_value.getObject();
47const variable::Value & uri_value = location_object->find(u"uri");
48if (uri_value.type() != variable::ValueType::String)
49return false;
50
51inout::Range range;
52
53if (!parseRange(location_object->find(u"range"), range))
54return false;
55
56location = inout::Location(inout::toU8(uri_value.getString()), range);
57
58return true;
59}
60
61}
62