loom
39 строк · 1.3 Кб
1#include "simodo/lsp-client/CompletionParams.h"
2
3#include "simodo/inout/convert/functions.h"
4
5namespace simodo::lsp
6{
7
8bool parseCompletionContext(const simodo::variable::Value & context_value, CompletionContext & context)
9{
10if (context_value.type() != variable::ValueType::Object)
11return false;
12
13const std::shared_ptr<variable::Object> context_object = context_value.getObject();
14
15const variable::Value & triggerKind_value = context_object->find(u"triggerKind");
16const variable::Value & triggerCharacter_value = context_object->find(u"triggerCharacter");
17
18if (triggerKind_value.type() != variable::ValueType::Int
19|| triggerCharacter_value.type() != variable::ValueType::String)
20return false;
21
22context.triggerKind = static_cast<CompletionTriggerKind>(triggerKind_value.getInt());
23context.triggerCharacter = inout::toU8(triggerCharacter_value.getString());
24
25return true;
26}
27
28bool parseCompletionParams(const simodo::variable::Value & params, CompletionParams & completionParams)
29{
30if (params.type() != variable::ValueType::Object
31|| !parseTextDocumentPositionParams(params, completionParams))
32return false;
33
34const std::shared_ptr<variable::Object> params_object = params.getObject();
35
36return parseCompletionContext(params_object->find(u"context"), completionParams.context);
37}
38
39}
40