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