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