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