1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25 
26 #pragma once
27 
28 #include "jsonrpcmessages.h"
29 
30 namespace LanguageServerProtocol {
31 
32 /**
33  * MarkedString can be used to render human readable text. It is either a markdown string
34  * or a code-block that provides a language and a code snippet. The language identifier
35  * is semantically equal to the optional language identifier in fenced code blocks in GitHub
36  * issues. See https://help.github.com/articles/creating-and-highlighting-code-blocks/#syntax-highlighting
37  *
38  * The pair of a language and a value is an equivalent to markdown:
39  * ```${language}
40  * ${value}
41  * ```
42  *
43  * Note that markdown strings will be sanitized - that means html will be escaped.
44 * @deprecated use MarkupContent instead.
45 */
46 class LANGUAGESERVERPROTOCOL_EXPORT MarkedLanguageString : public JsonObject
47 {
48 public:
49     using JsonObject::JsonObject;
50 
language()51     QString language() const { return typedValue<QString>(languageKey); }
setLanguage(const QString & language)52     void setLanguage(const QString &language) { insert(languageKey, language); }
53 
value()54     QString value() const { return typedValue<QString>(valueKey); }
setValue(const QString & value)55     void setValue(const QString &value) { insert(valueKey, value); }
56 
isValid()57     bool isValid() const override { return contains(languageKey) && contains(valueKey); }
58 };
59 
60 class LANGUAGESERVERPROTOCOL_EXPORT MarkedString
61     : public Utils::variant<QString, MarkedLanguageString>
62 {
63 public:
64     MarkedString() = default;
MarkedString(const MarkedLanguageString & other)65     explicit MarkedString(const MarkedLanguageString &other)
66         : variant(other)
67     {}
MarkedString(const QString & other)68     explicit MarkedString(const QString &other)
69         : variant(other)
70     {}
71     explicit MarkedString(const QJsonValue &value);
72 
73     bool isValid() const;
74     operator QJsonValue() const;
75 };
76 
77 class LANGUAGESERVERPROTOCOL_EXPORT HoverContent
78     : public Utils::variant<MarkedString, QList<MarkedString>, MarkupContent>
79 {
80 public:
81     HoverContent() = default;
HoverContent(const MarkedString & other)82     explicit HoverContent(const MarkedString &other) : variant(other) {}
HoverContent(const QList<MarkedString> & other)83     explicit HoverContent(const QList<MarkedString> &other) : variant(other) {}
HoverContent(const MarkupContent & other)84     explicit HoverContent(const MarkupContent &other) : variant(other) {}
85     explicit HoverContent(const QJsonValue &value);
86     bool isValid() const;
87 };
88 
89 class LANGUAGESERVERPROTOCOL_EXPORT Hover : public JsonObject
90 {
91 public:
92     using JsonObject::JsonObject;
93 
94     HoverContent content() const;
95     void setContent(const HoverContent &content);
96 
range()97     Utils::optional<Range> range() const { return optionalValue<Range>(rangeKey); }
setRange(const Range & range)98     void setRange(const Range &range) { insert(rangeKey, range); }
clearRange()99     void clearRange() { remove(rangeKey); }
100 
isValid()101     bool isValid() const override { return contains(contentsKey); }
102 };
103 
104 class LANGUAGESERVERPROTOCOL_EXPORT HoverRequest
105     : public Request<Hover, std::nullptr_t, TextDocumentPositionParams>
106 {
107 public:
108     explicit HoverRequest(const TextDocumentPositionParams &params);
109     using Request::Request;
110     constexpr static const char methodName[] = "textDocument/hover";
111 };
112 
113 /**
114  * Represents a parameter of a callable-signature. A parameter can
115  * have a label and a doc-comment.
116  */
117 class LANGUAGESERVERPROTOCOL_EXPORT ParameterInformation : public JsonObject
118 {
119 public:
120     using JsonObject::JsonObject;
121 
label()122     QString label() const { return typedValue<QString>(labelKey); }
setLabel(const QString & label)123     void setLabel(const QString &label) { insert(labelKey, label); }
124 
125     Utils::optional<MarkupOrString> documentation() const;
setDocumentation(const MarkupOrString & documentation)126     void setDocumentation(const MarkupOrString &documentation)
127     { insert(documentationKey, documentation.toJson()); }
clearDocumentation()128     void clearDocumentation() { remove(documentationKey); }
129 
isValid()130     bool isValid() const override { return contains(labelKey); }
131 };
132 
133 /**
134  * Represents the signature of something callable. A signature
135  * can have a label, like a function-name, a doc-comment, and
136  * a set of parameters.
137  */
138 class LANGUAGESERVERPROTOCOL_EXPORT SignatureInformation : public ParameterInformation
139 {
140 public:
141     using ParameterInformation::ParameterInformation;
142 
parameters()143     Utils::optional<QList<ParameterInformation>> parameters() const
144     { return optionalArray<ParameterInformation>(parametersKey); }
setParameters(const QList<ParameterInformation> & parameters)145     void setParameters(const QList<ParameterInformation> &parameters)
146     { insertArray(parametersKey, parameters); }
clearParameters()147     void clearParameters() { remove(parametersKey); }
148 };
149 
150 /**
151  * Signature help represents the signature of something
152  * callable. There can be multiple signature but only one
153  * active and only one active parameter.
154  */
155 class LANGUAGESERVERPROTOCOL_EXPORT SignatureHelp : public JsonObject
156 {
157 public:
158     using JsonObject::JsonObject;
159 
160     /// One or more signatures.
signatures()161     QList<SignatureInformation> signatures() const
162     { return array<SignatureInformation>(signaturesKey); }
setSignatures(const QList<SignatureInformation> & signatures)163     void setSignatures(const QList<SignatureInformation> &signatures)
164     { insertArray(signaturesKey, signatures); }
165 
166     /**
167      * The active signature. If omitted or the value lies outside the
168      * range of `signatures` the value defaults to zero or is ignored if
169      * `signatures.length === 0`. Whenever possible implementors should
170      * make an active decision about the active signature and shouldn't
171      * rely on a default value.
172      * In future version of the protocol this property might become
173      * mandatory to better express this.
174      */
activeSignature()175     Utils::optional<int> activeSignature() const { return optionalValue<int>(activeSignatureKey); }
setActiveSignature(int activeSignature)176     void setActiveSignature(int activeSignature) { insert(activeSignatureKey, activeSignature); }
clearActiveSignature()177     void clearActiveSignature() { remove(activeSignatureKey); }
178 
179     /**
180      * The active parameter of the active signature. If omitted or the value
181      * lies outside the range of `signatures[activeSignature].parameters`
182      * defaults to 0 if the active signature has parameters. If
183      * the active signature has no parameters it is ignored.
184      * In future version of the protocol this property might become
185      * mandatory to better express the active parameter if the
186      * active signature does have any.
187      */
activeParameter()188     Utils::optional<int> activeParameter() const { return optionalValue<int>(activeParameterKey); }
setActiveParameter(int activeParameter)189     void setActiveParameter(int activeParameter) { insert(activeParameterKey, activeParameter); }
clearActiveParameter()190     void clearActiveParameter() { remove(activeParameterKey); }
191 
isValid()192     bool isValid() const override { return contains(signaturesKey); }
193 };
194 
195 class LANGUAGESERVERPROTOCOL_EXPORT SignatureHelpRequest
196     : public Request<LanguageClientValue<SignatureHelp>, std::nullptr_t, TextDocumentPositionParams>
197 {
198 public:
199     explicit SignatureHelpRequest(const TextDocumentPositionParams &params);
200     using Request::Request;
201     constexpr static const char methodName[] = "textDocument/signatureHelp";
202 };
203 
204 /// The result of a goto request can either be a location, a list of locations or null
205 class LANGUAGESERVERPROTOCOL_EXPORT GotoResult
206         : public Utils::variant<Location, QList<Location>, std::nullptr_t>
207 {
208 public:
209     explicit GotoResult(const QJsonValue &value);
210     using variant::variant;
211 };
212 
213 class LANGUAGESERVERPROTOCOL_EXPORT GotoDefinitionRequest
214     : public Request<GotoResult, std::nullptr_t, TextDocumentPositionParams>
215 {
216 public:
217     explicit GotoDefinitionRequest(const TextDocumentPositionParams &params);
218     using Request::Request;
219     constexpr static const char methodName[] = "textDocument/definition";
220 };
221 
222 class LANGUAGESERVERPROTOCOL_EXPORT GotoTypeDefinitionRequest : public Request<
223         GotoResult, std::nullptr_t, TextDocumentPositionParams>
224 {
225 public:
226     explicit GotoTypeDefinitionRequest(const TextDocumentPositionParams &params);
227     using Request::Request;
228     constexpr static const char methodName[] = "textDocument/typeDefinition";
229 };
230 
231 class LANGUAGESERVERPROTOCOL_EXPORT GotoImplementationRequest : public Request<
232         GotoResult, std::nullptr_t, TextDocumentPositionParams>
233 {
234 public:
235     explicit GotoImplementationRequest(const TextDocumentPositionParams &params);
236     using Request::Request;
237     constexpr static const char methodName[] = "textDocument/implementation";
238 };
239 
240 class LANGUAGESERVERPROTOCOL_EXPORT ReferenceParams : public TextDocumentPositionParams
241 {
242 public:
243     using TextDocumentPositionParams::TextDocumentPositionParams;
244 
245     class ReferenceContext : public JsonObject
246     {
247     public:
ReferenceContext(bool includeDeclaration)248         explicit ReferenceContext(bool includeDeclaration)
249         { setIncludeDeclaration(includeDeclaration); }
250         ReferenceContext() = default;
251         using JsonObject::JsonObject;
includeDeclaration()252         bool includeDeclaration() const { return typedValue<bool>(includeDeclarationKey); }
setIncludeDeclaration(bool includeDeclaration)253         void setIncludeDeclaration(bool includeDeclaration)
254         { insert(includeDeclarationKey, includeDeclaration); }
255 
isValid()256         bool isValid() const override { return contains(includeDeclarationKey); }
257     };
258 
context()259     ReferenceContext context() const { return typedValue<ReferenceContext>(contextKey); }
setContext(const ReferenceContext & context)260     void setContext(const ReferenceContext &context) { insert(contextKey, context); }
261 
isValid()262     bool isValid() const override
263     { return TextDocumentPositionParams::isValid() && contains(contextKey); }
264 };
265 
266 class LANGUAGESERVERPROTOCOL_EXPORT FindReferencesRequest : public Request<
267         LanguageClientArray<Location>, std::nullptr_t, ReferenceParams>
268 {
269 public:
270     explicit FindReferencesRequest(const ReferenceParams &params);
271     using Request::Request;
272     constexpr static const char methodName[] = "textDocument/references";
273 };
274 
275 class LANGUAGESERVERPROTOCOL_EXPORT DocumentHighlight : public JsonObject
276 {
277 public:
278     using JsonObject::JsonObject;
279 
280     enum DocumentHighlightKind {
281         Text = 1,
282         Read = 2,
283         Write = 3
284     };
285 
range()286     Range range() const { return typedValue<Range>(rangeKey); }
setRange(const Range & range)287     void setRange(const Range &range) { insert(rangeKey, range); }
288 
kind()289     Utils::optional<int> kind() const { return optionalValue<int>(kindKey); }
setKind(int kind)290     void setKind(int kind) { insert(kindKey, kind); }
clearKind()291     void clearKind() { remove(kindKey); }
292 
isValid()293     bool isValid() const override { return contains(rangeKey); }
294 };
295 
296 class LANGUAGESERVERPROTOCOL_EXPORT DocumentHighlightsResult
297         : public Utils::variant<QList<DocumentHighlight>, std::nullptr_t>
298 {
299 public:
300     using variant::variant;
DocumentHighlightsResult()301     DocumentHighlightsResult() : variant(nullptr) {}
302     explicit DocumentHighlightsResult(const QJsonValue &value);
303     using variant::operator=;
304 };
305 
306 class LANGUAGESERVERPROTOCOL_EXPORT DocumentHighlightsRequest : public Request<
307         DocumentHighlightsResult, std::nullptr_t, TextDocumentPositionParams>
308 {
309 public:
310     explicit DocumentHighlightsRequest(const TextDocumentPositionParams &params);
311     using Request::Request;
312     constexpr static const char methodName[] = "textDocument/documentHighlight";
313 };
314 
315 class LANGUAGESERVERPROTOCOL_EXPORT TextDocumentParams : public JsonObject
316 {
317 public:
318     TextDocumentParams();
319     explicit TextDocumentParams(const TextDocumentIdentifier &identifier);
320     using JsonObject::JsonObject;
321 
textDocument()322     TextDocumentIdentifier textDocument() const
323     { return typedValue<TextDocumentIdentifier>(textDocumentKey); }
setTextDocument(const TextDocumentIdentifier & textDocument)324     void setTextDocument(const TextDocumentIdentifier &textDocument)
325     { insert(textDocumentKey, textDocument); }
326 
isValid()327     bool isValid() const override { return contains(textDocumentKey); }
328 };
329 
330 using DocumentSymbolParams = TextDocumentParams;
331 
332 class LANGUAGESERVERPROTOCOL_EXPORT DocumentSymbolsResult
333         : public Utils::variant<QList<SymbolInformation>, QList<DocumentSymbol>, std::nullptr_t>
334 {
335 public:
336     using variant::variant;
DocumentSymbolsResult()337     DocumentSymbolsResult() : variant(nullptr) {}
338     explicit DocumentSymbolsResult(const QJsonValue &value);
DocumentSymbolsResult(const DocumentSymbolsResult & other)339     DocumentSymbolsResult(const DocumentSymbolsResult &other) : variant(other) {}
DocumentSymbolsResult(DocumentSymbolsResult && other)340     DocumentSymbolsResult(DocumentSymbolsResult &&other) : variant(std::move(other)) {}
341 
342     using variant::operator=;
343     DocumentSymbolsResult &operator =(DocumentSymbolsResult &&other)
344     {
345         variant::operator=(std::move(other));
346         return *this;
347     }
348     DocumentSymbolsResult &operator =(const DocumentSymbolsResult &other)
349     {
350         variant::operator=(other);
351         return *this;
352     }
353     // Needed to make it usable in Qt 6 signals.
354     bool operator<(const DocumentSymbolsResult &other) const = delete;
355 };
356 
357 
358 class LANGUAGESERVERPROTOCOL_EXPORT DocumentSymbolsRequest
359         : public Request<DocumentSymbolsResult, std::nullptr_t, DocumentSymbolParams>
360 {
361 public:
362     explicit DocumentSymbolsRequest(const DocumentSymbolParams &params);
363     using Request::Request;
364     constexpr static const char methodName[] = "textDocument/documentSymbol";
365 };
366 
367 /**
368  * The kind of a code action.
369  *
370  * Kinds are a hierarchical list of identifiers separated by `.`, e.g. `"refactor.extract.function"`.
371  *
372  * The set of kinds is open and client needs to announce the kinds it supports to the server during
373  * initialization.
374  */
375 
376 using CodeActionKind = QString;
377 
378 /**
379  * A set of predefined code action kinds
380  */
381 
382 namespace CodeActionKinds {
383 constexpr char QuickFix[] = "quickfix";
384 constexpr char Refactor[] = "refactor";
385 constexpr char RefactorExtract[] = "refactor.extract";
386 constexpr char RefactorInline[] = "refactor.inline";
387 constexpr char RefactorRewrite[] = "refactor.rewrite";
388 constexpr char Source[] = "source";
389 constexpr char SourceOrganizeImports[] = "source.organizeImports";
390 }
391 
392 class LANGUAGESERVERPROTOCOL_EXPORT CodeActionParams : public JsonObject
393 {
394 public:
395     using JsonObject::JsonObject;
396 
397     class LANGUAGESERVERPROTOCOL_EXPORT CodeActionContext : public JsonObject
398     {
399     public:
400         using JsonObject::JsonObject;
401 
diagnostics()402         QList<Diagnostic> diagnostics() const { return array<Diagnostic>(diagnosticsKey); }
setDiagnostics(const QList<Diagnostic> & diagnostics)403         void setDiagnostics(const QList<Diagnostic> &diagnostics)
404         { insertArray(diagnosticsKey, diagnostics); }
405 
406         Utils::optional<QList<CodeActionKind>> only() const;
407         void setOnly(const QList<CodeActionKind> &only);
clearOnly()408         void clearOnly() { remove(onlyKey); }
409 
isValid()410         bool isValid() const override { return contains(diagnosticsKey); }
411     };
412 
textDocument()413     TextDocumentIdentifier textDocument() const
414     { return typedValue<TextDocumentIdentifier>(textDocumentKey); }
setTextDocument(const TextDocumentIdentifier & textDocument)415     void setTextDocument(const TextDocumentIdentifier &textDocument)
416     { insert(textDocumentKey, textDocument); }
417 
range()418     Range range() const { return typedValue<Range>(rangeKey); }
setRange(const Range & range)419     void setRange(const Range &range) { insert(rangeKey, range); }
420 
context()421     CodeActionContext context() const { return typedValue<CodeActionContext>(contextKey); }
setContext(const CodeActionContext & context)422     void setContext(const CodeActionContext &context) { insert(contextKey, context); }
423 
isValid()424     bool isValid() const override
425     { return contains(textDocumentKey) && contains(rangeKey) && contains(contextKey); }
426 };
427 
428 class LANGUAGESERVERPROTOCOL_EXPORT CodeAction : public JsonObject
429 {
430 public:
431     using JsonObject::JsonObject;
432 
title()433     QString title() const { return typedValue<QString>(titleKey); }
setTitle(QString title)434     void setTitle(QString title) { insert(titleKey, title); }
435 
kind()436     Utils::optional<CodeActionKind> kind() const { return optionalValue<CodeActionKind>(kindKey); }
setKind(const CodeActionKind & kind)437     void setKind(const CodeActionKind &kind) { insert(kindKey, kind); }
clearKind()438     void clearKind() { remove(kindKey); }
439 
diagnostics()440     Utils::optional<QList<Diagnostic>> diagnostics() const
441     { return optionalArray<Diagnostic>(diagnosticsKey); }
setDiagnostics(const QList<Diagnostic> & diagnostics)442     void setDiagnostics(const QList<Diagnostic> &diagnostics)
443     { insertArray(diagnosticsKey, diagnostics); }
clearDiagnostics()444     void clearDiagnostics() { remove(diagnosticsKey); }
445 
edit()446     Utils::optional<WorkspaceEdit> edit() const { return optionalValue<WorkspaceEdit>(editKey); }
setEdit(const WorkspaceEdit & edit)447     void setEdit(const WorkspaceEdit &edit) { insert(editKey, edit); }
clearEdit()448     void clearEdit() { remove(editKey); }
449 
command()450     Utils::optional<Command> command() const { return optionalValue<Command>(commandKey); }
setCommand(const Command & command)451     void setCommand(const Command &command) { insert(commandKey, command); }
clearCommand()452     void clearCommand() { remove(commandKey); }
453 
isValid()454     bool isValid() const override { return contains(titleKey); }
455 };
456 
457 class LANGUAGESERVERPROTOCOL_EXPORT CodeActionResult
458     : public Utils::variant<QList<Utils::variant<Command, CodeAction>>, std::nullptr_t>
459 {
460 public:
461     using variant::variant;
462     explicit CodeActionResult(const QJsonValue &val);
463 };
464 
465 class LANGUAGESERVERPROTOCOL_EXPORT CodeActionRequest : public Request<
466         CodeActionResult, std::nullptr_t, CodeActionParams>
467 {
468 public:
469     explicit CodeActionRequest(const CodeActionParams &params);
470     using Request::Request;
471     constexpr static const char methodName[] = "textDocument/codeAction";
472 };
473 
474 using CodeLensParams = TextDocumentParams;
475 
476 class LANGUAGESERVERPROTOCOL_EXPORT CodeLens : public JsonObject
477 {
478 public:
479     using JsonObject::JsonObject;
480 
range()481     Range range() const { return typedValue<Range>(rangeKey); }
setRange(const Range & range)482     void setRange(const Range &range) { insert(rangeKey, range); }
483 
command()484     Utils::optional<Command> command() const { return optionalValue<Command>(commandKey); }
setCommand(const Command & command)485     void setCommand(const Command &command) { insert(commandKey, command); }
clearCommand()486     void clearCommand() { remove(commandKey); }
487 
488     Utils::optional<QJsonValue> data() const;
setData(const QJsonValue & data)489     void setData(const QJsonValue &data) { insert(dataKey, data); }
clearData()490     void clearData() { remove(dataKey); }
491 
isValid()492     bool isValid() const override { return contains(rangeKey); }
493 };
494 
495 class LANGUAGESERVERPROTOCOL_EXPORT CodeLensRequest : public Request<
496         LanguageClientArray<CodeLens>, std::nullptr_t, CodeLensParams>
497 {
498 public:
499     explicit CodeLensRequest(const CodeLensParams &params);
500     using Request::Request;
501     constexpr static const char methodName[] = "textDocument/codeLens";
502 };
503 
504 class LANGUAGESERVERPROTOCOL_EXPORT CodeLensResolveRequest : public Request<
505         CodeLens, std::nullptr_t, CodeLens>
506 {
507 public:
508     explicit CodeLensResolveRequest(const CodeLens &params);
509     using Request::Request;
510     constexpr static const char methodName[] = "codeLens/resolve";
511 };
512 
513 class LANGUAGESERVERPROTOCOL_EXPORT DocumentLink : public JsonObject
514 {
515 public:
516     using JsonObject::JsonObject;
517 
range()518     Range range() const { return typedValue<Range>(rangeKey); }
setRange(const Range & range)519     void setRange(const Range &range) { insert(rangeKey, range); }
520 
521     Utils::optional<DocumentUri> target() const;
setTarget(const DocumentUri & target)522     void setTarget(const DocumentUri &target) { insert(targetKey, target.toString()); }
clearTarget()523     void clearTarget() { remove(targetKey); }
524 
525     Utils::optional<QJsonValue> data() const;
setData(const QJsonValue & data)526     void setData(const QJsonValue &data) { insert(dataKey, data); }
clearData()527     void clearData() { remove(dataKey); }
528 
isValid()529     bool isValid() const override { return contains(rangeKey); }
530 };
531 
532 using DocumentLinkParams = TextDocumentParams;
533 
534 class LANGUAGESERVERPROTOCOL_EXPORT DocumentLinkRequest : public Request<
535         LanguageClientValue<DocumentLink>, std::nullptr_t, DocumentLinkParams>
536 {
537 public:
538     explicit DocumentLinkRequest(const DocumentLinkParams &params);
539     using Request::Request;
540     constexpr static const char methodName[] = "textDocument/documentLink";
541 };
542 
543 class LANGUAGESERVERPROTOCOL_EXPORT DocumentLinkResolveRequest : public Request<
544         DocumentLink, std::nullptr_t, DocumentLink>
545 {
546 public:
547     explicit DocumentLinkResolveRequest(const DocumentLink &params);
548     using Request::Request;
549     constexpr static const char methodName[] = "documentLink/resolve";
550 };
551 
552 using DocumentColorParams = TextDocumentParams;
553 
554 class LANGUAGESERVERPROTOCOL_EXPORT Color : public JsonObject
555 {
556 public:
557     using JsonObject::JsonObject;
558 
red()559     double red() const { return typedValue<double>(redKey); }
setRed(double red)560     void setRed(double red) { insert(redKey, red); }
561 
green()562     double green() const { return typedValue<double>(greenKey); }
setGreen(double green)563     void setGreen(double green) { insert(greenKey, green); }
564 
blue()565     double blue() const { return typedValue<double>(blueKey); }
setBlue(double blue)566     void setBlue(double blue) { insert(blueKey, blue); }
567 
alpha()568     double alpha() const { return typedValue<double>(alphaKey); }
setAlpha(double alpha)569     void setAlpha(double alpha) { insert(alphaKey, alpha); }
570 
isValid()571     bool isValid() const override
572     { return contains(redKey) && contains(greenKey) && contains(blueKey) && contains(alphaKey); }
573 };
574 
575 class LANGUAGESERVERPROTOCOL_EXPORT ColorInformation : public JsonObject
576 {
577 public:
578     using JsonObject::JsonObject;
579 
range()580     Range range() const { return typedValue<Range>(rangeKey); }
setRange(Range range)581     void setRange(Range range) { insert(rangeKey, range); }
582 
color()583     Color color() const { return typedValue<Color>(colorKey); }
setColor(const Color & color)584     void setColor(const Color &color) { insert(colorKey, color); }
585 
isValid()586     bool isValid() const override { return contains(rangeKey) && contains(colorKey); }
587 };
588 
589 class LANGUAGESERVERPROTOCOL_EXPORT DocumentColorRequest : public Request<
590         QList<ColorInformation>, std::nullptr_t, DocumentColorParams>
591 {
592 public:
593     explicit DocumentColorRequest(const DocumentColorParams &params);
594     using Request::Request;
595     constexpr static const char methodName[] = "textDocument/documentColor";
596 };
597 
598 class LANGUAGESERVERPROTOCOL_EXPORT ColorPresentationParams : public JsonObject
599 {
600 public:
601     using JsonObject::JsonObject;
602 
textDocument()603     TextDocumentIdentifier textDocument() const
604     { return typedValue<TextDocumentIdentifier>(textDocumentKey); }
setTextDocument(const TextDocumentIdentifier & textDocument)605     void setTextDocument(const TextDocumentIdentifier &textDocument)
606     { insert(textDocumentKey, textDocument); }
607 
colorInfo()608     Color colorInfo() const { return typedValue<Color>(colorInfoKey); }
setColorInfo(const Color & colorInfo)609     void setColorInfo(const Color &colorInfo) { insert(colorInfoKey, colorInfo); }
610 
range()611     Range range() const { return typedValue<Range>(rangeKey); }
setRange(const Range & range)612     void setRange(const Range &range) { insert(rangeKey, range); }
613 
isValid()614     bool isValid() const override
615     { return contains(textDocumentKey) && contains(colorInfoKey) && contains(rangeKey); }
616 };
617 
618 class LANGUAGESERVERPROTOCOL_EXPORT ColorPresentation : public JsonObject
619 {
620 public:
621     using JsonObject::JsonObject;
622 
label()623     QString label() const { return typedValue<QString>(labelKey); }
setLabel(const QString & label)624     void setLabel(const QString &label) { insert(labelKey, label); }
625 
textEdit()626     Utils::optional<TextEdit> textEdit() const { return optionalValue<TextEdit>(textEditKey); }
setTextEdit(const TextEdit & textEdit)627     void setTextEdit(const TextEdit &textEdit) { insert(textEditKey, textEdit); }
clearTextEdit()628     void clearTextEdit() { remove(textEditKey); }
629 
additionalTextEdits()630     Utils::optional<QList<TextEdit>> additionalTextEdits() const
631     { return optionalArray<TextEdit>(additionalTextEditsKey); }
setAdditionalTextEdits(const QList<TextEdit> & additionalTextEdits)632     void setAdditionalTextEdits(const QList<TextEdit> &additionalTextEdits)
633     { insertArray(additionalTextEditsKey, additionalTextEdits); }
clearAdditionalTextEdits()634     void clearAdditionalTextEdits() { remove(additionalTextEditsKey); }
635 
isValid()636     bool isValid() const override { return contains(labelKey); }
637 };
638 
639 class LANGUAGESERVERPROTOCOL_EXPORT ColorPresentationRequest : public Request<
640         QList<ColorPresentation>, std::nullptr_t, ColorPresentationParams>
641 {
642 public:
643     explicit ColorPresentationRequest(const ColorPresentationParams &params);
644     using Request::Request;
645     constexpr static const char methodName[] = "textDocument/colorPresentation";
646 };
647 
648 class DocumentFormattingProperty : public Utils::variant<bool, double, QString>
649 {
650 public:
651     DocumentFormattingProperty() = default;
652     explicit DocumentFormattingProperty(const QJsonValue &value);
DocumentFormattingProperty(const DocumentFormattingProperty & other)653     explicit DocumentFormattingProperty(const DocumentFormattingProperty &other)
654         : Utils::variant<bool, double, QString>(other) {}
655 
656     using variant::variant;
657     using variant::operator=;
658 };
659 
660 class LANGUAGESERVERPROTOCOL_EXPORT FormattingOptions : public JsonObject
661 {
662 public:
663     using JsonObject::JsonObject;
664 
tabSize()665     int tabSize() const { return typedValue<int>(tabSizeKey); }
setTabSize(int tabSize)666     void setTabSize(int tabSize) { insert(tabSizeKey, tabSize); }
667 
insertSpace()668     bool insertSpace() const { return typedValue<bool>(insertSpaceKey); }
setInsertSpace(bool insertSpace)669     void setInsertSpace(bool insertSpace) { insert(insertSpaceKey, insertSpace); }
670 
trimTrailingWhitespace()671     Utils::optional<bool> trimTrailingWhitespace() const
672     { return optionalValue<bool>(trimTrailingWhitespaceKey); }
setTrimTrailingWhitespace(bool trimTrailingWhitespace)673     void setTrimTrailingWhitespace(bool trimTrailingWhitespace)
674     { insert(trimTrailingWhitespaceKey, trimTrailingWhitespace); }
clearTrimTrailingWhitespace()675     void clearTrimTrailingWhitespace() { remove(trimTrailingWhitespaceKey); }
676 
insertFinalNewline()677     Utils::optional<bool> insertFinalNewline() const
678     { return optionalValue<bool>(insertFinalNewlineKey); }
setInsertFinalNewline(bool insertFinalNewline)679     void setInsertFinalNewline(bool insertFinalNewline)
680     { insert(insertFinalNewlineKey, insertFinalNewline); }
clearInsertFinalNewline()681     void clearInsertFinalNewline() { remove(insertFinalNewlineKey); }
682 
trimFinalNewlines()683     Utils::optional<bool> trimFinalNewlines() const
684     { return optionalValue<bool>(trimFinalNewlinesKey); }
setTrimFinalNewlines(bool trimFinalNewlines)685     void setTrimFinalNewlines(bool trimFinalNewlines)
686     { insert(trimFinalNewlinesKey, trimFinalNewlines); }
clearTrimFinalNewlines()687     void clearTrimFinalNewlines() { remove(trimFinalNewlinesKey); }
688 
689     QHash<QString, DocumentFormattingProperty> properties() const;
690     void setProperty(const QString &key, const DocumentFormattingProperty &property);
removeProperty(const QString & key)691     void removeProperty(const QString &key) { remove(key); }
692 
isValid()693     bool isValid() const override { return contains(insertSpaceKey) && contains(tabSizeKey); }
694 };
695 
696 class LANGUAGESERVERPROTOCOL_EXPORT DocumentFormattingParams : public JsonObject
697 {
698 public:
699     using JsonObject::JsonObject;
700 
textDocument()701     TextDocumentIdentifier textDocument() const
702     { return typedValue<TextDocumentIdentifier>(textDocumentKey); }
setTextDocument(const TextDocumentIdentifier & textDocument)703     void setTextDocument(const TextDocumentIdentifier &textDocument)
704     { insert(textDocumentKey, textDocument); }
705 
options()706     FormattingOptions options() const { return typedValue<FormattingOptions>(optionsKey); }
setOptions(const FormattingOptions & options)707     void setOptions(const FormattingOptions &options) { insert(optionsKey, options); }
708 
isValid()709     bool isValid() const override { return contains(textDocumentKey) && contains(optionsKey); }
710 };
711 
712 class LANGUAGESERVERPROTOCOL_EXPORT DocumentFormattingRequest : public Request<
713         LanguageClientArray<TextEdit>, std::nullptr_t, DocumentFormattingParams>
714 {
715 public:
716     explicit DocumentFormattingRequest(const DocumentFormattingParams &params);
717     using Request::Request;
718     constexpr static const char methodName[] = "textDocument/formatting";
719 };
720 
721 class LANGUAGESERVERPROTOCOL_EXPORT DocumentRangeFormattingParams : public JsonObject
722 {
723 public:
724     using JsonObject::JsonObject;
725 
textDocument()726     TextDocumentIdentifier textDocument() const
727     { return typedValue<TextDocumentIdentifier>(textDocumentKey); }
setTextDocument(const TextDocumentIdentifier & textDocument)728     void setTextDocument(const TextDocumentIdentifier &textDocument)
729     { insert(textDocumentKey, textDocument); }
730 
range()731     Range range() const { return typedValue<Range>(rangeKey); }
setRange(const Range & range)732     void setRange(const Range &range) { insert(rangeKey, range); }
733 
options()734     FormattingOptions options() const { return typedValue<FormattingOptions>(optionsKey); }
setOptions(const FormattingOptions & options)735     void setOptions(const FormattingOptions &options) { insert(optionsKey, options); }
736 
isValid()737     bool isValid() const override
738     { return contains(textDocumentKey) && contains(rangeKey) && contains(optionsKey); }
739 };
740 
741 class LANGUAGESERVERPROTOCOL_EXPORT DocumentRangeFormattingRequest : public Request<
742         LanguageClientArray<TextEdit>, std::nullptr_t, DocumentRangeFormattingParams>
743 {
744 public:
745     explicit DocumentRangeFormattingRequest(const DocumentRangeFormattingParams &params);
746     using Request::Request;
747     constexpr static const char methodName[] = "textDocument/rangeFormatting";
748 };
749 
750 class LANGUAGESERVERPROTOCOL_EXPORT DocumentOnTypeFormattingParams : public JsonObject
751 {
752 public:
753     using JsonObject::JsonObject;
754 
textDocument()755     TextDocumentIdentifier textDocument() const
756     { return typedValue<TextDocumentIdentifier>(textDocumentKey); }
setTextDocument(const TextDocumentIdentifier & textDocument)757     void setTextDocument(const TextDocumentIdentifier &textDocument)
758     { insert(textDocumentKey, textDocument); }
759 
position()760     Position position() const { return typedValue<Position>(positionKey); }
setPosition(const Position & position)761     void setPosition(const Position &position) { insert(positionKey, position); }
762 
ch()763     QString ch() const { return typedValue<QString>(chKey); }
setCh(const QString & ch)764     void setCh(const QString &ch) { insert(chKey, ch); }
765 
options()766     FormattingOptions options() const { return typedValue<FormattingOptions>(optionsKey); }
setOptions(const FormattingOptions & options)767     void setOptions(const FormattingOptions &options) { insert(optionsKey, options); }
768 
769     bool isValid() const override;
770 };
771 
772 class LANGUAGESERVERPROTOCOL_EXPORT DocumentOnTypeFormattingRequest : public Request<
773         LanguageClientArray<TextEdit>, std::nullptr_t, DocumentOnTypeFormattingParams>
774 {
775 public:
776     explicit DocumentOnTypeFormattingRequest(const DocumentOnTypeFormattingParams &params);
777     using Request::Request;
778     constexpr static const char methodName[] = "textDocument/onTypeFormatting";
779 };
780 
781 class PlaceHolderResult : public JsonObject
782 {
783 public:
784     using JsonObject::JsonObject;
785 
range()786     Range range() const { return typedValue<Range>(rangeKey); }
setRange(const Range & range)787     void setRange(const Range &range) { insert(rangeKey, range); }
788 
placeHolder()789     QString placeHolder() const { return typedValue<QString>(placeHolderKey); }
setPlaceHolder(const QString & placeHolder)790     void setPlaceHolder(const QString &placeHolder) { insert(placeHolderKey, placeHolder); }
791 
isValid()792     bool isValid() const override { return contains(rangeKey); }
793 };
794 
795 class LANGUAGESERVERPROTOCOL_EXPORT PrepareRenameResult
796     : public Utils::variant<PlaceHolderResult, Range, std::nullptr_t>
797 {
798 public:
799     PrepareRenameResult();
800     PrepareRenameResult(const Utils::variant<PlaceHolderResult, Range, std::nullptr_t> &val);
801     explicit PrepareRenameResult(const PlaceHolderResult &val);
802     explicit PrepareRenameResult(const Range &val);
803     explicit PrepareRenameResult(const QJsonValue &val);
804 
805     bool isValid() const;
806 };
807 
808 class LANGUAGESERVERPROTOCOL_EXPORT PrepareRenameRequest
809     : public Request<PrepareRenameResult, std::nullptr_t, TextDocumentPositionParams>
810 {
811 public:
812     explicit PrepareRenameRequest(const TextDocumentPositionParams &params);
813     using Request::Request;
814     constexpr static const char methodName[] = "textDocument/prepareRename";
815 };
816 
817 class LANGUAGESERVERPROTOCOL_EXPORT RenameParams : public JsonObject
818 {
819 public:
820     using JsonObject::JsonObject;
821 
textDocument()822     TextDocumentIdentifier textDocument() const
823     { return typedValue<TextDocumentIdentifier>(textDocumentKey); }
setTextDocument(const TextDocumentIdentifier & textDocument)824     void setTextDocument(const TextDocumentIdentifier &textDocument)
825     { insert(textDocumentKey, textDocument); }
826 
position()827     Position position() const { return typedValue<Position>(positionKey); }
setPosition(const Position & position)828     void setPosition(const Position &position) { insert(positionKey, position); }
829 
newName()830     QString newName() const { return typedValue<QString>(newNameKey); }
setNewName(const QString & newName)831     void setNewName(const QString &newName) { insert(newNameKey, newName); }
832 
833     bool isValid() const override;
834 };
835 
836 class LANGUAGESERVERPROTOCOL_EXPORT RenameRequest : public Request<
837         WorkspaceEdit, std::nullptr_t, RenameParams>
838 {
839 public:
840     explicit RenameRequest(const RenameParams &params);
841     using Request::Request;
842     constexpr static const char methodName[] = "textDocument/rename";
843 };
844 
845 class LANGUAGESERVERPROTOCOL_EXPORT SemanticHighlightToken
846 {
847 public:
848     // Just accepts token with 8 bytes
849     explicit SemanticHighlightToken(const QByteArray &token);
850     SemanticHighlightToken() = default;
851 
852     void appendToByteArray(QByteArray &byteArray) const;
853 
854     quint32 character = 0;
855     quint16 length = 0;
856     quint16 scope = 0;
857 };
858 
859 class LANGUAGESERVERPROTOCOL_EXPORT SemanticHighlightingInformation : public JsonObject
860 {
861 public:
862     using JsonObject::JsonObject;
863 
line()864     int line() const { return typedValue<int>(lineKey); }
setLine(int line)865     void setLine(int line) { insert(lineKey, line); }
866 
867     Utils::optional<QList<SemanticHighlightToken>> tokens() const;
868     void setTokens(const QList<SemanticHighlightToken> &tokens);
clearTokens()869     void clearTokens() { remove(tokensKey); }
870 
isValid()871     bool isValid() const override { return contains(lineKey); }
872 };
873 
874 class LANGUAGESERVERPROTOCOL_EXPORT SemanticHighlightingParams : public JsonObject
875 {
876 public:
877     using JsonObject::JsonObject;
878 
879     Utils::variant<VersionedTextDocumentIdentifier, TextDocumentIdentifier> textDocument() const;
setTextDocument(const TextDocumentIdentifier & textDocument)880     void setTextDocument(const TextDocumentIdentifier &textDocument)
881     { insert(textDocumentKey, textDocument); }
setTextDocument(const VersionedTextDocumentIdentifier & textDocument)882     void setTextDocument(const VersionedTextDocumentIdentifier &textDocument)
883     { insert(textDocumentKey, textDocument); }
884 
lines()885     QList<SemanticHighlightingInformation> lines() const
886     { return array<SemanticHighlightingInformation>(linesKey); }
setLines(const QList<SemanticHighlightingInformation> & lines)887     void setLines(const QList<SemanticHighlightingInformation> &lines)
888     { insertArray(linesKey, lines); }
889 
isValid()890     bool isValid() const override { return contains(textDocumentKey) && contains(linesKey); }
891 };
892 
893 class LANGUAGESERVERPROTOCOL_EXPORT SemanticHighlightNotification
894     : public Notification<SemanticHighlightingParams>
895 {
896 public:
897     explicit SemanticHighlightNotification(const SemanticHighlightingParams &params);
898     using Notification::Notification;
899     constexpr static const char methodName[] = "textDocument/semanticHighlighting";
900 };
901 
902 } // namespace LanguageClient
903