MLIR  19.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 MLIR_TOOLS_LSPSERVERSUPPORT_PROTOCOL_H
24 #define MLIR_TOOLS_LSPSERVERSUPPORT_PROTOCOL_H
25 
26 #include "mlir/Support/LLVM.h"
27 #include "llvm/Support/JSON.h"
28 #include "llvm/Support/SourceMgr.h"
29 #include "llvm/Support/raw_ostream.h"
30 #include <bitset>
31 #include <memory>
32 #include <optional>
33 #include <string>
34 #include <utility>
35 #include <vector>
36 
37 namespace mlir {
38 struct LogicalResult;
39 
40 namespace lsp {
41 
42 enum class ErrorCode {
43  // Defined by JSON RPC.
44  ParseError = -32700,
45  InvalidRequest = -32600,
46  MethodNotFound = -32601,
47  InvalidParams = -32602,
48  InternalError = -32603,
49 
50  ServerNotInitialized = -32002,
51  UnknownErrorCode = -32001,
52 
53  // Defined by the protocol.
54  RequestCancelled = -32800,
55  ContentModified = -32801,
56  RequestFailed = -32803,
57 };
58 
59 /// Defines how the host (editor) should sync document changes to the language
60 /// server.
62  /// Documents should not be synced at all.
63  None = 0,
64 
65  /// Documents are synced by always sending the full content of the document.
66  Full = 1,
67 
68  /// Documents are synced by sending the full content on open. After that only
69  /// incremental updates to the document are sent.
70  Incremental = 2,
71 };
72 
73 //===----------------------------------------------------------------------===//
74 // LSPError
75 //===----------------------------------------------------------------------===//
76 
77 /// This class models an LSP error as an llvm::Error.
78 class LSPError : public llvm::ErrorInfo<LSPError> {
79 public:
80  std::string message;
82  static char ID;
83 
85  : message(std::move(message)), code(code) {}
86 
87  void log(raw_ostream &os) const override {
88  os << int(code) << ": " << message;
89  }
90  std::error_code convertToErrorCode() const override {
91  return llvm::inconvertibleErrorCode();
92  }
93 };
94 
95 //===----------------------------------------------------------------------===//
96 // URIForFile
97 //===----------------------------------------------------------------------===//
98 
99 /// URI in "file" scheme for a file.
100 class URIForFile {
101 public:
102  URIForFile() = default;
103 
104  /// Try to build a URIForFile from the given URI string.
105  static llvm::Expected<URIForFile> fromURI(StringRef uri);
106 
107  /// Try to build a URIForFile from the given absolute file path and optional
108  /// scheme.
109  static llvm::Expected<URIForFile> fromFile(StringRef absoluteFilepath,
110  StringRef scheme = "file");
111 
112  /// Returns the absolute path to the file.
113  StringRef file() const { return filePath; }
114 
115  /// Returns the original uri of the file.
116  StringRef uri() const { return uriStr; }
117 
118  /// Return the scheme of the uri.
119  StringRef scheme() const;
120 
121  explicit operator bool() const { return !filePath.empty(); }
122 
123  friend bool operator==(const URIForFile &lhs, const URIForFile &rhs) {
124  return lhs.filePath == rhs.filePath;
125  }
126  friend bool operator!=(const URIForFile &lhs, const URIForFile &rhs) {
127  return !(lhs == rhs);
128  }
129  friend bool operator<(const URIForFile &lhs, const URIForFile &rhs) {
130  return lhs.filePath < rhs.filePath;
131  }
132 
133  /// Register a supported URI scheme. The protocol supports `file` by default,
134  /// so this is only necessary for any additional schemes that a server wants
135  /// to support.
136  static void registerSupportedScheme(StringRef scheme);
137 
138 private:
139  explicit URIForFile(std::string &&filePath, std::string &&uriStr)
140  : filePath(std::move(filePath)), uriStr(uriStr) {}
141 
142  std::string filePath;
143  std::string uriStr;
144 };
145 
146 /// Add support for JSON serialization.
147 llvm::json::Value toJSON(const URIForFile &value);
148 bool fromJSON(const llvm::json::Value &value, URIForFile &result,
149  llvm::json::Path path);
150 raw_ostream &operator<<(raw_ostream &os, const URIForFile &value);
151 
152 //===----------------------------------------------------------------------===//
153 // ClientCapabilities
154 //===----------------------------------------------------------------------===//
155 
157  /// Client supports hierarchical document symbols.
158  /// textDocument.documentSymbol.hierarchicalDocumentSymbolSupport
160 
161  /// Client supports CodeAction return value for textDocument/codeAction.
162  /// textDocument.codeAction.codeActionLiteralSupport.
163  bool codeActionStructure = false;
164 };
165 
166 /// Add support for JSON serialization.
167 bool fromJSON(const llvm::json::Value &value, ClientCapabilities &result,
168  llvm::json::Path path);
169 
170 //===----------------------------------------------------------------------===//
171 // ClientInfo
172 //===----------------------------------------------------------------------===//
173 
174 struct ClientInfo {
175  /// The name of the client as defined by the client.
176  std::string name;
177 
178  /// The client's version as defined by the client.
179  std::optional<std::string> version;
180 };
181 
182 /// Add support for JSON serialization.
183 bool fromJSON(const llvm::json::Value &value, ClientInfo &result,
184  llvm::json::Path path);
185 
186 //===----------------------------------------------------------------------===//
187 // InitializeParams
188 //===----------------------------------------------------------------------===//
189 
190 enum class TraceLevel {
191  Off = 0,
192  Messages = 1,
193  Verbose = 2,
194 };
195 
196 /// Add support for JSON serialization.
197 bool fromJSON(const llvm::json::Value &value, TraceLevel &result,
198  llvm::json::Path path);
199 
201  /// The capabilities provided by the client (editor or tool).
203 
204  /// Information about the client.
205  std::optional<ClientInfo> clientInfo;
206 
207  /// The initial trace setting. If omitted trace is disabled ('off').
208  std::optional<TraceLevel> trace;
209 };
210 
211 /// Add support for JSON serialization.
212 bool fromJSON(const llvm::json::Value &value, InitializeParams &result,
213  llvm::json::Path path);
214 
215 //===----------------------------------------------------------------------===//
216 // InitializedParams
217 //===----------------------------------------------------------------------===//
218 
219 struct NoParams {};
220 inline bool fromJSON(const llvm::json::Value &, NoParams &, llvm::json::Path) {
221  return true;
222 }
224 
225 //===----------------------------------------------------------------------===//
226 // TextDocumentItem
227 //===----------------------------------------------------------------------===//
228 
230  /// The text document's URI.
232 
233  /// The text document's language identifier.
234  std::string languageId;
235 
236  /// The content of the opened text document.
237  std::string text;
238 
239  /// The version number of this document.
240  int64_t version;
241 };
242 
243 /// Add support for JSON serialization.
244 bool fromJSON(const llvm::json::Value &value, TextDocumentItem &result,
245  llvm::json::Path path);
246 
247 //===----------------------------------------------------------------------===//
248 // TextDocumentIdentifier
249 //===----------------------------------------------------------------------===//
250 
252  /// The text document's URI.
254 };
255 
256 /// Add support for JSON serialization.
257 llvm::json::Value toJSON(const TextDocumentIdentifier &value);
258 bool fromJSON(const llvm::json::Value &value, TextDocumentIdentifier &result,
259  llvm::json::Path path);
260 
261 //===----------------------------------------------------------------------===//
262 // VersionedTextDocumentIdentifier
263 //===----------------------------------------------------------------------===//
264 
266  /// The text document's URI.
268  /// The version number of this document.
269  int64_t version;
270 };
271 
272 /// Add support for JSON serialization.
273 llvm::json::Value toJSON(const VersionedTextDocumentIdentifier &value);
274 bool fromJSON(const llvm::json::Value &value,
275  VersionedTextDocumentIdentifier &result, llvm::json::Path path);
276 
277 //===----------------------------------------------------------------------===//
278 // Position
279 //===----------------------------------------------------------------------===//
280 
281 struct Position {
282  Position(int line = 0, int character = 0)
283  : line(line), character(character) {}
284 
285  /// Construct a position from the given source location.
286  Position(llvm::SourceMgr &mgr, SMLoc loc) {
287  std::pair<unsigned, unsigned> lineAndCol = mgr.getLineAndColumn(loc);
288  line = lineAndCol.first - 1;
289  character = lineAndCol.second - 1;
290  }
291 
292  /// Line position in a document (zero-based).
293  int line = 0;
294 
295  /// Character offset on a line in a document (zero-based).
296  int character = 0;
297 
298  friend bool operator==(const Position &lhs, const Position &rhs) {
299  return std::tie(lhs.line, lhs.character) ==
300  std::tie(rhs.line, rhs.character);
301  }
302  friend bool operator!=(const Position &lhs, const Position &rhs) {
303  return !(lhs == rhs);
304  }
305  friend bool operator<(const Position &lhs, const Position &rhs) {
306  return std::tie(lhs.line, lhs.character) <
307  std::tie(rhs.line, rhs.character);
308  }
309  friend bool operator<=(const Position &lhs, const Position &rhs) {
310  return std::tie(lhs.line, lhs.character) <=
311  std::tie(rhs.line, rhs.character);
312  }
313 
314  /// Convert this position into a source location in the main file of the given
315  /// source manager.
316  SMLoc getAsSMLoc(llvm::SourceMgr &mgr) const {
317  return mgr.FindLocForLineAndColumn(mgr.getMainFileID(), line + 1,
318  character + 1);
319  }
320 };
321 
322 /// Add support for JSON serialization.
323 bool fromJSON(const llvm::json::Value &value, Position &result,
324  llvm::json::Path path);
325 llvm::json::Value toJSON(const Position &value);
326 raw_ostream &operator<<(raw_ostream &os, const Position &value);
327 
328 //===----------------------------------------------------------------------===//
329 // Range
330 //===----------------------------------------------------------------------===//
331 
332 struct Range {
333  Range() = default;
335  Range(Position loc) : Range(loc, loc) {}
336 
337  /// Construct a range from the given source range.
338  Range(llvm::SourceMgr &mgr, SMRange range)
339  : Range(Position(mgr, range.Start), Position(mgr, range.End)) {}
340 
341  /// The range's start position.
343 
344  /// The range's end position.
346 
347  friend bool operator==(const Range &lhs, const Range &rhs) {
348  return std::tie(lhs.start, lhs.end) == std::tie(rhs.start, rhs.end);
349  }
350  friend bool operator!=(const Range &lhs, const Range &rhs) {
351  return !(lhs == rhs);
352  }
353  friend bool operator<(const Range &lhs, const Range &rhs) {
354  return std::tie(lhs.start, lhs.end) < std::tie(rhs.start, rhs.end);
355  }
356 
357  bool contains(Position pos) const { return start <= pos && pos < end; }
358  bool contains(Range range) const {
359  return start <= range.start && range.end <= end;
360  }
361 
362  /// Convert this range into a source range in the main file of the given
363  /// source manager.
364  SMRange getAsSMRange(llvm::SourceMgr &mgr) const {
365  SMLoc startLoc = start.getAsSMLoc(mgr);
366  SMLoc endLoc = end.getAsSMLoc(mgr);
367  // Check that the start and end locations are valid.
368  if (!startLoc.isValid() || !endLoc.isValid() ||
369  startLoc.getPointer() > endLoc.getPointer())
370  return SMRange();
371  return SMRange(startLoc, endLoc);
372  }
373 };
374 
375 /// Add support for JSON serialization.
376 bool fromJSON(const llvm::json::Value &value, Range &result,
377  llvm::json::Path path);
378 llvm::json::Value toJSON(const Range &value);
379 raw_ostream &operator<<(raw_ostream &os, const Range &value);
380 
381 //===----------------------------------------------------------------------===//
382 // Location
383 //===----------------------------------------------------------------------===//
384 
385 struct Location {
386  Location() = default;
388 
389  /// Construct a Location from the given source range.
390  Location(const URIForFile &uri, llvm::SourceMgr &mgr, SMRange range)
391  : Location(uri, Range(mgr, range)) {}
392 
393  /// The text document's URI.
396 
397  friend bool operator==(const Location &lhs, const Location &rhs) {
398  return lhs.uri == rhs.uri && lhs.range == rhs.range;
399  }
400 
401  friend bool operator!=(const Location &lhs, const Location &rhs) {
402  return !(lhs == rhs);
403  }
404 
405  friend bool operator<(const Location &lhs, const Location &rhs) {
406  return std::tie(lhs.uri, lhs.range) < std::tie(rhs.uri, rhs.range);
407  }
408 };
409 
410 /// Add support for JSON serialization.
411 bool fromJSON(const llvm::json::Value &value, Location &result,
412  llvm::json::Path path);
413 llvm::json::Value toJSON(const Location &value);
414 raw_ostream &operator<<(raw_ostream &os, const Location &value);
415 
416 //===----------------------------------------------------------------------===//
417 // TextDocumentPositionParams
418 //===----------------------------------------------------------------------===//
419 
421  /// The text document.
423 
424  /// The position inside the text document.
426 };
427 
428 /// Add support for JSON serialization.
429 bool fromJSON(const llvm::json::Value &value,
430  TextDocumentPositionParams &result, llvm::json::Path path);
431 
432 //===----------------------------------------------------------------------===//
433 // ReferenceParams
434 //===----------------------------------------------------------------------===//
435 
437  /// Include the declaration of the current symbol.
438  bool includeDeclaration = false;
439 };
440 
441 /// Add support for JSON serialization.
442 bool fromJSON(const llvm::json::Value &value, ReferenceContext &result,
443  llvm::json::Path path);
444 
447 };
448 
449 /// Add support for JSON serialization.
450 bool fromJSON(const llvm::json::Value &value, ReferenceParams &result,
451  llvm::json::Path path);
452 
453 //===----------------------------------------------------------------------===//
454 // DidOpenTextDocumentParams
455 //===----------------------------------------------------------------------===//
456 
458  /// The document that was opened.
460 };
461 
462 /// Add support for JSON serialization.
463 bool fromJSON(const llvm::json::Value &value, DidOpenTextDocumentParams &result,
464  llvm::json::Path path);
465 
466 //===----------------------------------------------------------------------===//
467 // DidCloseTextDocumentParams
468 //===----------------------------------------------------------------------===//
469 
471  /// The document that was closed.
473 };
474 
475 /// Add support for JSON serialization.
476 bool fromJSON(const llvm::json::Value &value,
477  DidCloseTextDocumentParams &result, llvm::json::Path path);
478 
479 //===----------------------------------------------------------------------===//
480 // DidChangeTextDocumentParams
481 //===----------------------------------------------------------------------===//
482 
484  /// Try to apply this change to the given contents string.
485  LogicalResult applyTo(std::string &contents) const;
486  /// Try to apply a set of changes to the given contents string.
488  std::string &contents);
489 
490  /// The range of the document that changed.
491  std::optional<Range> range;
492 
493  /// The length of the range that got replaced.
494  std::optional<int> rangeLength;
495 
496  /// The new text of the range/document.
497  std::string text;
498 };
499 
500 /// Add support for JSON serialization.
501 bool fromJSON(const llvm::json::Value &value,
502  TextDocumentContentChangeEvent &result, llvm::json::Path path);
503 
505  /// The document that changed.
507 
508  /// The actual content changes.
509  std::vector<TextDocumentContentChangeEvent> contentChanges;
510 };
511 
512 /// Add support for JSON serialization.
513 bool fromJSON(const llvm::json::Value &value,
514  DidChangeTextDocumentParams &result, llvm::json::Path path);
515 
516 //===----------------------------------------------------------------------===//
517 // MarkupContent
518 //===----------------------------------------------------------------------===//
519 
520 /// Describes the content type that a client supports in various result literals
521 /// like `Hover`.
522 enum class MarkupKind {
523  PlainText,
524  Markdown,
525 };
526 raw_ostream &operator<<(raw_ostream &os, MarkupKind kind);
527 
530  std::string value;
531 };
532 
533 /// Add support for JSON serialization.
534 llvm::json::Value toJSON(const MarkupContent &mc);
535 
536 //===----------------------------------------------------------------------===//
537 // Hover
538 //===----------------------------------------------------------------------===//
539 
540 struct Hover {
541  /// Construct a default hover with the given range that uses Markdown content.
543 
544  /// The hover's content.
546 
547  /// An optional range is a range inside a text document that is used to
548  /// visualize a hover, e.g. by changing the background color.
549  std::optional<Range> range;
550 };
551 
552 /// Add support for JSON serialization.
553 llvm::json::Value toJSON(const Hover &hover);
554 
555 //===----------------------------------------------------------------------===//
556 // SymbolKind
557 //===----------------------------------------------------------------------===//
558 
559 enum class SymbolKind {
560  File = 1,
561  Module = 2,
562  Namespace = 3,
563  Package = 4,
564  Class = 5,
565  Method = 6,
566  Property = 7,
567  Field = 8,
568  Constructor = 9,
569  Enum = 10,
570  Interface = 11,
571  Function = 12,
572  Variable = 13,
573  Constant = 14,
574  String = 15,
575  Number = 16,
576  Boolean = 17,
577  Array = 18,
578  Object = 19,
579  Key = 20,
580  Null = 21,
581  EnumMember = 22,
582  Struct = 23,
583  Event = 24,
584  Operator = 25,
585  TypeParameter = 26
586 };
587 
588 //===----------------------------------------------------------------------===//
589 // DocumentSymbol
590 //===----------------------------------------------------------------------===//
591 
592 /// Represents programming constructs like variables, classes, interfaces etc.
593 /// that appear in a document. Document symbols can be hierarchical and they
594 /// have two ranges: one that encloses its definition and one that points to its
595 /// most interesting range, e.g. the range of an identifier.
597  DocumentSymbol() = default;
601  : name(name.str()), kind(kind), range(range),
603 
604  /// The name of this symbol.
605  std::string name;
606 
607  /// More detail for this symbol, e.g the signature of a function.
608  std::string detail;
609 
610  /// The kind of this symbol.
612 
613  /// The range enclosing this symbol not including leading/trailing whitespace
614  /// but everything else like comments. This information is typically used to
615  /// determine if the clients cursor is inside the symbol to reveal in the
616  /// symbol in the UI.
618 
619  /// The range that should be selected and revealed when this symbol is being
620  /// picked, e.g the name of a function. Must be contained by the `range`.
622 
623  /// Children of this symbol, e.g. properties of a class.
624  std::vector<DocumentSymbol> children;
625 };
626 
627 /// Add support for JSON serialization.
628 llvm::json::Value toJSON(const DocumentSymbol &symbol);
629 
630 //===----------------------------------------------------------------------===//
631 // DocumentSymbolParams
632 //===----------------------------------------------------------------------===//
633 
635  // The text document to find symbols in.
637 };
638 
639 /// Add support for JSON serialization.
640 bool fromJSON(const llvm::json::Value &value, DocumentSymbolParams &result,
641  llvm::json::Path path);
642 
643 //===----------------------------------------------------------------------===//
644 // DiagnosticRelatedInformation
645 //===----------------------------------------------------------------------===//
646 
647 /// Represents a related message and source code location for a diagnostic.
648 /// This should be used to point to code locations that cause or related to a
649 /// diagnostics, e.g. when duplicating a symbol in a scope.
653  : location(std::move(location)), message(std::move(message)) {}
654 
655  /// The location of this related diagnostic information.
657  /// The message of this related diagnostic information.
658  std::string message;
659 };
660 
661 /// Add support for JSON serialization.
662 bool fromJSON(const llvm::json::Value &value,
663  DiagnosticRelatedInformation &result, llvm::json::Path path);
664 llvm::json::Value toJSON(const DiagnosticRelatedInformation &info);
665 
666 //===----------------------------------------------------------------------===//
667 // Diagnostic
668 //===----------------------------------------------------------------------===//
669 
670 enum class DiagnosticSeverity {
671  /// It is up to the client to interpret diagnostics as error, warning, info or
672  /// hint.
673  Undetermined = 0,
674  Error = 1,
675  Warning = 2,
676  Information = 3,
677  Hint = 4
678 };
679 
680 struct Diagnostic {
681  /// The source range where the message applies.
683 
684  /// The diagnostic's severity. Can be omitted. If omitted it is up to the
685  /// client to interpret diagnostics as error, warning, info or hint.
687 
688  /// A human-readable string describing the source of this diagnostic, e.g.
689  /// 'typescript' or 'super lint'.
690  std::string source;
691 
692  /// The diagnostic's message.
693  std::string message;
694 
695  /// An array of related diagnostic information, e.g. when symbol-names within
696  /// a scope collide all definitions can be marked via this property.
697  std::optional<std::vector<DiagnosticRelatedInformation>> relatedInformation;
698 
699  /// The diagnostic's category. Can be omitted.
700  /// An LSP extension that's used to send the name of the category over to the
701  /// client. The category typically describes the compilation stage during
702  /// which the issue was produced, e.g. "Semantic Issue" or "Parse Issue".
703  std::optional<std::string> category;
704 };
705 
706 /// Add support for JSON serialization.
707 llvm::json::Value toJSON(const Diagnostic &diag);
708 bool fromJSON(const llvm::json::Value &value, Diagnostic &result,
709  llvm::json::Path path);
710 
711 //===----------------------------------------------------------------------===//
712 // PublishDiagnosticsParams
713 //===----------------------------------------------------------------------===//
714 
717  : uri(std::move(uri)), version(version) {}
718 
719  /// The URI for which diagnostic information is reported.
721  /// The list of reported diagnostics.
722  std::vector<Diagnostic> diagnostics;
723  /// The version number of the document the diagnostics are published for.
724  int64_t version;
725 };
726 
727 /// Add support for JSON serialization.
728 llvm::json::Value toJSON(const PublishDiagnosticsParams &params);
729 
730 //===----------------------------------------------------------------------===//
731 // TextEdit
732 //===----------------------------------------------------------------------===//
733 
734 struct TextEdit {
735  /// The range of the text document to be manipulated. To insert
736  /// text into a document create a range where start === end.
738 
739  /// The string to be inserted. For delete operations use an
740  /// empty string.
741  std::string newText;
742 };
743 
744 inline bool operator==(const TextEdit &lhs, const TextEdit &rhs) {
745  return std::tie(lhs.newText, lhs.range) == std::tie(rhs.newText, rhs.range);
746 }
747 
748 bool fromJSON(const llvm::json::Value &value, TextEdit &result,
749  llvm::json::Path path);
750 llvm::json::Value toJSON(const TextEdit &value);
751 raw_ostream &operator<<(raw_ostream &os, const TextEdit &value);
752 
753 //===----------------------------------------------------------------------===//
754 // CompletionItemKind
755 //===----------------------------------------------------------------------===//
756 
757 /// The kind of a completion entry.
758 enum class CompletionItemKind {
759  Missing = 0,
760  Text = 1,
761  Method = 2,
762  Function = 3,
763  Constructor = 4,
764  Field = 5,
765  Variable = 6,
766  Class = 7,
767  Interface = 8,
768  Module = 9,
769  Property = 10,
770  Unit = 11,
771  Value = 12,
772  Enum = 13,
773  Keyword = 14,
774  Snippet = 15,
775  Color = 16,
776  File = 17,
777  Reference = 18,
778  Folder = 19,
779  EnumMember = 20,
780  Constant = 21,
781  Struct = 22,
782  Event = 23,
783  Operator = 24,
784  TypeParameter = 25,
785 };
786 bool fromJSON(const llvm::json::Value &value, CompletionItemKind &result,
787  llvm::json::Path path);
788 
789 constexpr auto kCompletionItemKindMin =
790  static_cast<size_t>(CompletionItemKind::Text);
791 constexpr auto kCompletionItemKindMax =
792  static_cast<size_t>(CompletionItemKind::TypeParameter);
793 using CompletionItemKindBitset = std::bitset<kCompletionItemKindMax + 1>;
794 bool fromJSON(const llvm::json::Value &value, CompletionItemKindBitset &result,
795  llvm::json::Path path);
796 
799  CompletionItemKindBitset &supportedCompletionItemKinds);
800 
801 //===----------------------------------------------------------------------===//
802 // CompletionItem
803 //===----------------------------------------------------------------------===//
804 
805 /// Defines whether the insert text in a completion item should be interpreted
806 /// as plain text or a snippet.
807 enum class InsertTextFormat {
808  Missing = 0,
809  /// The primary text to be inserted is treated as a plain string.
810  PlainText = 1,
811  /// The primary text to be inserted is treated as a snippet.
812  ///
813  /// A snippet can define tab stops and placeholders with `$1`, `$2`
814  /// and `${3:foo}`. `$0` defines the final tab stop, it defaults to the end
815  /// of the snippet. Placeholders with equal identifiers are linked, that is
816  /// typing in one will update others too.
817  ///
818  /// See also:
819  /// https//github.com/Microsoft/vscode/blob/master/src/vs/editor/contrib/snippet/common/snippet.md
820  Snippet = 2,
821 };
822 
824  CompletionItem() = default;
826  StringRef sortText = "")
827  : label(label.str()), kind(kind), sortText(sortText.str()),
829 
830  /// The label of this completion item. By default also the text that is
831  /// inserted when selecting this completion.
832  std::string label;
833 
834  /// The kind of this completion item. Based of the kind an icon is chosen by
835  /// the editor.
837 
838  /// A human-readable string with additional information about this item, like
839  /// type or symbol information.
840  std::string detail;
841 
842  /// A human-readable string that represents a doc-comment.
843  std::optional<MarkupContent> documentation;
844 
845  /// A string that should be used when comparing this item with other items.
846  /// When `falsy` the label is used.
847  std::string sortText;
848 
849  /// A string that should be used when filtering a set of completion items.
850  /// When `falsy` the label is used.
851  std::string filterText;
852 
853  /// A string that should be inserted to a document when selecting this
854  /// completion. When `falsy` the label is used.
855  std::string insertText;
856 
857  /// The format of the insert text. The format applies to both the `insertText`
858  /// property and the `newText` property of a provided `textEdit`.
860 
861  /// An edit which is applied to a document when selecting this completion.
862  /// When an edit is provided `insertText` is ignored.
863  ///
864  /// Note: The range of the edit must be a single line range and it must
865  /// contain the position at which completion has been requested.
866  std::optional<TextEdit> textEdit;
867 
868  /// An optional array of additional text edits that are applied when selecting
869  /// this completion. Edits must not overlap with the main edit nor with
870  /// themselves.
871  std::vector<TextEdit> additionalTextEdits;
872 
873  /// Indicates if this item is deprecated.
874  bool deprecated = false;
875 };
876 
877 /// Add support for JSON serialization.
878 llvm::json::Value toJSON(const CompletionItem &value);
879 raw_ostream &operator<<(raw_ostream &os, const CompletionItem &value);
880 bool operator<(const CompletionItem &lhs, const CompletionItem &rhs);
881 
882 //===----------------------------------------------------------------------===//
883 // CompletionList
884 //===----------------------------------------------------------------------===//
885 
886 /// Represents a collection of completion items to be presented in the editor.
888  /// The list is not complete. Further typing should result in recomputing the
889  /// list.
890  bool isIncomplete = false;
891 
892  /// The completion items.
893  std::vector<CompletionItem> items;
894 };
895 
896 /// Add support for JSON serialization.
897 llvm::json::Value toJSON(const CompletionList &value);
898 
899 //===----------------------------------------------------------------------===//
900 // CompletionContext
901 //===----------------------------------------------------------------------===//
902 
904  /// Completion was triggered by typing an identifier (24x7 code
905  /// complete), manual invocation (e.g Ctrl+Space) or via API.
906  Invoked = 1,
907 
908  /// Completion was triggered by a trigger character specified by
909  /// the `triggerCharacters` properties of the `CompletionRegistrationOptions`.
910  TriggerCharacter = 2,
911 
912  /// Completion was re-triggered as the current completion list is incomplete.
914 };
915 
917  /// How the completion was triggered.
919 
920  /// The trigger character (a single character) that has trigger code complete.
921  /// Is undefined if `triggerKind !== CompletionTriggerKind.TriggerCharacter`
922  std::string triggerCharacter;
923 };
924 
925 /// Add support for JSON serialization.
926 bool fromJSON(const llvm::json::Value &value, CompletionContext &result,
927  llvm::json::Path path);
928 
929 //===----------------------------------------------------------------------===//
930 // CompletionParams
931 //===----------------------------------------------------------------------===//
932 
935 };
936 
937 /// Add support for JSON serialization.
938 bool fromJSON(const llvm::json::Value &value, CompletionParams &result,
939  llvm::json::Path path);
940 
941 //===----------------------------------------------------------------------===//
942 // ParameterInformation
943 //===----------------------------------------------------------------------===//
944 
945 /// A single parameter of a particular signature.
947  /// The label of this parameter. Ignored when labelOffsets is set.
948  std::string labelString;
949 
950  /// Inclusive start and exclusive end offsets withing the containing signature
951  /// label.
952  std::optional<std::pair<unsigned, unsigned>> labelOffsets;
953 
954  /// The documentation of this parameter. Optional.
955  std::string documentation;
956 };
957 
958 /// Add support for JSON serialization.
959 llvm::json::Value toJSON(const ParameterInformation &value);
960 
961 //===----------------------------------------------------------------------===//
962 // SignatureInformation
963 //===----------------------------------------------------------------------===//
964 
965 /// Represents the signature of something callable.
967  /// The label of this signature. Mandatory.
968  std::string label;
969 
970  /// The documentation of this signature. Optional.
971  std::string documentation;
972 
973  /// The parameters of this signature.
974  std::vector<ParameterInformation> parameters;
975 };
976 
977 /// Add support for JSON serialization.
978 llvm::json::Value toJSON(const SignatureInformation &value);
979 raw_ostream &operator<<(raw_ostream &os, const SignatureInformation &value);
980 
981 //===----------------------------------------------------------------------===//
982 // SignatureHelp
983 //===----------------------------------------------------------------------===//
984 
985 /// Represents the signature of a callable.
987  /// The resulting signatures.
988  std::vector<SignatureInformation> signatures;
989 
990  /// The active signature.
992 
993  /// The active parameter of the active signature.
995 };
996 
997 /// Add support for JSON serialization.
998 llvm::json::Value toJSON(const SignatureHelp &value);
999 
1000 //===----------------------------------------------------------------------===//
1001 // DocumentLinkParams
1002 //===----------------------------------------------------------------------===//
1003 
1004 /// Parameters for the document link request.
1006  /// The document to provide document links for.
1008 };
1009 
1010 /// Add support for JSON serialization.
1011 bool fromJSON(const llvm::json::Value &value, DocumentLinkParams &result,
1012  llvm::json::Path path);
1013 
1014 //===----------------------------------------------------------------------===//
1015 // DocumentLink
1016 //===----------------------------------------------------------------------===//
1017 
1018 /// A range in a text document that links to an internal or external resource,
1019 /// like another text document or a web site.
1021  DocumentLink() = default;
1023  : range(range), target(std::move(target)) {}
1024 
1025  /// The range this link applies to.
1027 
1028  /// The uri this link points to. If missing a resolve request is sent later.
1030 
1031  // TODO: The following optional fields defined by the language server protocol
1032  // are unsupported:
1033  //
1034  // data?: any - A data entry field that is preserved on a document link
1035  // between a DocumentLinkRequest and a
1036  // DocumentLinkResolveRequest.
1037 
1038  friend bool operator==(const DocumentLink &lhs, const DocumentLink &rhs) {
1039  return lhs.range == rhs.range && lhs.target == rhs.target;
1040  }
1041 
1042  friend bool operator!=(const DocumentLink &lhs, const DocumentLink &rhs) {
1043  return !(lhs == rhs);
1044  }
1045 };
1046 
1047 /// Add support for JSON serialization.
1048 llvm::json::Value toJSON(const DocumentLink &value);
1049 
1050 //===----------------------------------------------------------------------===//
1051 // InlayHintsParams
1052 //===----------------------------------------------------------------------===//
1053 
1054 /// A parameter literal used in inlay hint requests.
1056  /// The text document.
1058 
1059  /// The visible document range for which inlay hints should be computed.
1061 };
1062 
1063 /// Add support for JSON serialization.
1064 bool fromJSON(const llvm::json::Value &value, InlayHintsParams &result,
1065  llvm::json::Path path);
1066 
1067 //===----------------------------------------------------------------------===//
1068 // InlayHintKind
1069 //===----------------------------------------------------------------------===//
1070 
1071 /// Inlay hint kinds.
1072 enum class InlayHintKind {
1073  /// An inlay hint that for a type annotation.
1074  ///
1075  /// An example of a type hint is a hint in this position:
1076  /// auto var ^ = expr;
1077  /// which shows the deduced type of the variable.
1078  Type = 1,
1079 
1080  /// An inlay hint that is for a parameter.
1081  ///
1082  /// An example of a parameter hint is a hint in this position:
1083  /// func(^arg);
1084  /// which shows the name of the corresponding parameter.
1085  Parameter = 2,
1086 };
1087 
1088 //===----------------------------------------------------------------------===//
1089 // InlayHint
1090 //===----------------------------------------------------------------------===//
1091 
1092 /// Inlay hint information.
1093 struct InlayHint {
1095 
1096  /// The position of this hint.
1098 
1099  /// The label of this hint. A human readable string or an array of
1100  /// InlayHintLabelPart label parts.
1101  ///
1102  /// *Note* that neither the string nor the label part can be empty.
1103  std::string label;
1104 
1105  /// The kind of this hint. Can be omitted in which case the client should fall
1106  /// back to a reasonable default.
1108 
1109  /// Render padding before the hint.
1110  ///
1111  /// Note: Padding should use the editor's background color, not the
1112  /// background color of the hint itself. That means padding can be used
1113  /// to visually align/separate an inlay hint.
1114  bool paddingLeft = false;
1115 
1116  /// Render padding after the hint.
1117  ///
1118  /// Note: Padding should use the editor's background color, not the
1119  /// background color of the hint itself. That means padding can be used
1120  /// to visually align/separate an inlay hint.
1121  bool paddingRight = false;
1122 };
1123 
1124 /// Add support for JSON serialization.
1125 llvm::json::Value toJSON(const InlayHint &);
1126 bool operator==(const InlayHint &lhs, const InlayHint &rhs);
1127 bool operator<(const InlayHint &lhs, const InlayHint &rhs);
1128 llvm::raw_ostream &operator<<(llvm::raw_ostream &os, InlayHintKind value);
1129 
1130 //===----------------------------------------------------------------------===//
1131 // CodeActionContext
1132 //===----------------------------------------------------------------------===//
1133 
1135  /// An array of diagnostics known on the client side overlapping the range
1136  /// provided to the `textDocument/codeAction` request. They are provided so
1137  /// that the server knows which errors are currently presented to the user for
1138  /// the given range. There is no guarantee that these accurately reflect the
1139  /// error state of the resource. The primary parameter to compute code actions
1140  /// is the provided range.
1141  std::vector<Diagnostic> diagnostics;
1142 
1143  /// Requested kind of actions to return.
1144  ///
1145  /// Actions not of this kind are filtered out by the client before being
1146  /// shown. So servers can omit computing them.
1147  std::vector<std::string> only;
1148 };
1149 
1150 /// Add support for JSON serialization.
1151 bool fromJSON(const llvm::json::Value &value, CodeActionContext &result,
1152  llvm::json::Path path);
1153 
1154 //===----------------------------------------------------------------------===//
1155 // CodeActionParams
1156 //===----------------------------------------------------------------------===//
1157 
1159  /// The document in which the command was invoked.
1161 
1162  /// The range for which the command was invoked.
1164 
1165  /// Context carrying additional information.
1167 };
1168 
1169 /// Add support for JSON serialization.
1170 bool fromJSON(const llvm::json::Value &value, CodeActionParams &result,
1171  llvm::json::Path path);
1172 
1173 //===----------------------------------------------------------------------===//
1174 // WorkspaceEdit
1175 //===----------------------------------------------------------------------===//
1176 
1178  /// Holds changes to existing resources.
1179  std::map<std::string, std::vector<TextEdit>> changes;
1180 
1181  /// Note: "documentChanges" is not currently used because currently there is
1182  /// no support for versioned edits.
1183 };
1184 
1185 /// Add support for JSON serialization.
1186 bool fromJSON(const llvm::json::Value &value, WorkspaceEdit &result,
1187  llvm::json::Path path);
1188 llvm::json::Value toJSON(const WorkspaceEdit &value);
1189 
1190 //===----------------------------------------------------------------------===//
1191 // CodeAction
1192 //===----------------------------------------------------------------------===//
1193 
1194 /// A code action represents a change that can be performed in code, e.g. to fix
1195 /// a problem or to refactor code.
1196 ///
1197 /// A CodeAction must set either `edit` and/or a `command`. If both are
1198 /// supplied, the `edit` is applied first, then the `command` is executed.
1199 struct CodeAction {
1200  /// A short, human-readable, title for this code action.
1201  std::string title;
1202 
1203  /// The kind of the code action.
1204  /// Used to filter code actions.
1205  std::optional<std::string> kind;
1206  const static llvm::StringLiteral kQuickFix;
1207  const static llvm::StringLiteral kRefactor;
1208  const static llvm::StringLiteral kInfo;
1209 
1210  /// The diagnostics that this code action resolves.
1211  std::optional<std::vector<Diagnostic>> diagnostics;
1212 
1213  /// Marks this as a preferred action. Preferred actions are used by the
1214  /// `auto fix` command and can be targeted by keybindings.
1215  /// A quick fix should be marked preferred if it properly addresses the
1216  /// underlying error. A refactoring should be marked preferred if it is the
1217  /// most reasonable choice of actions to take.
1218  bool isPreferred = false;
1219 
1220  /// The workspace edit this code action performs.
1221  std::optional<WorkspaceEdit> edit;
1222 };
1223 
1224 /// Add support for JSON serialization.
1225 llvm::json::Value toJSON(const CodeAction &);
1226 
1227 } // namespace lsp
1228 } // namespace mlir
1229 
1230 namespace llvm {
1231 template <>
1232 struct format_provider<mlir::lsp::Position> {
1233  static void format(const mlir::lsp::Position &pos, raw_ostream &os,
1234  StringRef style) {
1235  assert(style.empty() && "style modifiers for this type are not supported");
1236  os << pos;
1237  }
1238 };
1239 } // namespace llvm
1240 
1241 #endif
static std::string diag(const llvm::Value &value)
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:63
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:74
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:96
This class models an LSP error as an llvm::Error.
Definition: Protocol.h:78
static char ID
Definition: Protocol.h:82
std::string message
Definition: Protocol.h:80
ErrorCode code
Definition: Protocol.h:81
std::error_code convertToErrorCode() const override
Definition: Protocol.h:90
LSPError(std::string message, ErrorCode code)
Definition: Protocol.h:84
void log(raw_ostream &os) const override
Definition: Protocol.h:87
URI in "file" scheme for a file.
Definition: Protocol.h:100
StringRef uri() const
Returns the original uri of the file.
Definition: Protocol.h:116
friend bool operator==(const URIForFile &lhs, const URIForFile &rhs)
Definition: Protocol.h:123
static void registerSupportedScheme(StringRef scheme)
Register a supported URI scheme.
Definition: Protocol.cpp:244
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:233
static llvm::Expected< URIForFile > fromURI(StringRef uri)
Try to build a URIForFile from the given URI string.
Definition: Protocol.cpp:226
StringRef scheme() const
Return the scheme of the uri.
Definition: Protocol.cpp:242
friend bool operator!=(const URIForFile &lhs, const URIForFile &rhs)
Definition: Protocol.h:126
friend bool operator<(const URIForFile &lhs, const URIForFile &rhs)
Definition: Protocol.h:129
StringRef file() const
Returns the absolute path to the file.
Definition: Protocol.h:113
Include the generated interface declarations.
Definition: CallGraph.h:229
llvm::json::Value toJSON(const URIForFile &value)
Add support for JSON serialization.
Definition: Protocol.cpp:263
raw_ostream & operator<<(raw_ostream &os, const URIForFile &value)
Definition: Protocol.cpp:267
DiagnosticSeverity
Definition: Protocol.h:670
@ Undetermined
It is up to the client to interpret diagnostics as error, warning, info or hint.
bool operator<(const CompletionItem &lhs, const CompletionItem &rhs)
Definition: Protocol.cpp:805
constexpr auto kCompletionItemKindMin
Definition: Protocol.h:789
TextDocumentSyncKind
Defines how the host (editor) should sync document changes to the language server.
Definition: Protocol.h:61
@ Incremental
Documents are synced by sending the full content on open.
@ None
Documents should not be synced at all.
@ Full
Documents are synced by always sending the full content of the document.
MarkupKind
Describes the content type that a client supports in various result literals like Hover.
Definition: Protocol.h:522
bool fromJSON(const llvm::json::Value &value, URIForFile &result, llvm::json::Path path)
Definition: Protocol.cpp:248
CompletionItemKind adjustKindToCapability(CompletionItemKind kind, CompletionItemKindBitset &supportedCompletionItemKinds)
Definition: Protocol.cpp:732
std::bitset< kCompletionItemKindMax+1 > CompletionItemKindBitset
Definition: Protocol.h:793
constexpr auto kCompletionItemKindMax
Definition: Protocol.h:791
InsertTextFormat
Defines whether the insert text in a completion item should be interpreted as plain text or a snippet...
Definition: Protocol.h:807
@ PlainText
The primary text to be inserted is treated as a plain string.
@ Snippet
The primary text to be inserted is treated as a snippet.
CompletionTriggerKind
Definition: Protocol.h:903
@ Invoked
Completion was triggered by typing an identifier (24x7 code complete), manual invocation (e....
@ TriggerTriggerForIncompleteCompletions
Completion was re-triggered as the current completion list is incomplete.
@ TriggerCharacter
Completion was triggered by a trigger character specified by the triggerCharacters properties of the ...
InlayHintKind
Inlay hint kinds.
Definition: Protocol.h:1072
@ Parameter
An inlay hint that is for a parameter.
CompletionItemKind
The kind of a completion entry.
Definition: Protocol.h:758
bool operator==(const TextEdit &lhs, const TextEdit &rhs)
Definition: Protocol.h:744
Include the generated interface declarations.
static void format(const mlir::lsp::Position &pos, raw_ostream &os, StringRef style)
Definition: Protocol.h:1233
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26
Represents a range (offset, size, and stride) where each element of the triple may be dynamic or stat...
bool codeActionStructure
Client supports CodeAction return value for textDocument/codeAction.
Definition: Protocol.h:163
bool hierarchicalDocumentSymbol
Client supports hierarchical document symbols.
Definition: Protocol.h:159
std::string name
The name of the client as defined by the client.
Definition: Protocol.h:176
std::optional< std::string > version
The client's version as defined by the client.
Definition: Protocol.h:179
std::vector< std::string > only
Requested kind of actions to return.
Definition: Protocol.h:1147
std::vector< Diagnostic > diagnostics
An array of diagnostics known on the client side overlapping the range provided to the textDocument/c...
Definition: Protocol.h:1141
TextDocumentIdentifier textDocument
The document in which the command was invoked.
Definition: Protocol.h:1160
Range range
The range for which the command was invoked.
Definition: Protocol.h:1163
CodeActionContext context
Context carrying additional information.
Definition: Protocol.h:1166
A code action represents a change that can be performed in code, e.g.
Definition: Protocol.h:1199
bool isPreferred
Marks this as a preferred action.
Definition: Protocol.h:1218
std::optional< WorkspaceEdit > edit
The workspace edit this code action performs.
Definition: Protocol.h:1221
std::optional< std::string > kind
The kind of the code action.
Definition: Protocol.h:1205
static const llvm::StringLiteral kRefactor
Definition: Protocol.h:1207
static const llvm::StringLiteral kInfo
Definition: Protocol.h:1208
std::optional< std::vector< Diagnostic > > diagnostics
The diagnostics that this code action resolves.
Definition: Protocol.h:1211
static const llvm::StringLiteral kQuickFix
Definition: Protocol.h:1206
std::string title
A short, human-readable, title for this code action.
Definition: Protocol.h:1201
std::string triggerCharacter
The trigger character (a single character) that has trigger code complete.
Definition: Protocol.h:922
CompletionTriggerKind triggerKind
How the completion was triggered.
Definition: Protocol.h:918
std::string detail
A human-readable string with additional information about this item, like type or symbol information.
Definition: Protocol.h:840
std::string filterText
A string that should be used when filtering a set of completion items.
Definition: Protocol.h:851
std::optional< TextEdit > textEdit
An edit which is applied to a document when selecting this completion.
Definition: Protocol.h:866
std::optional< MarkupContent > documentation
A human-readable string that represents a doc-comment.
Definition: Protocol.h:843
std::string insertText
A string that should be inserted to a document when selecting this completion.
Definition: Protocol.h:855
CompletionItem(const Twine &label, CompletionItemKind kind, StringRef sortText="")
Definition: Protocol.h:825
std::string label
The label of this completion item.
Definition: Protocol.h:832
bool deprecated
Indicates if this item is deprecated.
Definition: Protocol.h:874
CompletionItemKind kind
The kind of this completion item.
Definition: Protocol.h:836
std::vector< TextEdit > additionalTextEdits
An optional array of additional text edits that are applied when selecting this completion.
Definition: Protocol.h:871
InsertTextFormat insertTextFormat
The format of the insert text.
Definition: Protocol.h:859
std::string sortText
A string that should be used when comparing this item with other items.
Definition: Protocol.h:847
Represents a collection of completion items to be presented in the editor.
Definition: Protocol.h:887
std::vector< CompletionItem > items
The completion items.
Definition: Protocol.h:893
bool isIncomplete
The list is not complete.
Definition: Protocol.h:890
CompletionContext context
Definition: Protocol.h:934
Represents a related message and source code location for a diagnostic.
Definition: Protocol.h:650
std::string message
The message of this related diagnostic information.
Definition: Protocol.h:658
DiagnosticRelatedInformation(Location location, std::string message)
Definition: Protocol.h:652
Location location
The location of this related diagnostic information.
Definition: Protocol.h:656
std::string source
A human-readable string describing the source of this diagnostic, e.g.
Definition: Protocol.h:690
DiagnosticSeverity severity
The diagnostic's severity.
Definition: Protocol.h:686
Range range
The source range where the message applies.
Definition: Protocol.h:682
std::optional< std::vector< DiagnosticRelatedInformation > > relatedInformation
An array of related diagnostic information, e.g.
Definition: Protocol.h:697
std::string message
The diagnostic's message.
Definition: Protocol.h:693
std::optional< std::string > category
The diagnostic's category.
Definition: Protocol.h:703
VersionedTextDocumentIdentifier textDocument
The document that changed.
Definition: Protocol.h:506
std::vector< TextDocumentContentChangeEvent > contentChanges
The actual content changes.
Definition: Protocol.h:509
TextDocumentIdentifier textDocument
The document that was closed.
Definition: Protocol.h:472
TextDocumentItem textDocument
The document that was opened.
Definition: Protocol.h:459
Parameters for the document link request.
Definition: Protocol.h:1005
TextDocumentIdentifier textDocument
The document to provide document links for.
Definition: Protocol.h:1007
TextDocumentIdentifier textDocument
Definition: Protocol.h:636
Represents programming constructs like variables, classes, interfaces etc.
Definition: Protocol.h:596
std::string detail
More detail for this symbol, e.g the signature of a function.
Definition: Protocol.h:608
Range range
The range enclosing this symbol not including leading/trailing whitespace but everything else like co...
Definition: Protocol.h:617
Range selectionRange
The range that should be selected and revealed when this symbol is being picked, e....
Definition: Protocol.h:621
DocumentSymbol(const Twine &name, SymbolKind kind, Range range, Range selectionRange)
Definition: Protocol.h:599
std::vector< DocumentSymbol > children
Children of this symbol, e.g. properties of a class.
Definition: Protocol.h:624
DocumentSymbol(DocumentSymbol &&)=default
SymbolKind kind
The kind of this symbol.
Definition: Protocol.h:611
std::string name
The name of this symbol.
Definition: Protocol.h:605
std::optional< Range > range
An optional range is a range inside a text document that is used to visualize a hover,...
Definition: Protocol.h:549
MarkupContent contents
The hover's content.
Definition: Protocol.h:545
Hover(Range range)
Construct a default hover with the given range that uses Markdown content.
Definition: Protocol.h:542
std::optional< ClientInfo > clientInfo
Information about the client.
Definition: Protocol.h:205
ClientCapabilities capabilities
The capabilities provided by the client (editor or tool).
Definition: Protocol.h:202
std::optional< TraceLevel > trace
The initial trace setting. If omitted trace is disabled ('off').
Definition: Protocol.h:208
Inlay hint information.
Definition: Protocol.h:1093
bool paddingLeft
Render padding before the hint.
Definition: Protocol.h:1114
InlayHintKind kind
The kind of this hint.
Definition: Protocol.h:1107
Position position
The position of this hint.
Definition: Protocol.h:1097
bool paddingRight
Render padding after the hint.
Definition: Protocol.h:1121
std::string label
The label of this hint.
Definition: Protocol.h:1103
InlayHint(InlayHintKind kind, Position pos)
Definition: Protocol.h:1094
A parameter literal used in inlay hint requests.
Definition: Protocol.h:1055
Range range
The visible document range for which inlay hints should be computed.
Definition: Protocol.h:1060
TextDocumentIdentifier textDocument
The text document.
Definition: Protocol.h:1057
URIForFile uri
The text document's URI.
Definition: Protocol.h:394
Location(const URIForFile &uri, Range range)
Definition: Protocol.h:387
friend bool operator<(const Location &lhs, const Location &rhs)
Definition: Protocol.h:405
Location(const URIForFile &uri, llvm::SourceMgr &mgr, SMRange range)
Construct a Location from the given source range.
Definition: Protocol.h:390
friend bool operator!=(const Location &lhs, const Location &rhs)
Definition: Protocol.h:401
friend bool operator==(const Location &lhs, const Location &rhs)
Definition: Protocol.h:397
A single parameter of a particular signature.
Definition: Protocol.h:946
std::optional< std::pair< unsigned, unsigned > > labelOffsets
Inclusive start and exclusive end offsets withing the containing signature label.
Definition: Protocol.h:952
std::string labelString
The label of this parameter. Ignored when labelOffsets is set.
Definition: Protocol.h:948
std::string documentation
The documentation of this parameter. Optional.
Definition: Protocol.h:955
int line
Line position in a document (zero-based).
Definition: Protocol.h:293
Position(llvm::SourceMgr &mgr, SMLoc loc)
Construct a position from the given source location.
Definition: Protocol.h:286
int character
Character offset on a line in a document (zero-based).
Definition: Protocol.h:296
friend bool operator==(const Position &lhs, const Position &rhs)
Definition: Protocol.h:298
Position(int line=0, int character=0)
Definition: Protocol.h:282
friend bool operator<(const Position &lhs, const Position &rhs)
Definition: Protocol.h:305
friend bool operator<=(const Position &lhs, const Position &rhs)
Definition: Protocol.h:309
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:316
friend bool operator!=(const Position &lhs, const Position &rhs)
Definition: Protocol.h:302
std::vector< Diagnostic > diagnostics
The list of reported diagnostics.
Definition: Protocol.h:722
URIForFile uri
The URI for which diagnostic information is reported.
Definition: Protocol.h:720
PublishDiagnosticsParams(URIForFile uri, int64_t version)
Definition: Protocol.h:716
int64_t version
The version number of the document the diagnostics are published for.
Definition: Protocol.h:724
Position end
The range's end position.
Definition: Protocol.h:345
Range(llvm::SourceMgr &mgr, SMRange range)
Construct a range from the given source range.
Definition: Protocol.h:338
friend bool operator!=(const Range &lhs, const Range &rhs)
Definition: Protocol.h:350
Range(Position start, Position end)
Definition: Protocol.h:334
friend bool operator<(const Range &lhs, const Range &rhs)
Definition: Protocol.h:353
bool contains(Position pos) const
Definition: Protocol.h:357
Range(Position loc)
Definition: Protocol.h:335
bool contains(Range range) const
Definition: Protocol.h:358
friend bool operator==(const Range &lhs, const Range &rhs)
Definition: Protocol.h:347
Position start
The range's start position.
Definition: Protocol.h:342
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:364
bool includeDeclaration
Include the declaration of the current symbol.
Definition: Protocol.h:438
ReferenceContext context
Definition: Protocol.h:446
Represents the signature of a callable.
Definition: Protocol.h:986
int activeSignature
The active signature.
Definition: Protocol.h:991
int activeParameter
The active parameter of the active signature.
Definition: Protocol.h:994
std::vector< SignatureInformation > signatures
The resulting signatures.
Definition: Protocol.h:988
Represents the signature of something callable.
Definition: Protocol.h:966
std::string label
The label of this signature. Mandatory.
Definition: Protocol.h:968
std::string documentation
The documentation of this signature. Optional.
Definition: Protocol.h:971
std::vector< ParameterInformation > parameters
The parameters of this signature.
Definition: Protocol.h:974
std::string text
The new text of the range/document.
Definition: Protocol.h:497
LogicalResult applyTo(std::string &contents) const
Try to apply this change to the given contents string.
Definition: Protocol.cpp:515
std::optional< Range > range
The range of the document that changed.
Definition: Protocol.h:491
std::optional< int > rangeLength
The length of the range that got replaced.
Definition: Protocol.h:494
URIForFile uri
The text document's URI.
Definition: Protocol.h:253
std::string languageId
The text document's language identifier.
Definition: Protocol.h:234
int64_t version
The version number of this document.
Definition: Protocol.h:240
std::string text
The content of the opened text document.
Definition: Protocol.h:237
URIForFile uri
The text document's URI.
Definition: Protocol.h:231
TextDocumentIdentifier textDocument
The text document.
Definition: Protocol.h:422
Position position
The position inside the text document.
Definition: Protocol.h:425
std::string newText
The string to be inserted.
Definition: Protocol.h:741
Range range
The range of the text document to be manipulated.
Definition: Protocol.h:737
int64_t version
The version number of this document.
Definition: Protocol.h:269
URIForFile uri
The text document's URI.
Definition: Protocol.h:267
std::map< std::string, std::vector< TextEdit > > changes
Holds changes to existing resources.
Definition: Protocol.h:1179