loom
85 строк · 3.0 Кб
1#include "simodo/lsp/client/ClientParamsParsers.h"
2
3#include "simodo/variable/Variable.h"
4#include "simodo/inout/convert/functions.h"
5
6using namespace simodo::inout;
7
8namespace simodo::lsp
9{
10
11ClientParams parseClientParams(std::shared_ptr<variable::Object> params_object)
12{
13ClientParams p;
14
15const variable::Value & processId_value = params_object->find(u"processId");
16if (processId_value.type() == variable::ValueType::Int)
17p.processId = processId_value.getInt();
18
19const variable::Value & locale_value = params_object->find(u"locale");
20if (locale_value.type() == variable::ValueType::String)
21p.locale = toU8(locale_value.getString());
22
23const variable::Value & rootPath_value = params_object->find(u"rootPath");
24if (rootPath_value.type() == variable::ValueType::String)
25p.rootPath = toU8(rootPath_value.getString());
26
27const variable::Value & rootUri_value = params_object->find(u"rootUri");
28if (rootUri_value.type() == variable::ValueType::String)
29p.rootUri = toU8(rootUri_value.getString());
30
31const variable::Value & capabilities_value = params_object->find(u"capabilities");
32if (capabilities_value.type() == variable::ValueType::Object)
33p.cap = parseClientCapabilities(capabilities_value.getObject());
34
35const variable::Value & trace_value = params_object->find(u"trace");
36if (trace_value.type() == variable::ValueType::String) {
37if (trace_value.getString() == u"messages")
38p.trace = TraceValue::messages;
39else if (trace_value.getString() == u"verbose")
40p.trace = TraceValue::verbose;
41}
42
43return p;
44}
45
46Capabilities parseClientCapabilities(std::shared_ptr<variable::Object> cap_object)
47{
48Capabilities cap;
49
50const variable::Value & textDocument_value = cap_object->find(u"textDocument");
51if (textDocument_value.type() == variable::ValueType::Object)
52cap.doc = parseTextDocument(textDocument_value.getObject());
53
54return cap;
55}
56
57TextDocument parseTextDocument(std::shared_ptr<variable::Object> doc_object)
58{
59TextDocument doc;
60
61const variable::Value & hover_value = doc_object->find(u"hover");
62if (hover_value.type() == variable::ValueType::Object)
63doc.hover = parseHoverClientCapabilities(hover_value.getObject());
64
65return doc;
66}
67
68HoverClientCapabilities parseHoverClientCapabilities(std::shared_ptr<simodo::variable::Object> hover_object)
69{
70HoverClientCapabilities hover;
71
72const variable::Value & dynamicRegistration_value = hover_object->find(u"dynamicRegistration");
73if (dynamicRegistration_value.type() == variable::ValueType::Bool)
74hover.dynamicRegistration = dynamicRegistration_value.getBool();
75
76const variable::Value & contentFormat_value = hover_object->find(u"contentFormat");
77if (contentFormat_value.type() == variable::ValueType::Array)
78for(const variable::Value & format_value : contentFormat_value.getArray()->values())
79if (format_value.type() == variable::ValueType::String)
80hover.contentFormat.insert(toU8(format_value.getString()));
81
82return hover;
83}
84
85}
86