1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #include "documentsynchronization.h" |
6 | |
7 | namespace newlsp { |
8 | std::string toJsonValueStr(const DidOpenTextDocumentParams &val) |
9 | { |
10 | return {}; |
11 | } |
12 | |
13 | std::string toJsonValueStr(const DidChangeTextDocumentParams &val) |
14 | { |
15 | std::string ret; |
16 | ret = json::addValue(ret, json::KV{"textDocument" , val.textDocument}); |
17 | ret = json::addValue(ret, json::KV{"contentChanges" , val.contentChanges}); |
18 | return json::addScope(ret); |
19 | } |
20 | |
21 | std::string toJsonValueStr(const std::vector<TextDocumentContentChangeEvent> &val) |
22 | { |
23 | std::string ret; |
24 | if (val.size() < 0) |
25 | return ret; |
26 | |
27 | ret += "[" ; |
28 | int n = val.size(); |
29 | for (int i = 0; i < n; i++) { |
30 | ret += toJsonValueStr(val[i]); |
31 | if (i < n - 1) |
32 | ret += "," ; |
33 | } |
34 | ret += "]" ; |
35 | return ret; |
36 | } |
37 | |
38 | std::string toJsonValueStr(const TextDocumentContentChangeEvent &val) |
39 | { |
40 | std::string ret; |
41 | if (val.range) |
42 | ret = json::addValue(ret, json::KV{"range" , val.range}); |
43 | if (val.rangeLength) |
44 | ret = json::addValue(ret, json::KV{"rangeLength" , val.rangeLength}); |
45 | ret = json::addValue(ret , json::KV{"text" , val.text}); |
46 | return json::addScope(ret); |
47 | } |
48 | |
49 | std::string toJsonValueStr(const WillSaveTextDocumentParams &val) |
50 | { |
51 | std::string ret; |
52 | ret = json::addValue(ret, json::KV{"textDocument" , val.textDocument}); |
53 | ret = json::addValue(ret, json::KV{"reason" , val.reason}); |
54 | return json::addScope(ret); |
55 | } |
56 | |
57 | std::string toJsonValueStr(const SaveOptions &val) |
58 | { |
59 | std::string ret; |
60 | if (val.includeText) |
61 | ret = json::addValue(ret, json::KV{"includeText" , val.includeText}); |
62 | return json::addScope(ret); |
63 | } |
64 | |
65 | std::string toJsonValueStr(const TextDocumentRegistrationOptions &val) |
66 | { |
67 | std::string ret; |
68 | ret = json::addValue(ret, json::KV{"documentSelector" , val.documentSelector}); |
69 | return json::addScope(ret); |
70 | } |
71 | |
72 | std::string toJsonValueStr(const TextDocumentSaveRegistrationOptions &val) |
73 | { |
74 | //= json::delScope(TextDocumentRegistrationOptions::toJsonValueStr()); |
75 | std::string ret; |
76 | if (val.includeText) |
77 | ret = json::addValue(ret, json::KV{"includeText" , val.includeText}); |
78 | return json::addScope(ret); |
79 | } |
80 | |
81 | std::string toJsonValueStr(const DidSaveTextDocumentParams &val) |
82 | { |
83 | std::string ret; |
84 | ret = json::addValue(ret, json::KV{"textDocument" , val.textDocument}); |
85 | if (val.text) |
86 | ret = json::addValue(ret, json::KV{"text" , val.text}); |
87 | return json::addScope(ret); |
88 | } |
89 | |
90 | std::string toJsonValueStr(const DidCloseTextDocumentParams &val) |
91 | { |
92 | std::string ret; |
93 | ret = json::addValue(ret, json::KV{"textDocument" , val.textDocument}); |
94 | return json::addScope(ret); |
95 | } |
96 | |
97 | std::string toJsonValueStr(const TextDocumentSyncOptions &val) |
98 | { |
99 | std::string ret; |
100 | if (val.openClose) |
101 | ret = json::addValue(ret, json::KV{"openColse" , val.openClose}); |
102 | if (val.change) |
103 | ret = json::addValue(ret, json::KV{"change" , val.change}); |
104 | if (val.willSave) |
105 | ret = json::addValue(ret, json::KV{"willSave" , val.willSave}); |
106 | if (val.willSaveWaitUntil) |
107 | ret = json::addValue(ret, json::KV{"willSaveWaitUntil" , val.willSaveWaitUntil}); |
108 | if (val.save) { |
109 | if (any_contrast<SaveOptions>(val.save)) |
110 | ret = json::addValue(ret, json::KV{"save" , std::any_cast<SaveOptions>(val.save)}); |
111 | if (any_contrast<bool>(val.save)) |
112 | ret = json::addValue(ret, json::KV{"save" , std::any_cast<bool>(val.save)}); |
113 | } |
114 | return json::addScope(ret); |
115 | } |
116 | } // namespace newlsp |
117 | |