loom
76 строк · 2.8 Кб
1#include "simodo/lsp-client/SimodoCommandResult.h"
2
3#include "simodo/inout/convert/functions.h"
4
5namespace simodo::lsp
6{
7namespace
8{
9bool parseSimodoCommandReport(const variable::Value & report_value, SimodoCommandReport & report)
10{
11if (report_value.type() != variable::ValueType::Object)
12return false;
13
14std::shared_ptr<variable::Object> report_object = report_value.getObject();
15
16const variable::Value & id_value = report_object->find(u"id");
17const variable::Value & title_value = report_object->find(u"title");
18const variable::Value & type_value = report_object->find(u"type");
19const variable::Value & text_value = report_object->find(u"text");
20
21if (id_value.type() == variable::ValueType::String)
22report.id = id_value.getString();
23if (title_value.type() == variable::ValueType::String)
24report.title = title_value.getString();
25if (type_value.type() == variable::ValueType::Int)
26report.type = static_cast<SimodoCommandReportType>(type_value.getInt());
27if (text_value.type() == variable::ValueType::String)
28report.text = inout::decodeSpecialChars(text_value.getString());
29
30return true;
31}
32}
33
34std::vector<SimodoCommandReport> parseSimodoCommandResult(const variable::Value & result_value)
35{
36std::vector<SimodoCommandReport> res;
37
38if (result_value.type() == variable::ValueType::Object) {
39SimodoCommandReport report;
40if (parseSimodoCommandReport(result_value, report))
41res.push_back(report);
42return res;
43}
44
45if (result_value.type() != variable::ValueType::Array)
46return res;
47
48std::shared_ptr<variable::Array> result_array = result_value.getArray();
49
50for(const variable::Value & report_value : result_array->values()) {
51SimodoCommandReport report;
52if (parseSimodoCommandReport(report_value, report))
53res.push_back(report);
54}
55
56return res;
57}
58
59bool parseSimodoCommandResult(const simodo::variable::Value & result_value, SimodoCommandResult & result)
60{
61if (result_value.type() != variable::ValueType::Object)
62return false;
63
64std::shared_ptr<variable::Object> result_object = result_value.getObject();
65
66const variable::Value & uri_value = result_object->find(u"uri");
67const variable::Value & commandResult_value = result_object->find(u"commandResult");
68
69if (uri_value.type() == variable::ValueType::String)
70result.uri = uri_value.getString();
71
72result.commandResult = parseSimodoCommandResult(commandResult_value);
73
74return true;
75}
76}
77