LLVM 22.0.0git
Protocol.h
Go to the documentation of this file.
1//===--- Protocol.h - Language Server Protocol Implementation ---*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains structs based on the LSP specification at
10// https://microsoft.github.io/language-server-protocol/specification
11//
12// This is not meant to be a complete implementation, new interfaces are added
13// when they're needed.
14//
15// Each struct has a toJSON and fromJSON function, that converts between
16// the struct and a JSON representation. (See JSON.h)
17//
18// Some structs also have operator<< serialization. This is for debugging and
19// tests, and is not generally machine-readable.
20//
21//===----------------------------------------------------------------------===//
22
23#ifndef LLVM_SUPPORT_LSP_PROTOCOL_H
24#define LLVM_SUPPORT_LSP_PROTOCOL_H
25
27#include "llvm/Support/JSON.h"
31#include <bitset>
32#include <optional>
33#include <string>
34#include <utility>
35
36// This file is using the LSP syntax for identifier names which is different
37// from the LLVM coding standard. To avoid the clang-tidy warnings, we're
38// disabling one check here.
39// NOLINTBEGIN(readability-identifier-naming)
40
41namespace llvm {
42namespace lsp {
43
44enum class ErrorCode {
45 // Defined by JSON RPC.
46 ParseError = -32700,
49 InvalidParams = -32602,
50 InternalError = -32603,
51
54
55 // Defined by the protocol.
58 RequestFailed = -32803,
59};
60
61/// Defines how the host (editor) should sync document changes to the language
62/// server.
64 /// Documents should not be synced at all.
65 None = 0,
66
67 /// Documents are synced by always sending the full content of the document.
68 Full = 1,
69
70 /// Documents are synced by sending the full content on open. After that only
71 /// incremental updates to the document are sent.
73};
74
75//===----------------------------------------------------------------------===//
76// LSPError
77//===----------------------------------------------------------------------===//
78
79/// This class models an LSP error as an llvm::Error.
80class LSPError : public llvm::ErrorInfo<LSPError> {
81public:
82 std::string message;
84 LLVM_ABI_FOR_TEST static char ID;
85
88
89 void log(raw_ostream &os) const override {
90 os << int(code) << ": " << message;
91 }
92 std::error_code convertToErrorCode() const override {
94 }
95};
96
97//===----------------------------------------------------------------------===//
98// URIForFile
99//===----------------------------------------------------------------------===//
100
101/// URI in "file" scheme for a file.
103public:
104 URIForFile() = default;
105
106 /// Try to build a URIForFile from the given URI string.
108
109 /// Try to build a URIForFile from the given absolute file path and optional
110 /// scheme.
111 static llvm::Expected<URIForFile> fromFile(StringRef absoluteFilepath,
112 StringRef scheme = "file");
113
114 /// Returns the absolute path to the file.
115 StringRef file() const { return filePath; }
116
117 /// Returns the original uri of the file.
118 StringRef uri() const { return uriStr; }
119
120 /// Return the scheme of the uri.
121 StringRef scheme() const;
122
123 explicit operator bool() const { return !filePath.empty(); }
124
125 friend bool operator==(const URIForFile &lhs, const URIForFile &rhs) {
126 return lhs.filePath == rhs.filePath;
127 }
128 friend bool operator!=(const URIForFile &lhs, const URIForFile &rhs) {
129 return !(lhs == rhs);
130 }
131 friend bool operator<(const URIForFile &lhs, const URIForFile &rhs) {
132 return lhs.filePath < rhs.filePath;
133 }
134
135 /// Register a supported URI scheme. The protocol supports `file` by default,
136 /// so this is only necessary for any additional schemes that a server wants
137 /// to support.
139
140private:
141 explicit URIForFile(std::string &&filePath, std::string &&uriStr)
142 : filePath(std::move(filePath)), uriStr(uriStr) {}
143
144 std::string filePath;
145 std::string uriStr;
146};
147
148/// Add support for JSON serialization.
149LLVM_ABI_FOR_TEST llvm::json::Value toJSON(const URIForFile &value);
151 URIForFile &result, llvm::json::Path path);
152raw_ostream &operator<<(raw_ostream &os, const URIForFile &value);
153
154//===----------------------------------------------------------------------===//
155// ClientCapabilities
156//===----------------------------------------------------------------------===//
157
159 /// Client supports hierarchical document symbols.
160 /// textDocument.documentSymbol.hierarchicalDocumentSymbolSupport
162
163 /// Client supports CodeAction return value for textDocument/codeAction.
164 /// textDocument.codeAction.codeActionLiteralSupport.
166
167 /// Client supports server-initiated progress via the
168 /// window/workDoneProgress/create method.
169 ///
170 /// window.workDoneProgress
171 bool workDoneProgress = false;
172};
173
174/// Add support for JSON serialization.
176 ClientCapabilities &result,
178
179//===----------------------------------------------------------------------===//
180// ClientInfo
181//===----------------------------------------------------------------------===//
182
184 /// The name of the client as defined by the client.
185 std::string name;
186
187 /// The client's version as defined by the client.
188 std::optional<std::string> version;
189};
190
191/// Add support for JSON serialization.
194
195//===----------------------------------------------------------------------===//
196// InitializeParams
197//===----------------------------------------------------------------------===//
198
199enum class TraceLevel {
200 Off = 0,
203};
204
205/// Add support for JSON serialization.
208
210 /// The capabilities provided by the client (editor or tool).
212
213 /// Information about the client.
214 std::optional<ClientInfo> clientInfo;
215
216 /// The initial trace setting. If omitted trace is disabled ('off').
217 std::optional<TraceLevel> trace;
218};
219
220/// Add support for JSON serialization.
222 InitializeParams &result,
224
225//===----------------------------------------------------------------------===//
226// InitializedParams
227//===----------------------------------------------------------------------===//
228
229struct NoParams {};
231 return true;
232}
234
235//===----------------------------------------------------------------------===//
236// TextDocumentItem
237//===----------------------------------------------------------------------===//
238
240 /// The text document's URI.
242
243 /// The text document's language identifier.
244 std::string languageId;
245
246 /// The content of the opened text document.
247 std::string text;
248
249 /// The version number of this document.
250 int64_t version;
251};
252
253/// Add support for JSON serialization.
255 TextDocumentItem &result,
257
258//===----------------------------------------------------------------------===//
259// TextDocumentIdentifier
260//===----------------------------------------------------------------------===//
261
263 /// The text document's URI.
265};
266
267/// Add support for JSON serialization.
272
273//===----------------------------------------------------------------------===//
274// VersionedTextDocumentIdentifier
275//===----------------------------------------------------------------------===//
276
278 /// The text document's URI.
280 /// The version number of this document.
281 int64_t version;
282};
283
284/// Add support for JSON serialization.
290
291//===----------------------------------------------------------------------===//
292// Position
293//===----------------------------------------------------------------------===//
294
295struct Position {
296 Position(int line = 0, int character = 0)
298
299 /// Construct a position from the given source location.
301 std::pair<unsigned, unsigned> lineAndCol = mgr.getLineAndColumn(loc);
302 line = lineAndCol.first - 1;
303 character = lineAndCol.second - 1;
304 }
305
306 /// Line position in a document (zero-based).
307 int line = 0;
308
309 /// Character offset on a line in a document (zero-based).
310 int character = 0;
311
312 friend bool operator==(const Position &lhs, const Position &rhs) {
313 return std::tie(lhs.line, lhs.character) ==
314 std::tie(rhs.line, rhs.character);
315 }
316 friend bool operator!=(const Position &lhs, const Position &rhs) {
317 return !(lhs == rhs);
318 }
319 friend bool operator<(const Position &lhs, const Position &rhs) {
320 return std::tie(lhs.line, lhs.character) <
321 std::tie(rhs.line, rhs.character);
322 }
323 friend bool operator<=(const Position &lhs, const Position &rhs) {
324 return std::tie(lhs.line, lhs.character) <=
325 std::tie(rhs.line, rhs.character);
326 }
327
328 /// Convert this position into a source location in the main file of the given
329 /// source manager.
331 return mgr.FindLocForLineAndColumn(mgr.getMainFileID(), line + 1,
332 character + 1);
333 }
334};
335
336/// Add support for JSON serialization.
338 Position &result, llvm::json::Path path);
339LLVM_ABI_FOR_TEST llvm::json::Value toJSON(const Position &value);
340raw_ostream &operator<<(raw_ostream &os, const Position &value);
341
342//===----------------------------------------------------------------------===//
343// Range
344//===----------------------------------------------------------------------===//
345
346struct Range {
347 Range() = default;
349 Range(Position loc) : Range(loc, loc) {}
350
351 /// Construct a range from the given source range.
353 : Range(Position(mgr, range.Start), Position(mgr, range.End)) {}
354
355 /// The range's start position.
357
358 /// The range's end position.
360
361 friend bool operator==(const Range &lhs, const Range &rhs) {
362 return std::tie(lhs.start, lhs.end) == std::tie(rhs.start, rhs.end);
363 }
364 friend bool operator!=(const Range &lhs, const Range &rhs) {
365 return !(lhs == rhs);
366 }
367 friend bool operator<(const Range &lhs, const Range &rhs) {
368 return std::tie(lhs.start, lhs.end) < std::tie(rhs.start, rhs.end);
369 }
370
371 bool contains(Position pos) const { return start <= pos && pos < end; }
372 bool contains(Range range) const {
373 return start <= range.start && range.end <= end;
374 }
375
376 /// Convert this range into a source range in the main file of the given
377 /// source manager.
379 SMLoc startLoc = start.getAsSMLoc(mgr);
380 SMLoc endLoc = end.getAsSMLoc(mgr);
381 // Check that the start and end locations are valid.
382 if (!startLoc.isValid() || !endLoc.isValid() ||
383 startLoc.getPointer() > endLoc.getPointer())
384 return SMRange();
385 return SMRange(startLoc, endLoc);
386 }
387};
388
389/// Add support for JSON serialization.
390LLVM_ABI_FOR_TEST bool fromJSON(const llvm::json::Value &value, Range &result,
393raw_ostream &operator<<(raw_ostream &os, const Range &value);
394
395//===----------------------------------------------------------------------===//
396// Location
397//===----------------------------------------------------------------------===//
398
399struct Location {
400 Location() = default;
402
403 /// Construct a Location from the given source range.
406
407 /// The text document's URI.
410
411 friend bool operator==(const Location &lhs, const Location &rhs) {
412 return lhs.uri == rhs.uri && lhs.range == rhs.range;
413 }
414
415 friend bool operator!=(const Location &lhs, const Location &rhs) {
416 return !(lhs == rhs);
417 }
418
419 friend bool operator<(const Location &lhs, const Location &rhs) {
420 return std::tie(lhs.uri, lhs.range) < std::tie(rhs.uri, rhs.range);
421 }
422};
423
424/// Add support for JSON serialization.
426 Location &result, llvm::json::Path path);
427LLVM_ABI_FOR_TEST llvm::json::Value toJSON(const Location &value);
428raw_ostream &operator<<(raw_ostream &os, const Location &value);
429
430//===----------------------------------------------------------------------===//
431// TextDocumentPositionParams
432//===----------------------------------------------------------------------===//
433
435 /// The text document.
437
438 /// The position inside the text document.
440};
441
442/// Add support for JSON serialization.
446
447//===----------------------------------------------------------------------===//
448// ReferenceParams
449//===----------------------------------------------------------------------===//
450
452 /// Include the declaration of the current symbol.
453 bool includeDeclaration = false;
454};
455
456/// Add support for JSON serialization.
458 ReferenceContext &result,
460
464
465/// Add support for JSON serialization.
468
469//===----------------------------------------------------------------------===//
470// DidOpenTextDocumentParams
471//===----------------------------------------------------------------------===//
472
474 /// The document that was opened.
476};
477
478/// Add support for JSON serialization.
482
483//===----------------------------------------------------------------------===//
484// DidCloseTextDocumentParams
485//===----------------------------------------------------------------------===//
486
488 /// The document that was closed.
490};
491
492/// Add support for JSON serialization.
496
497//===----------------------------------------------------------------------===//
498// DidChangeTextDocumentParams
499//===----------------------------------------------------------------------===//
500
502 /// Try to apply this change to the given contents string.
503 LogicalResult applyTo(std::string &contents) const;
504 /// Try to apply a set of changes to the given contents string.
506 std::string &contents);
507
508 /// The range of the document that changed.
509 std::optional<Range> range;
510
511 /// The length of the range that got replaced.
512 std::optional<int> rangeLength;
513
514 /// The new text of the range/document.
515 std::string text;
516};
517
518/// Add support for JSON serialization.
522
524 /// The document that changed.
526
527 /// The actual content changes.
528 std::vector<TextDocumentContentChangeEvent> contentChanges;
529};
530
531/// Add support for JSON serialization.
535
536//===----------------------------------------------------------------------===//
537// MarkupContent
538//===----------------------------------------------------------------------===//
539
540/// Describes the content type that a client supports in various result literals
541/// like `Hover`.
546raw_ostream &operator<<(raw_ostream &os, MarkupKind kind);
547
552
553/// Add support for JSON serialization.
555
556//===----------------------------------------------------------------------===//
557// Hover
558//===----------------------------------------------------------------------===//
559
560struct Hover {
561 /// Construct a default hover with the given range that uses Markdown content.
563
564 /// The hover's content.
566
567 /// An optional range is a range inside a text document that is used to
568 /// visualize a hover, e.g. by changing the background color.
569 std::optional<Range> range;
570};
571
572/// Add support for JSON serialization.
574
575//===----------------------------------------------------------------------===//
576// SymbolKind
577//===----------------------------------------------------------------------===//
578
607
608//===----------------------------------------------------------------------===//
609// DocumentSymbol
610//===----------------------------------------------------------------------===//
611
612/// Represents programming constructs like variables, classes, interfaces etc.
613/// that appear in a document. Document symbols can be hierarchical and they
614/// have two ranges: one that encloses its definition and one that points to its
615/// most interesting range, e.g. the range of an identifier.
617 DocumentSymbol() = default;
623
624 /// The name of this symbol.
625 std::string name;
626
627 /// More detail for this symbol, e.g the signature of a function.
628 std::string detail;
629
630 /// The kind of this symbol.
632
633 /// The range enclosing this symbol not including leading/trailing whitespace
634 /// but everything else like comments. This information is typically used to
635 /// determine if the clients cursor is inside the symbol to reveal in the
636 /// symbol in the UI.
638
639 /// The range that should be selected and revealed when this symbol is being
640 /// picked, e.g the name of a function. Must be contained by the `range`.
642
643 /// Children of this symbol, e.g. properties of a class.
644 std::vector<DocumentSymbol> children;
645};
646
647/// Add support for JSON serialization.
649
650//===----------------------------------------------------------------------===//
651// DocumentSymbolParams
652//===----------------------------------------------------------------------===//
653
655 // The text document to find symbols in.
657};
658
659/// Add support for JSON serialization.
661 DocumentSymbolParams &result,
663
664//===----------------------------------------------------------------------===//
665// DiagnosticRelatedInformation
666//===----------------------------------------------------------------------===//
667
668/// Represents a related message and source code location for a diagnostic.
669/// This should be used to point to code locations that cause or related to a
670/// diagnostics, e.g. when duplicating a symbol in a scope.
675
676 /// The location of this related diagnostic information.
678 /// The message of this related diagnostic information.
679 std::string message;
680};
681
682/// Add support for JSON serialization.
688
689//===----------------------------------------------------------------------===//
690// Diagnostic
691//===----------------------------------------------------------------------===//
692
694 /// It is up to the client to interpret diagnostics as error, warning, info or
695 /// hint.
697 Error = 1,
701};
702
703enum class DiagnosticTag {
706};
707
708/// Add support for JSON serialization.
712
714 /// The source range where the message applies.
716
717 /// The diagnostic's severity. Can be omitted. If omitted it is up to the
718 /// client to interpret diagnostics as error, warning, info or hint.
720
721 /// A human-readable string describing the source of this diagnostic, e.g.
722 /// 'typescript' or 'super lint'.
723 std::string source;
724
725 /// The diagnostic's message.
726 std::string message;
727
728 /// An array of related diagnostic information, e.g. when symbol-names within
729 /// a scope collide all definitions can be marked via this property.
730 std::optional<std::vector<DiagnosticRelatedInformation>> relatedInformation;
731
732 /// Additional metadata about the diagnostic.
733 std::vector<DiagnosticTag> tags;
734
735 /// The diagnostic's category. Can be omitted.
736 /// An LSP extension that's used to send the name of the category over to the
737 /// client. The category typically describes the compilation stage during
738 /// which the issue was produced, e.g. "Semantic Issue" or "Parse Issue".
739 std::optional<std::string> category;
740};
741
742/// Add support for JSON serialization.
746
747//===----------------------------------------------------------------------===//
748// PublishDiagnosticsParams
749//===----------------------------------------------------------------------===//
750
754
755 /// The URI for which diagnostic information is reported.
757 /// The list of reported diagnostics.
758 std::vector<Diagnostic> diagnostics;
759 /// The version number of the document the diagnostics are published for.
760 int64_t version;
761};
762
763/// Add support for JSON serialization.
765toJSON(const PublishDiagnosticsParams &params);
766
767//===----------------------------------------------------------------------===//
768// TextEdit
769//===----------------------------------------------------------------------===//
770
771struct TextEdit {
772 /// The range of the text document to be manipulated. To insert
773 /// text into a document create a range where start === end.
775
776 /// The string to be inserted. For delete operations use an
777 /// empty string.
778 std::string newText;
779};
780
781inline bool operator==(const TextEdit &lhs, const TextEdit &rhs) {
782 return std::tie(lhs.newText, lhs.range) == std::tie(rhs.newText, rhs.range);
783}
784
786 TextEdit &result, llvm::json::Path path);
787LLVM_ABI_FOR_TEST llvm::json::Value toJSON(const TextEdit &value);
788raw_ostream &operator<<(raw_ostream &os, const TextEdit &value);
789
790//===----------------------------------------------------------------------===//
791// CompletionItemKind
792//===----------------------------------------------------------------------===//
793
794/// The kind of a completion entry.
824 CompletionItemKind &result,
826
828 static_cast<size_t>(CompletionItemKind::Text);
830 static_cast<size_t>(CompletionItemKind::TypeParameter);
831using CompletionItemKindBitset = std::bitset<kCompletionItemKindMax + 1>;
835
838 CompletionItemKindBitset &supportedCompletionItemKinds);
839
840//===----------------------------------------------------------------------===//
841// CompletionItem
842//===----------------------------------------------------------------------===//
843
844/// Defines whether the insert text in a completion item should be interpreted
845/// as plain text or a snippet.
848 /// The primary text to be inserted is treated as a plain string.
850 /// The primary text to be inserted is treated as a snippet.
851 ///
852 /// A snippet can define tab stops and placeholders with `$1`, `$2`
853 /// and `${3:foo}`. `$0` defines the final tab stop, it defaults to the end
854 /// of the snippet. Placeholders with equal identifiers are linked, that is
855 /// typing in one will update others too.
856 ///
857 /// See also:
858 /// https//github.com/Microsoft/vscode/blob/master/src/vs/editor/contrib/snippet/common/snippet.md
860};
861
863 CompletionItem() = default;
868
869 /// The label of this completion item. By default also the text that is
870 /// inserted when selecting this completion.
871 std::string label;
872
873 /// The kind of this completion item. Based of the kind an icon is chosen by
874 /// the editor.
876
877 /// A human-readable string with additional information about this item, like
878 /// type or symbol information.
879 std::string detail;
880
881 /// A human-readable string that represents a doc-comment.
882 std::optional<MarkupContent> documentation;
883
884 /// A string that should be used when comparing this item with other items.
885 /// When `falsy` the label is used.
886 std::string sortText;
887
888 /// A string that should be used when filtering a set of completion items.
889 /// When `falsy` the label is used.
890 std::string filterText;
891
892 /// A string that should be inserted to a document when selecting this
893 /// completion. When `falsy` the label is used.
894 std::string insertText;
895
896 /// The format of the insert text. The format applies to both the `insertText`
897 /// property and the `newText` property of a provided `textEdit`.
899
900 /// An edit which is applied to a document when selecting this completion.
901 /// When an edit is provided `insertText` is ignored.
902 ///
903 /// Note: The range of the edit must be a single line range and it must
904 /// contain the position at which completion has been requested.
905 std::optional<TextEdit> textEdit;
906
907 /// An optional array of additional text edits that are applied when selecting
908 /// this completion. Edits must not overlap with the main edit nor with
909 /// themselves.
910 std::vector<TextEdit> additionalTextEdits;
911
912 /// Indicates if this item is deprecated.
913 bool deprecated = false;
914};
915
916/// Add support for JSON serialization.
919bool operator<(const CompletionItem &lhs, const CompletionItem &rhs);
920
921//===----------------------------------------------------------------------===//
922// CompletionList
923//===----------------------------------------------------------------------===//
924
925/// Represents a collection of completion items to be presented in the editor.
927 /// The list is not complete. Further typing should result in recomputing the
928 /// list.
929 bool isIncomplete = false;
930
931 /// The completion items.
932 std::vector<CompletionItem> items;
933};
934
935/// Add support for JSON serialization.
937
938//===----------------------------------------------------------------------===//
939// CompletionContext
940//===----------------------------------------------------------------------===//
941
943 /// Completion was triggered by typing an identifier (24x7 code
944 /// complete), manual invocation (e.g Ctrl+Space) or via API.
946
947 /// Completion was triggered by a trigger character specified by
948 /// the `triggerCharacters` properties of the `CompletionRegistrationOptions`.
950
951 /// Completion was re-triggered as the current completion list is incomplete.
953};
954
956 /// How the completion was triggered.
958
959 /// The trigger character (a single character) that has trigger code complete.
960 /// Is undefined if `triggerKind !== CompletionTriggerKind.TriggerCharacter`
961 std::string triggerCharacter;
962};
963
964/// Add support for JSON serialization.
966 CompletionContext &result,
968
969//===----------------------------------------------------------------------===//
970// CompletionParams
971//===----------------------------------------------------------------------===//
972
976
977/// Add support for JSON serialization.
979 CompletionParams &result,
981
982//===----------------------------------------------------------------------===//
983// ParameterInformation
984//===----------------------------------------------------------------------===//
985
986/// A single parameter of a particular signature.
988 /// The label of this parameter. Ignored when labelOffsets is set.
989 std::string labelString;
990
991 /// Inclusive start and exclusive end offsets withing the containing signature
992 /// label.
993 std::optional<std::pair<unsigned, unsigned>> labelOffsets;
994
995 /// The documentation of this parameter. Optional.
996 std::string documentation;
997};
998
999/// Add support for JSON serialization.
1001
1002//===----------------------------------------------------------------------===//
1003// SignatureInformation
1004//===----------------------------------------------------------------------===//
1005
1006/// Represents the signature of something callable.
1008 /// The label of this signature. Mandatory.
1009 std::string label;
1010
1011 /// The documentation of this signature. Optional.
1012 std::string documentation;
1013
1014 /// The parameters of this signature.
1015 std::vector<ParameterInformation> parameters;
1016};
1017
1018/// Add support for JSON serialization.
1021
1022//===----------------------------------------------------------------------===//
1023// SignatureHelp
1024//===----------------------------------------------------------------------===//
1025
1026/// Represents the signature of a callable.
1028 /// The resulting signatures.
1029 std::vector<SignatureInformation> signatures;
1030
1031 /// The active signature.
1033
1034 /// The active parameter of the active signature.
1036};
1037
1038/// Add support for JSON serialization.
1040
1041//===----------------------------------------------------------------------===//
1042// DocumentLinkParams
1043//===----------------------------------------------------------------------===//
1044
1045/// Parameters for the document link request.
1047 /// The document to provide document links for.
1049};
1050
1051/// Add support for JSON serialization.
1053 DocumentLinkParams &result,
1055
1056//===----------------------------------------------------------------------===//
1057// DocumentLink
1058//===----------------------------------------------------------------------===//
1059
1060/// A range in a text document that links to an internal or external resource,
1061/// like another text document or a web site.
1063 DocumentLink() = default;
1066
1067 /// The range this link applies to.
1069
1070 /// The uri this link points to. If missing a resolve request is sent later.
1072
1073 // TODO: The following optional fields defined by the language server protocol
1074 // are unsupported:
1075 //
1076 // data?: any - A data entry field that is preserved on a document link
1077 // between a DocumentLinkRequest and a
1078 // DocumentLinkResolveRequest.
1079
1080 friend bool operator==(const DocumentLink &lhs, const DocumentLink &rhs) {
1081 return lhs.range == rhs.range && lhs.target == rhs.target;
1082 }
1083
1084 friend bool operator!=(const DocumentLink &lhs, const DocumentLink &rhs) {
1085 return !(lhs == rhs);
1086 }
1087};
1088
1089/// Add support for JSON serialization.
1090LLVM_ABI_FOR_TEST llvm::json::Value toJSON(const DocumentLink &value);
1091
1092//===----------------------------------------------------------------------===//
1093// InlayHintsParams
1094//===----------------------------------------------------------------------===//
1095
1096/// A parameter literal used in inlay hint requests.
1098 /// The text document.
1100
1101 /// The visible document range for which inlay hints should be computed.
1103};
1104
1105/// Add support for JSON serialization.
1107 InlayHintsParams &result,
1109
1110//===----------------------------------------------------------------------===//
1111// InlayHintKind
1112//===----------------------------------------------------------------------===//
1113
1114/// Inlay hint kinds.
1115enum class InlayHintKind {
1116 /// An inlay hint that for a type annotation.
1117 ///
1118 /// An example of a type hint is a hint in this position:
1119 /// auto var ^ = expr;
1120 /// which shows the deduced type of the variable.
1121 Type = 1,
1122
1123 /// An inlay hint that is for a parameter.
1124 ///
1125 /// An example of a parameter hint is a hint in this position:
1126 /// func(^arg);
1127 /// which shows the name of the corresponding parameter.
1129};
1130
1131//===----------------------------------------------------------------------===//
1132// InlayHint
1133//===----------------------------------------------------------------------===//
1134
1135/// Inlay hint information.
1138
1139 /// The position of this hint.
1141
1142 /// The label of this hint. A human readable string or an array of
1143 /// InlayHintLabelPart label parts.
1144 ///
1145 /// *Note* that neither the string nor the label part can be empty.
1146 std::string label;
1147
1148 /// The kind of this hint. Can be omitted in which case the client should fall
1149 /// back to a reasonable default.
1151
1152 /// Render padding before the hint.
1153 ///
1154 /// Note: Padding should use the editor's background color, not the
1155 /// background color of the hint itself. That means padding can be used
1156 /// to visually align/separate an inlay hint.
1157 bool paddingLeft = false;
1158
1159 /// Render padding after the hint.
1160 ///
1161 /// Note: Padding should use the editor's background color, not the
1162 /// background color of the hint itself. That means padding can be used
1163 /// to visually align/separate an inlay hint.
1164 bool paddingRight = false;
1165};
1166
1167/// Add support for JSON serialization.
1169bool operator==(const InlayHint &lhs, const InlayHint &rhs);
1170bool operator<(const InlayHint &lhs, const InlayHint &rhs);
1172
1173//===----------------------------------------------------------------------===//
1174// CodeActionContext
1175//===----------------------------------------------------------------------===//
1176
1178 /// An array of diagnostics known on the client side overlapping the range
1179 /// provided to the `textDocument/codeAction` request. They are provided so
1180 /// that the server knows which errors are currently presented to the user for
1181 /// the given range. There is no guarantee that these accurately reflect the
1182 /// error state of the resource. The primary parameter to compute code actions
1183 /// is the provided range.
1184 std::vector<Diagnostic> diagnostics;
1185
1186 /// Requested kind of actions to return.
1187 ///
1188 /// Actions not of this kind are filtered out by the client before being
1189 /// shown. So servers can omit computing them.
1190 std::vector<std::string> only;
1191};
1192
1193/// Add support for JSON serialization.
1195 CodeActionContext &result,
1197
1198//===----------------------------------------------------------------------===//
1199// CodeActionParams
1200//===----------------------------------------------------------------------===//
1201
1203 /// The document in which the command was invoked.
1205
1206 /// The range for which the command was invoked.
1208
1209 /// Context carrying additional information.
1211};
1212
1213/// Add support for JSON serialization.
1215 CodeActionParams &result,
1217
1218//===----------------------------------------------------------------------===//
1219// WorkspaceEdit
1220//===----------------------------------------------------------------------===//
1221
1223 /// Holds changes to existing resources.
1224 std::map<std::string, std::vector<TextEdit>> changes;
1225
1226 /// Note: "documentChanges" is not currently used because currently there is
1227 /// no support for versioned edits.
1228};
1229
1230/// Add support for JSON serialization.
1234
1235//===----------------------------------------------------------------------===//
1236// CodeAction
1237//===----------------------------------------------------------------------===//
1238
1239/// A code action represents a change that can be performed in code, e.g. to fix
1240/// a problem or to refactor code.
1241///
1242/// A CodeAction must set either `edit` and/or a `command`. If both are
1243/// supplied, the `edit` is applied first, then the `command` is executed.
1245 /// A short, human-readable, title for this code action.
1246 std::string title;
1247
1248 /// The kind of the code action.
1249 /// Used to filter code actions.
1250 std::optional<std::string> kind;
1254
1255 /// The diagnostics that this code action resolves.
1256 std::optional<std::vector<Diagnostic>> diagnostics;
1257
1258 /// Marks this as a preferred action. Preferred actions are used by the
1259 /// `auto fix` command and can be targeted by keybindings.
1260 /// A quick fix should be marked preferred if it properly addresses the
1261 /// underlying error. A refactoring should be marked preferred if it is the
1262 /// most reasonable choice of actions to take.
1263 bool isPreferred = false;
1264
1265 /// The workspace edit this code action performs.
1266 std::optional<WorkspaceEdit> edit;
1267};
1268
1269/// Add support for JSON serialization.
1271
1272} // namespace lsp
1273} // namespace llvm
1274
1275namespace llvm {
1276template <> struct format_provider<llvm::lsp::Position> {
1277 static void format(const llvm::lsp::Position &pos, raw_ostream &os,
1278 StringRef style) {
1279 assert(style.empty() && "style modifiers for this type are not supported");
1280 os << pos;
1281 }
1282};
1283} // namespace llvm
1284
1285#endif
1286
1287// NOLINTEND(readability-identifier-naming)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI_FOR_TEST
Definition Compiler.h:218
This file supports working with JSON data.
lazy value info
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Base class for user error types.
Definition Error.h:354
Tagged union holding either a T or a Error.
Definition Error.h:485
Represents a location in source code.
Definition SMLoc.h:22
constexpr const char * getPointer() const
Definition SMLoc.h:33
constexpr bool isValid() const
Definition SMLoc.h:28
Represents a range in source code.
Definition SMLoc.h:47
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
Definition SourceMgr.h:37
unsigned getMainFileID() const
Definition SourceMgr.h:148
LLVM_ABI std::pair< unsigned, unsigned > getLineAndColumn(SMLoc Loc, unsigned BufferID=0) const
Find the line and column number for the specified location in the specified file.
LLVM_ABI SMLoc FindLocForLineAndColumn(unsigned BufferID, unsigned LineNo, unsigned ColNo)
Given a line and column number in a mapped buffer, turn it into an SMLoc.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition StringRef.h:854
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
constexpr bool empty() const
empty - Check if the string is empty.
Definition StringRef.h:143
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
A "cursor" marking a position within a Value.
Definition JSON.h:666
A Value is an JSON value of unknown type.
Definition JSON.h:290
static LLVM_ABI_FOR_TEST char ID
Definition Protocol.h:84
void log(raw_ostream &os) const override
Print an error message to an output stream.
Definition Protocol.h:89
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition Protocol.h:92
std::string message
Definition Protocol.h:82
LSPError(std::string message, ErrorCode code)
Definition Protocol.h:86
URI in "file" scheme for a file.
Definition Protocol.h:102
friend bool operator==(const URIForFile &lhs, const URIForFile &rhs)
Definition Protocol.h:125
static void registerSupportedScheme(StringRef scheme)
Register a supported URI scheme.
Definition Protocol.cpp:234
static llvm::Expected< URIForFile > fromFile(StringRef absoluteFilepath, StringRef scheme="file")
Try to build a URIForFile from the given absolute file path and optional scheme.
Definition Protocol.cpp:223
static llvm::Expected< URIForFile > fromURI(StringRef uri)
Try to build a URIForFile from the given URI string.
Definition Protocol.cpp:216
StringRef scheme() const
Return the scheme of the uri.
Definition Protocol.cpp:232
friend bool operator!=(const URIForFile &lhs, const URIForFile &rhs)
Definition Protocol.h:128
StringRef uri() const
Returns the original uri of the file.
Definition Protocol.h:118
friend bool operator<(const URIForFile &lhs, const URIForFile &rhs)
Definition Protocol.h:131
StringRef file() const
Returns the absolute path to the file.
Definition Protocol.h:115
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
constexpr auto kCompletionItemKindMin
Definition Protocol.h:827
MarkupKind
Describes the content type that a client supports in various result literals like Hover.
Definition Protocol.h:542
LLVM_ABI_FOR_TEST llvm::json::Value toJSON(const URIForFile &value)
Add support for JSON serialization.
Definition Protocol.cpp:253
CompletionTriggerKind
Definition Protocol.h:942
@ Invoked
Completion was triggered by typing an identifier (24x7 code complete), manual invocation (e....
Definition Protocol.h:945
@ TriggerTriggerForIncompleteCompletions
Completion was re-triggered as the current completion list is incomplete.
Definition Protocol.h:952
@ TriggerCharacter
Completion was triggered by a trigger character specified by the triggerCharacters properties of the ...
Definition Protocol.h:949
TextDocumentSyncKind
Defines how the host (editor) should sync document changes to the language server.
Definition Protocol.h:63
@ Incremental
Documents are synced by sending the full content on open.
Definition Protocol.h:72
@ None
Documents should not be synced at all.
Definition Protocol.h:65
@ Full
Documents are synced by always sending the full content of the document.
Definition Protocol.h:68
bool operator<(const CompletionItem &lhs, const CompletionItem &rhs)
Definition Protocol.cpp:817
bool operator==(const TextEdit &lhs, const TextEdit &rhs)
Definition Protocol.h:781
NoParams InitializedParams
Definition Protocol.h:233
raw_ostream & operator<<(raw_ostream &os, const URIForFile &value)
Definition Protocol.cpp:257
CompletionItemKind adjustKindToCapability(CompletionItemKind kind, CompletionItemKindBitset &supportedCompletionItemKinds)
Definition Protocol.cpp:744
InlayHintKind
Inlay hint kinds.
Definition Protocol.h:1115
@ Parameter
An inlay hint that is for a parameter.
Definition Protocol.h:1128
@ Type
An inlay hint that for a type annotation.
Definition Protocol.h:1121
DiagnosticSeverity
Definition Protocol.h:693
@ Undetermined
It is up to the client to interpret diagnostics as error, warning, info or hint.
Definition Protocol.h:696
InsertTextFormat
Defines whether the insert text in a completion item should be interpreted as plain text or a snippet...
Definition Protocol.h:846
std::bitset< kCompletionItemKindMax+1 > CompletionItemKindBitset
Definition Protocol.h:831
constexpr auto kCompletionItemKindMax
Definition Protocol.h:829
CompletionItemKind
The kind of a completion entry.
Definition Protocol.h:795
LLVM_ABI_FOR_TEST bool fromJSON(const llvm::json::Value &value, URIForFile &result, llvm::json::Path path)
Definition Protocol.cpp:238
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition Error.cpp:98
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1867
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:867
This class represents an efficient way to signal success or failure.
static void format(const llvm::lsp::Position &pos, raw_ostream &os, StringRef style)
Definition Protocol.h:1277
bool hierarchicalDocumentSymbol
Client supports hierarchical document symbols.
Definition Protocol.h:161
bool workDoneProgress
Client supports server-initiated progress via the window/workDoneProgress/create method.
Definition Protocol.h:171
bool codeActionStructure
Client supports CodeAction return value for textDocument/codeAction.
Definition Protocol.h:165
std::string name
The name of the client as defined by the client.
Definition Protocol.h:185
std::optional< std::string > version
The client's version as defined by the client.
Definition Protocol.h:188
std::vector< Diagnostic > diagnostics
An array of diagnostics known on the client side overlapping the range provided to the textDocument/c...
Definition Protocol.h:1184
std::vector< std::string > only
Requested kind of actions to return.
Definition Protocol.h:1190
CodeActionContext context
Context carrying additional information.
Definition Protocol.h:1210
TextDocumentIdentifier textDocument
The document in which the command was invoked.
Definition Protocol.h:1204
Range range
The range for which the command was invoked.
Definition Protocol.h:1207
A code action represents a change that can be performed in code, e.g.
Definition Protocol.h:1244
std::optional< std::string > kind
The kind of the code action.
Definition Protocol.h:1250
static const llvm::StringLiteral kRefactor
Definition Protocol.h:1252
static const llvm::StringLiteral kInfo
Definition Protocol.h:1253
bool isPreferred
Marks this as a preferred action.
Definition Protocol.h:1263
static const llvm::StringLiteral kQuickFix
Definition Protocol.h:1251
std::optional< std::vector< Diagnostic > > diagnostics
The diagnostics that this code action resolves.
Definition Protocol.h:1256
std::optional< WorkspaceEdit > edit
The workspace edit this code action performs.
Definition Protocol.h:1266
std::string title
A short, human-readable, title for this code action.
Definition Protocol.h:1246
std::string triggerCharacter
The trigger character (a single character) that has trigger code complete.
Definition Protocol.h:961
CompletionTriggerKind triggerKind
How the completion was triggered.
Definition Protocol.h:957
CompletionItem(const Twine &label, CompletionItemKind kind, StringRef sortText="")
Definition Protocol.h:864
std::string filterText
A string that should be used when filtering a set of completion items.
Definition Protocol.h:890
std::string insertText
A string that should be inserted to a document when selecting this completion.
Definition Protocol.h:894
bool deprecated
Indicates if this item is deprecated.
Definition Protocol.h:913
std::optional< TextEdit > textEdit
An edit which is applied to a document when selecting this completion.
Definition Protocol.h:905
std::vector< TextEdit > additionalTextEdits
An optional array of additional text edits that are applied when selecting this completion.
Definition Protocol.h:910
CompletionItemKind kind
The kind of this completion item.
Definition Protocol.h:875
InsertTextFormat insertTextFormat
The format of the insert text.
Definition Protocol.h:898
std::string label
The label of this completion item.
Definition Protocol.h:871
std::optional< MarkupContent > documentation
A human-readable string that represents a doc-comment.
Definition Protocol.h:882
std::string sortText
A string that should be used when comparing this item with other items.
Definition Protocol.h:886
Represents a collection of completion items to be presented in the editor.
Definition Protocol.h:926
bool isIncomplete
The list is not complete.
Definition Protocol.h:929
std::vector< CompletionItem > items
The completion items.
Definition Protocol.h:932
CompletionContext context
Definition Protocol.h:974
Represents a related message and source code location for a diagnostic.
Definition Protocol.h:671
DiagnosticRelatedInformation(Location location, std::string message)
Definition Protocol.h:673
std::string message
The message of this related diagnostic information.
Definition Protocol.h:679
Location location
The location of this related diagnostic information.
Definition Protocol.h:677
std::vector< DiagnosticTag > tags
Additional metadata about the diagnostic.
Definition Protocol.h:733
std::string message
The diagnostic's message.
Definition Protocol.h:726
Range range
The source range where the message applies.
Definition Protocol.h:715
std::optional< std::vector< DiagnosticRelatedInformation > > relatedInformation
An array of related diagnostic information, e.g.
Definition Protocol.h:730
std::string source
A human-readable string describing the source of this diagnostic, e.g.
Definition Protocol.h:723
DiagnosticSeverity severity
The diagnostic's severity.
Definition Protocol.h:719
std::optional< std::string > category
The diagnostic's category.
Definition Protocol.h:739
VersionedTextDocumentIdentifier textDocument
The document that changed.
Definition Protocol.h:525
std::vector< TextDocumentContentChangeEvent > contentChanges
The actual content changes.
Definition Protocol.h:528
TextDocumentIdentifier textDocument
The document that was closed.
Definition Protocol.h:489
TextDocumentItem textDocument
The document that was opened.
Definition Protocol.h:475
Parameters for the document link request.
Definition Protocol.h:1046
TextDocumentIdentifier textDocument
The document to provide document links for.
Definition Protocol.h:1048
TextDocumentIdentifier textDocument
Definition Protocol.h:656
Represents programming constructs like variables, classes, interfaces etc.
Definition Protocol.h:616
Range range
The range enclosing this symbol not including leading/trailing whitespace but everything else like co...
Definition Protocol.h:637
SymbolKind kind
The kind of this symbol.
Definition Protocol.h:631
DocumentSymbol(const Twine &name, SymbolKind kind, Range range, Range selectionRange)
Definition Protocol.h:619
std::string name
The name of this symbol.
Definition Protocol.h:625
DocumentSymbol(DocumentSymbol &&)=default
std::vector< DocumentSymbol > children
Children of this symbol, e.g. properties of a class.
Definition Protocol.h:644
Range selectionRange
The range that should be selected and revealed when this symbol is being picked, e....
Definition Protocol.h:641
std::optional< Range > range
An optional range is a range inside a text document that is used to visualize a hover,...
Definition Protocol.h:569
Hover(Range range)
Construct a default hover with the given range that uses Markdown content.
Definition Protocol.h:562
MarkupContent contents
The hover's content.
Definition Protocol.h:565
std::optional< TraceLevel > trace
The initial trace setting. If omitted trace is disabled ('off').
Definition Protocol.h:217
ClientCapabilities capabilities
The capabilities provided by the client (editor or tool).
Definition Protocol.h:211
std::optional< ClientInfo > clientInfo
Information about the client.
Definition Protocol.h:214
Inlay hint information.
Definition Protocol.h:1136
bool paddingRight
Render padding after the hint.
Definition Protocol.h:1164
InlayHint(InlayHintKind kind, Position pos)
Definition Protocol.h:1137
bool paddingLeft
Render padding before the hint.
Definition Protocol.h:1157
InlayHintKind kind
The kind of this hint.
Definition Protocol.h:1150
std::string label
The label of this hint.
Definition Protocol.h:1146
Position position
The position of this hint.
Definition Protocol.h:1140
A parameter literal used in inlay hint requests.
Definition Protocol.h:1097
Range range
The visible document range for which inlay hints should be computed.
Definition Protocol.h:1102
TextDocumentIdentifier textDocument
The text document.
Definition Protocol.h:1099
Location(const URIForFile &uri, Range range)
Definition Protocol.h:401
friend bool operator<(const Location &lhs, const Location &rhs)
Definition Protocol.h:419
friend bool operator!=(const Location &lhs, const Location &rhs)
Definition Protocol.h:415
URIForFile uri
The text document's URI.
Definition Protocol.h:408
Location(const URIForFile &uri, llvm::SourceMgr &mgr, SMRange range)
Construct a Location from the given source range.
Definition Protocol.h:404
friend bool operator==(const Location &lhs, const Location &rhs)
Definition Protocol.h:411
A single parameter of a particular signature.
Definition Protocol.h:987
std::optional< std::pair< unsigned, unsigned > > labelOffsets
Inclusive start and exclusive end offsets withing the containing signature label.
Definition Protocol.h:993
std::string documentation
The documentation of this parameter. Optional.
Definition Protocol.h:996
std::string labelString
The label of this parameter. Ignored when labelOffsets is set.
Definition Protocol.h:989
Position(llvm::SourceMgr &mgr, SMLoc loc)
Construct a position from the given source location.
Definition Protocol.h:300
int line
Line position in a document (zero-based).
Definition Protocol.h:307
SMLoc getAsSMLoc(llvm::SourceMgr &mgr) const
Convert this position into a source location in the main file of the given source manager.
Definition Protocol.h:330
friend bool operator==(const Position &lhs, const Position &rhs)
Definition Protocol.h:312
Position(int line=0, int character=0)
Definition Protocol.h:296
int character
Character offset on a line in a document (zero-based).
Definition Protocol.h:310
friend bool operator<(const Position &lhs, const Position &rhs)
Definition Protocol.h:319
friend bool operator<=(const Position &lhs, const Position &rhs)
Definition Protocol.h:323
friend bool operator!=(const Position &lhs, const Position &rhs)
Definition Protocol.h:316
URIForFile uri
The URI for which diagnostic information is reported.
Definition Protocol.h:756
PublishDiagnosticsParams(URIForFile uri, int64_t version)
Definition Protocol.h:752
int64_t version
The version number of the document the diagnostics are published for.
Definition Protocol.h:760
std::vector< Diagnostic > diagnostics
The list of reported diagnostics.
Definition Protocol.h:758
bool contains(Position pos) const
Definition Protocol.h:371
friend bool operator!=(const Range &lhs, const Range &rhs)
Definition Protocol.h:364
SMRange getAsSMRange(llvm::SourceMgr &mgr) const
Convert this range into a source range in the main file of the given source manager.
Definition Protocol.h:378
friend bool operator<(const Range &lhs, const Range &rhs)
Definition Protocol.h:367
bool contains(Range range) const
Definition Protocol.h:372
Position end
The range's end position.
Definition Protocol.h:359
Position start
The range's start position.
Definition Protocol.h:356
Range(llvm::SourceMgr &mgr, SMRange range)
Construct a range from the given source range.
Definition Protocol.h:352
Range(Position start, Position end)
Definition Protocol.h:348
friend bool operator==(const Range &lhs, const Range &rhs)
Definition Protocol.h:361
Range(Position loc)
Definition Protocol.h:349
bool includeDeclaration
Include the declaration of the current symbol.
Definition Protocol.h:453
ReferenceContext context
Definition Protocol.h:462
Represents the signature of a callable.
Definition Protocol.h:1027
std::vector< SignatureInformation > signatures
The resulting signatures.
Definition Protocol.h:1029
int activeParameter
The active parameter of the active signature.
Definition Protocol.h:1035
int activeSignature
The active signature.
Definition Protocol.h:1032
Represents the signature of something callable.
Definition Protocol.h:1007
std::vector< ParameterInformation > parameters
The parameters of this signature.
Definition Protocol.h:1015
std::string label
The label of this signature. Mandatory.
Definition Protocol.h:1009
std::string documentation
The documentation of this signature. Optional.
Definition Protocol.h:1012
std::optional< Range > range
The range of the document that changed.
Definition Protocol.h:509
std::optional< int > rangeLength
The length of the range that got replaced.
Definition Protocol.h:512
LogicalResult applyTo(std::string &contents) const
Try to apply this change to the given contents string.
Definition Protocol.cpp:510
std::string text
The new text of the range/document.
Definition Protocol.h:515
URIForFile uri
The text document's URI.
Definition Protocol.h:264
std::string languageId
The text document's language identifier.
Definition Protocol.h:244
URIForFile uri
The text document's URI.
Definition Protocol.h:241
int64_t version
The version number of this document.
Definition Protocol.h:250
std::string text
The content of the opened text document.
Definition Protocol.h:247
Position position
The position inside the text document.
Definition Protocol.h:439
TextDocumentIdentifier textDocument
The text document.
Definition Protocol.h:436
Range range
The range of the text document to be manipulated.
Definition Protocol.h:774
std::string newText
The string to be inserted.
Definition Protocol.h:778
URIForFile uri
The text document's URI.
Definition Protocol.h:279
int64_t version
The version number of this document.
Definition Protocol.h:281
std::map< std::string, std::vector< TextEdit > > changes
Holds changes to existing resources.
Definition Protocol.h:1224