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