1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #ifndef LANGUAGESERVERPROTOCOL_H |
6 | #define LANGUAGESERVERPROTOCOL_H |
7 | |
8 | #include "common/type/menuext.h" |
9 | |
10 | #include <QUrl> |
11 | #include <QString> |
12 | #include <QJsonValue> |
13 | #include <QProcess> |
14 | #include <QVector> |
15 | #include <QVariant> |
16 | |
17 | #include <any> |
18 | #include <variant> |
19 | #include <optional> |
20 | |
21 | namespace lsp { |
22 | |
23 | extern const QString K_ID; |
24 | extern const QString K_JSON_RPC; |
25 | extern const QString K_METHOD; |
26 | extern const QString K_RESULT; |
27 | extern const QString K_PARAMS; |
28 | extern const QString K_CAPABILITIES; |
29 | extern const QString K_TEXTDOCUMENT; |
30 | extern const QString K_DOCUMENTSYMBOL; |
31 | extern const QString K_HIERARCHICALDOCUMENTSYMBOLSUPPORT; |
32 | extern const QString K_PUBLISHDIAGNOSTICS; |
33 | extern const QString K_RELATEDINFOMATION; |
34 | extern const QString K_INITIALIZATIONOPTIONS; |
35 | extern const QString K_PROCESSID; |
36 | extern const QString K_ROOTPATH; |
37 | extern const QString K_ROOTURI; |
38 | extern const QString K_URI; // value QString from file url |
39 | extern const QString K_VERSION; // value int |
40 | extern const QString K_LANGUAGEID; |
41 | extern const QString K_TEXT; |
42 | extern const QString K_CONTAINERNAME; |
43 | extern const QString K_KIND; |
44 | extern const QString K_LOCATION; |
45 | extern const QString K_POSITION; |
46 | extern const QString K_DATA; |
47 | extern const QString K_NewName; |
48 | extern const QString K_NewText; |
49 | |
50 | extern const QString H_CONTENT_LENGTH; |
51 | extern const QString V_2_0; |
52 | extern const QString V_INITIALIZE; //has request result |
53 | extern const QString V_SHUTDOWN; //has request result |
54 | extern const QString V_EXIT; //has request result |
55 | extern const QString V_TEXTDOCUMENT_DIDOPEN; //no request result |
56 | extern const QString V_TEXTDOCUMENT_PUBLISHDIAGNOSTICS; //server call |
57 | extern const QString V_TEXTDOCUMENT_DIDCHANGE; //no request result, json error |
58 | extern const QString V_TEXTDOCUMENT_DOCUMENTSYMBOL; // has request result |
59 | extern const QString V_TEXTDOCUMENT_HOVER; // has request result |
60 | extern const QString V_TEXTDOCUMENT_RENAME; |
61 | extern const QString V_TEXTDOCUMENT_DEFINITION ; |
62 | extern const QString V_TEXTDOCUMENT_DIDCLOSE; |
63 | extern const QString V_TEXTDOCUMENT_COMPLETION; |
64 | extern const QString V_TEXTDOCUMENT_SIGNATUREHELP; |
65 | extern const QString V_TEXTDOCUMENT_REFERENCES; |
66 | extern const QString V_TEXTDOCUMENT_DOCUMENTHIGHLIGHT; |
67 | extern const QString V_TEXTDOCUMENT_SEMANTICTOKENS; |
68 | extern const QString V_TEXTDOCUMENT_SEMANTICTOKENS_FULL; |
69 | inline static QString V_TEXTDOCUMENT_DOCUMENTCOLOR{"textDocument/documentColor" }; |
70 | inline static QString V_TEXTDOCUMENT_FORMATTING{"textDocument/formatting" }; |
71 | inline static QString V_TEXTDOCUMENT_RANGEFORMATTING{"textDocument/rangeFormatting" }; |
72 | extern const QString K_WORKSPACEFOLDERS; |
73 | |
74 | extern const QString K_CONTENTCHANGES; |
75 | extern const QString K_DIAGNOSTICS; |
76 | extern const QString K_RANGE; |
77 | extern const QString K_MESSAGE; |
78 | extern const QString K_SEVERITY; |
79 | extern const QString K_END; |
80 | extern const QString K_START; |
81 | extern const QString K_CHARACTER; |
82 | extern const QString K_LINE; |
83 | extern const QString K_CONTEXT; |
84 | extern const QString K_INCLUDEDECLARATION; |
85 | |
86 | extern const QString K_ERROR; |
87 | extern const QString K_CODE; |
88 | |
89 | enum_def(SemanticTokenType, QString) |
90 | { |
91 | enum_exp Namespace = "namespace" ; |
92 | enum_exp Type = "type" ; |
93 | enum_exp Class = "class" ; |
94 | enum_exp Enum = "enum" ; |
95 | enum_exp Interface = "interface" ; |
96 | enum_exp Struct = "struct" ; |
97 | enum_exp TypeParameter = "typeParameter" ; |
98 | enum_exp Parameter = "parameter" ; |
99 | enum_exp Variable = "variable" ; |
100 | enum_exp Property = "property" ; |
101 | enum_exp EnumMember = "enumMember" ; |
102 | enum_exp Event = "event" ; |
103 | enum_exp Function = "function" ; |
104 | enum_exp Method = "method" ; |
105 | enum_exp Macro = "macro" ; |
106 | enum_exp Keyword = "keyword" ; |
107 | enum_exp Modifier = "modifier" ; |
108 | enum_exp = "comment" ; |
109 | enum_exp String = "string" ; |
110 | enum_exp Number = "number" ; |
111 | enum_exp Regexp = "regexp" ; |
112 | enum_exp Operator = "operator" ; |
113 | enum_exp Member = "member" ; |
114 | }; |
115 | |
116 | enum_def(SemanticTokenModifier, QString) |
117 | { |
118 | enum_exp Declaration = "declaration" ; //声明 |
119 | enum_exp Definition = "declaration" ; //定义 |
120 | enum_exp Readonly = "readonly" ; |
121 | enum_exp Static = "static" ; |
122 | enum_exp Deprecated = "deprecated" ; |
123 | enum_exp Abstract = "abstract" ; |
124 | enum_exp Async = "async" ; |
125 | enum_exp Modification = "modification" ; |
126 | enum_exp Documentation = "documentation" ; |
127 | enum_exp DefaultLibrary = "defaultLibrary" ; |
128 | }; |
129 | |
130 | struct Position |
131 | { |
132 | int line; |
133 | int character; |
134 | }; |
135 | |
136 | struct Range |
137 | { |
138 | Position start; |
139 | Position end; |
140 | }; |
141 | |
142 | typedef QUrl DocumentUri; |
143 | |
144 | struct Location |
145 | { |
146 | Range range; |
147 | QUrl fileUrl; |
148 | }; |
149 | struct Locations :public QList<Location>{}; |
150 | |
151 | struct DiagnosticRelatedInformation |
152 | { |
153 | Location location; |
154 | QString message; |
155 | }; |
156 | |
157 | struct Diagnostic |
158 | { |
159 | enum Severity{ |
160 | Unkown = 0, |
161 | Error = 1, |
162 | Warning = 2, |
163 | Info = 3, |
164 | Hint = 4, |
165 | }; |
166 | QString code; |
167 | QString message; |
168 | Range range; |
169 | QVector<DiagnosticRelatedInformation> relatedInfomation; |
170 | Severity severity; |
171 | QString source; |
172 | }; |
173 | struct Diagnostics : QVector<Diagnostic>{}; |
174 | |
175 | struct DiagnosticsParams |
176 | { |
177 | DocumentUri uri; |
178 | int version; |
179 | Diagnostics diagnostics; |
180 | }; |
181 | |
182 | struct Symbol |
183 | { |
184 | QString containerName; |
185 | int kind; |
186 | Location location; |
187 | QString name; |
188 | }; |
189 | typedef QList<Symbol> Symbols; |
190 | |
191 | enum InsertTextFormat |
192 | { |
193 | PlainText = 1, |
194 | Snippet = 2, |
195 | }; |
196 | |
197 | struct TextEdit |
198 | { |
199 | QString newText; |
200 | Range range; |
201 | }; |
202 | |
203 | struct AdditionalTextEdits:QList<TextEdit>{}; |
204 | |
205 | struct Documentation |
206 | { |
207 | QString kind; // markdown or plaintext |
208 | QString value; |
209 | }; |
210 | |
211 | struct CompletionItem |
212 | { |
213 | enum Kind { |
214 | Text = 1, |
215 | Method = 2, |
216 | Function = 3, |
217 | Constructor = 4, |
218 | Field = 5, |
219 | Variable = 6, |
220 | Class = 7, |
221 | Interface = 8, |
222 | Module = 9, |
223 | Property = 10, |
224 | Unit = 11, |
225 | Value = 12, |
226 | Enum = 13, |
227 | Keyword = 14, |
228 | Snippet = 15, |
229 | Color = 16, |
230 | File = 17, |
231 | Reference = 18, |
232 | Folder = 19, |
233 | EnumMember = 20, |
234 | Constant = 21, |
235 | Struct = 22, |
236 | Event = 23, |
237 | Operator = 24, |
238 | TypeParameter = 25 |
239 | }; |
240 | AdditionalTextEdits additionalTextEdits; |
241 | struct Documentation documentation; |
242 | QString filterText; |
243 | QString insertText; |
244 | InsertTextFormat insertTextFormat; |
245 | CompletionItem::Kind kind; |
246 | QString label; |
247 | double score; |
248 | QString sortText; |
249 | TextEdit textEdit; |
250 | }; |
251 | |
252 | struct CompletionItems : public QList<CompletionItem>{}; |
253 | |
254 | struct CompletionProvider |
255 | { |
256 | bool isIncomplete; |
257 | CompletionItems items; |
258 | }; |
259 | |
260 | struct SignatureHelp //暂时留空 |
261 | { |
262 | |
263 | }; |
264 | struct SignatureHelps : QList<SignatureHelp>{}; |
265 | |
266 | struct DefinitionProvider : public Locations{}; |
267 | |
268 | struct Contents |
269 | { |
270 | QString kind; |
271 | QString value; |
272 | }; |
273 | |
274 | struct Hover //暂时留空 |
275 | { |
276 | Contents contents; |
277 | Range range; |
278 | }; |
279 | |
280 | struct Highlight //暂时留空 |
281 | { |
282 | |
283 | }; |
284 | typedef QList<Highlight> Highlights; |
285 | |
286 | struct Data //from result key "data" |
287 | { |
288 | Position start; |
289 | int length; |
290 | int tokenType; |
291 | QList<int> tokenModifiers; |
292 | }; |
293 | |
294 | struct SemanticTokensProvider |
295 | { |
296 | struct Full{bool delta;}; |
297 | struct Legend{ |
298 | QStringList tokenTypes; |
299 | QStringList tokenModifiers; |
300 | }; |
301 | Full full; |
302 | Legend legend; |
303 | bool range; |
304 | }; |
305 | |
306 | enum TextDocumentSyncKind |
307 | { |
308 | None = 0, |
309 | Full = 1, |
310 | Incremental = 2 |
311 | }; |
312 | |
313 | struct TextDocumentSyncOptions |
314 | { |
315 | bool openColse; |
316 | TextDocumentSyncKind change; |
317 | }; |
318 | |
319 | struct TextDocumentIdentifier |
320 | { |
321 | QUrl documentUri; |
322 | }; |
323 | |
324 | struct VersionedTextDocumentIdentifier: public TextDocumentIdentifier |
325 | { |
326 | int version; |
327 | }; |
328 | |
329 | struct TextDocumentPositionParams |
330 | { |
331 | TextDocumentIdentifier textDocument; |
332 | Position position; |
333 | }; |
334 | |
335 | struct TextDocumentItem |
336 | { |
337 | QUrl DocumentUri; |
338 | QString languageId; |
339 | int version; |
340 | QString text; |
341 | }; |
342 | |
343 | struct TextDocumentContentChangeEvent |
344 | { |
345 | Range range; |
346 | int rangeLength; |
347 | QString text; |
348 | }; |
349 | |
350 | struct DidChangeTextDocumentParams |
351 | { |
352 | VersionedTextDocumentIdentifier textDocument; |
353 | QList<TextDocumentContentChangeEvent> contentChanges; |
354 | }; |
355 | |
356 | struct RenameChange : public TextDocumentIdentifier |
357 | { |
358 | AdditionalTextEdits edits; |
359 | }; |
360 | |
361 | struct References : public Locations{}; |
362 | |
363 | namespace new_initialize{ |
364 | |
365 | } |
366 | |
367 | typedef QVariant ProgressToken; // integer | string; |
368 | struct WorkDoneProgressParams |
369 | { |
370 | ProgressToken token; |
371 | std::any value; // any |
372 | }; |
373 | |
374 | struct WorkspaceEditClientCapabilities |
375 | { |
376 | struct changeAnnotationSupport{ |
377 | /** |
378 | * Whether the client groups edits with equal labels into tree nodes, |
379 | * for instance all edits labelled with "Changes in Strings" would |
380 | * be a tree node. |
381 | */ |
382 | std::optional<bool> groupsOnLabel; |
383 | }; |
384 | |
385 | // documentChanges?: boolean; |
386 | std::optional<bool> documentChanges; |
387 | // resourceOperations?: ResourceOperationKind[]; |
388 | std::optional<bool> resourceOperations; |
389 | // failureHandling?: FailureHandlingKind; |
390 | std::optional<int> failureHandling; |
391 | // normalizesLineEndings?: boolean; |
392 | std::optional<bool> normalizesLineEndings; |
393 | // changeAnnotationSupport?: {groupsOnLabel?: boolean;} |
394 | std::optional<changeAnnotationSupport> changeAnnotationSupport; |
395 | }; |
396 | |
397 | QString fromTokenType(SemanticTokenType type); |
398 | QString fromTokenModifier(SemanticTokenModifier modifier); |
399 | QList<int> fromTokenModifiers(int modifiers); |
400 | QJsonArray tokenTypes(); |
401 | QJsonArray tokenModifiers(); |
402 | |
403 | QJsonObject workspace(); |
404 | QJsonObject initialize(const QString &workspaceFolder, const QString &language, const QString &compile); |
405 | QJsonObject didOpen(const QString &filePath); |
406 | QJsonObject didChange(const QString &filePath, const QByteArray &text, int version); |
407 | QJsonObject didClose(const QString &filePath); |
408 | QJsonObject hover(const QString &filePath, const Position &pos); |
409 | QJsonObject symbol(const QString &filePath); |
410 | QJsonObject rename(const QString &filePath, const Position &pos, const QString &newName); |
411 | QJsonObject completion(const QString &filePath, const Position &pos); |
412 | QJsonObject definition(const QString &filePath, const Position &pos); |
413 | QJsonObject signatureHelp(const QString &filePath, const Position &pos); |
414 | QJsonObject references(const QString &filePath, const Position &pos); |
415 | QJsonObject documentHighlight(const QString &filePath, const Position &pos); |
416 | QJsonObject documentSemanticTokensFull(const QString &filePath); |
417 | QJsonObject documentSemanticTokensRange(const QString &filePath); |
418 | QJsonObject documentSemanticTokensDelta(const QString &filePath); |
419 | QJsonObject shutdown(); |
420 | QJsonObject exit(); |
421 | bool isRequestResult(const QJsonObject &object); |
422 | bool isRequestError(const QJsonObject &object); |
423 | |
424 | |
425 | } // namespace lsp |
426 | |
427 | |
428 | Q_DECLARE_METATYPE(lsp::Range) |
429 | |
430 | #endif // LANGUAGESERVERPROTOCOL_H |
431 | |