loom
47 строк · 2.0 Кб
1#include "Completion.h"
2#include "simodo/lsp/server/ServerContext.h"
3#include "simodo/lsp/server/DocumentContext.h"
4
5#include "simodo/variable/json/Rpc.h"
6#include "simodo/variable/json/Serialization.h"
7#include "simodo/inout/convert/functions.h"
8#include "simodo/lsp/client/CompletionParamsParsers.h"
9#include "simodo/lsp/client/TextDocumentPositionParamsParsers.h"
10
11namespace simodo::lsp
12{
13
14void Completion::work()
15{
16if (_jsonrpc.is_valid()) {
17lsp::CompletionParams completionParams;
18if (lsp::parseTextDocumentPositionParams(_jsonrpc.params(), completionParams)
19&& lsp::parseCompletionParams(_jsonrpc.params(), completionParams)) {
20DocumentContext * doc = _server.findDocument(completionParams.textDocument.uri);
21if (doc) {
22variable::Value result = doc->produceCompletionResponse(completionParams);
23_server.sending().push(variable::JsonRpc(result, _jsonrpc.id()));
24return;
25}
26
27_server.log().error("'textDocument/completion' command: uri '"
28+ completionParams.textDocument.uri + "' don't loaded yet",
29variable::toJson(_jsonrpc.value()));
30_server.sending().push(
31/// @todo Скорректировать коды (и тексты) ошибок
32variable::JsonRpc(-1,
33u"'textDocument/completion' command: uri '"
34+ inout::toU16(completionParams.textDocument.uri) + u"' don't loaded yet",
35_jsonrpc.id()));
36return;
37}
38}
39_server.log().error("There are wrong parameter structure of 'textDocument/completion' command",
40variable::toJson(_jsonrpc.value()));
41_server.sending().push(
42/// @todo Скорректировать коды (и тексты) ошибок
43variable::JsonRpc(-1,u"There are wrong parameter structure of 'textDocument/completion' command",
44_jsonrpc.id()));
45}
46
47}