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