clang-tools  9.0.0
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://github.com/Microsoft/language-server-protocol/blob/master/protocol.md
11 //
12 // This is not meant to be a complete implementation, new interfaces are added
13 // when they're needed.
14 //
15 // Each struct has a toJSON and fromJSON function, that converts between
16 // the struct and a JSON representation. (See JSON.h)
17 //
18 // Some structs also have operator<< serialization. This is for debugging and
19 // tests, and is not generally machine-readable.
20 //
21 //===----------------------------------------------------------------------===//
22 
23 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROTOCOL_H
24 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROTOCOL_H
25 
26 #include "URI.h"
27 #include "index/SymbolID.h"
28 #include "clang/Index/IndexSymbol.h"
29 #include "llvm/ADT/Optional.h"
30 #include "llvm/Support/JSON.h"
31 #include "llvm/Support/raw_ostream.h"
32 #include <bitset>
33 #include <string>
34 #include <vector>
35 
36 namespace clang {
37 namespace clangd {
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 };
53 // Models an LSP error as an llvm::Error.
54 class LSPError : public llvm::ErrorInfo<LSPError> {
55 public:
56  std::string Message;
58  static char ID;
59 
60  LSPError(std::string Message, ErrorCode Code)
61  : Message(std::move(Message)), Code(Code) {}
62 
63  void log(llvm::raw_ostream &OS) const override {
64  OS << int(Code) << ": " << Message;
65  }
66  std::error_code convertToErrorCode() const override {
67  return llvm::inconvertibleErrorCode();
68  }
69 };
70 
71 // URI in "file" scheme for a file.
72 struct URIForFile {
73  URIForFile() = default;
74 
75  /// Canonicalizes \p AbsPath via URI.
76  ///
77  /// File paths in URIForFile can come from index or local AST. Path from
78  /// index goes through URI transformation, and the final path is resolved by
79  /// URI scheme and could potentially be different from the original path.
80  /// Hence, we do the same transformation for all paths.
81  ///
82  /// Files can be referred to by several paths (e.g. in the presence of links).
83  /// Which one we prefer may depend on where we're coming from. \p TUPath is a
84  /// hint, and should usually be the main entrypoint file we're processing.
85  static URIForFile canonicalize(llvm::StringRef AbsPath,
86  llvm::StringRef TUPath);
87 
88  static llvm::Expected<URIForFile> fromURI(const URI &U,
89  llvm::StringRef HintPath);
90 
91  /// Retrieves absolute path to the file.
92  llvm::StringRef file() const { return File; }
93 
94  explicit operator bool() const { return !File.empty(); }
95  std::string uri() const { return URI::createFile(File).toString(); }
96 
97  friend bool operator==(const URIForFile &LHS, const URIForFile &RHS) {
98  return LHS.File == RHS.File;
99  }
100 
101  friend bool operator!=(const URIForFile &LHS, const URIForFile &RHS) {
102  return !(LHS == RHS);
103  }
104 
105  friend bool operator<(const URIForFile &LHS, const URIForFile &RHS) {
106  return LHS.File < RHS.File;
107  }
108 
109 private:
110  explicit URIForFile(std::string &&File) : File(std::move(File)) {}
111 
112  std::string File;
113 };
114 
115 /// Serialize/deserialize \p URIForFile to/from a string URI.
116 llvm::json::Value toJSON(const URIForFile &U);
117 bool fromJSON(const llvm::json::Value &, URIForFile &);
118 
120  /// The text document's URI.
122 };
123 llvm::json::Value toJSON(const TextDocumentIdentifier &);
124 bool fromJSON(const llvm::json::Value &, TextDocumentIdentifier &);
125 
126 struct Position {
127  /// Line position in a document (zero-based).
128  int line = 0;
129 
130  /// Character offset on a line in a document (zero-based).
131  /// WARNING: this is in UTF-16 codepoints, not bytes or characters!
132  /// Use the functions in SourceCode.h to construct/interpret Positions.
133  int character = 0;
134 
135  friend bool operator==(const Position &LHS, const Position &RHS) {
136  return std::tie(LHS.line, LHS.character) ==
137  std::tie(RHS.line, RHS.character);
138  }
139  friend bool operator!=(const Position &LHS, const Position &RHS) {
140  return !(LHS == RHS);
141  }
142  friend bool operator<(const Position &LHS, const Position &RHS) {
143  return std::tie(LHS.line, LHS.character) <
144  std::tie(RHS.line, RHS.character);
145  }
146  friend bool operator<=(const Position &LHS, const Position &RHS) {
147  return std::tie(LHS.line, LHS.character) <=
148  std::tie(RHS.line, RHS.character);
149  }
150 };
151 bool fromJSON(const llvm::json::Value &, Position &);
152 llvm::json::Value toJSON(const Position &);
153 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Position &);
154 
155 struct Range {
156  /// The range's start position.
158 
159  /// The range's end position.
161 
162  friend bool operator==(const Range &LHS, const Range &RHS) {
163  return std::tie(LHS.start, LHS.end) == std::tie(RHS.start, RHS.end);
164  }
165  friend bool operator!=(const Range &LHS, const Range &RHS) {
166  return !(LHS == RHS);
167  }
168  friend bool operator<(const Range &LHS, const Range &RHS) {
169  return std::tie(LHS.start, LHS.end) < std::tie(RHS.start, RHS.end);
170  }
171 
172  bool contains(Position Pos) const { return start <= Pos && Pos < end; }
173  bool contains(Range Rng) const {
174  return start <= Rng.start && Rng.end <= end;
175  }
176 };
177 bool fromJSON(const llvm::json::Value &, Range &);
178 llvm::json::Value toJSON(const Range &);
179 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Range &);
180 
181 struct Location {
182  /// The text document's URI.
185 
186  friend bool operator==(const Location &LHS, const Location &RHS) {
187  return LHS.uri == RHS.uri && LHS.range == RHS.range;
188  }
189 
190  friend bool operator!=(const Location &LHS, const Location &RHS) {
191  return !(LHS == RHS);
192  }
193 
194  friend bool operator<(const Location &LHS, const Location &RHS) {
195  return std::tie(LHS.uri, LHS.range) < std::tie(RHS.uri, RHS.range);
196  }
197 };
198 llvm::json::Value toJSON(const Location &);
199 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Location &);
200 
201 struct TextEdit {
202  /// The range of the text document to be manipulated. To insert
203  /// text into a document create a range where start === end.
205 
206  /// The string to be inserted. For delete operations use an
207  /// empty string.
208  std::string newText;
209 };
210 inline bool operator==(const TextEdit &L, const TextEdit &R) {
211  return std::tie(L.newText, L.range) == std::tie(R.newText, R.range);
212 }
213 bool fromJSON(const llvm::json::Value &, TextEdit &);
214 llvm::json::Value toJSON(const TextEdit &);
215 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const TextEdit &);
216 
218  /// The text document's URI.
220 
221  /// The text document's language identifier.
222  std::string languageId;
223 
224  /// The version number of this document (it will strictly increase after each
225  int version = 0;
226 
227  /// The content of the opened text document.
228  std::string text;
229 };
230 bool fromJSON(const llvm::json::Value &, TextDocumentItem &);
231 
232 enum class TraceLevel {
233  Off = 0,
234  Messages = 1,
235  Verbose = 2,
236 };
237 bool fromJSON(const llvm::json::Value &E, TraceLevel &Out);
238 
239 struct NoParams {};
240 inline bool fromJSON(const llvm::json::Value &, NoParams &) { return true; }
243 
244 /// Defines how the host (editor) should sync document changes to the language
245 /// server.
247  /// Documents should not be synced at all.
248  None = 0,
249 
250  /// Documents are synced by always sending the full content of the document.
251  Full = 1,
252 
253  /// Documents are synced by sending the full content on open. After that
254  /// only incremental updates to the document are send.
255  Incremental = 2,
256 };
257 
258 /// The kind of a completion entry.
259 enum class CompletionItemKind {
260  Missing = 0,
261  Text = 1,
262  Method = 2,
263  Function = 3,
264  Constructor = 4,
265  Field = 5,
266  Variable = 6,
267  Class = 7,
268  Interface = 8,
269  Module = 9,
270  Property = 10,
271  Unit = 11,
272  Value = 12,
273  Enum = 13,
274  Keyword = 14,
275  Snippet = 15,
276  Color = 16,
277  File = 17,
278  Reference = 18,
279  Folder = 19,
280  EnumMember = 20,
281  Constant = 21,
282  Struct = 22,
283  Event = 23,
284  Operator = 24,
285  TypeParameter = 25,
286 };
287 bool fromJSON(const llvm::json::Value &, CompletionItemKind &);
288 constexpr auto CompletionItemKindMin =
289  static_cast<size_t>(CompletionItemKind::Text);
290 constexpr auto CompletionItemKindMax =
291  static_cast<size_t>(CompletionItemKind::TypeParameter);
292 using CompletionItemKindBitset = std::bitset<CompletionItemKindMax + 1>;
293 bool fromJSON(const llvm::json::Value &, CompletionItemKindBitset &);
296  CompletionItemKindBitset &SupportedCompletionItemKinds);
297 
298 /// A symbol kind.
299 enum class SymbolKind {
300  File = 1,
301  Module = 2,
302  Namespace = 3,
303  Package = 4,
304  Class = 5,
305  Method = 6,
306  Property = 7,
307  Field = 8,
308  Constructor = 9,
309  Enum = 10,
310  Interface = 11,
311  Function = 12,
312  Variable = 13,
313  Constant = 14,
314  String = 15,
315  Number = 16,
316  Boolean = 17,
317  Array = 18,
318  Object = 19,
319  Key = 20,
320  Null = 21,
321  EnumMember = 22,
322  Struct = 23,
323  Event = 24,
324  Operator = 25,
325  TypeParameter = 26
326 };
327 bool fromJSON(const llvm::json::Value &, SymbolKind &);
328 constexpr auto SymbolKindMin = static_cast<size_t>(SymbolKind::File);
329 constexpr auto SymbolKindMax = static_cast<size_t>(SymbolKind::TypeParameter);
330 using SymbolKindBitset = std::bitset<SymbolKindMax + 1>;
331 bool fromJSON(const llvm::json::Value &, SymbolKindBitset &);
333  SymbolKindBitset &supportedSymbolKinds);
334 
335 // Convert a index::SymbolKind to clangd::SymbolKind (LSP)
336 // Note, some are not perfect matches and should be improved when this LSP
337 // issue is addressed:
338 // https://github.com/Microsoft/language-server-protocol/issues/344
340 
341 // Determines the encoding used to measure offsets and lengths of source in LSP.
342 enum class OffsetEncoding {
343  // Any string is legal on the wire. Unrecognized encodings parse as this.
345  // Length counts code units of UTF-16 encoded text. (Standard LSP behavior).
346  UTF16,
347  // Length counts bytes of UTF-8 encoded text. (Clangd extension).
348  UTF8,
349  // Length counts codepoints in unicode text. (Clangd extension).
350  UTF32,
351 };
352 llvm::json::Value toJSON(const OffsetEncoding &);
353 bool fromJSON(const llvm::json::Value &, OffsetEncoding &);
354 llvm::raw_ostream &operator<<(llvm::raw_ostream &, OffsetEncoding);
355 
356 // Describes the content type that a client supports in various result literals
357 // like `Hover`, `ParameterInfo` or `CompletionItem`.
358 enum class MarkupKind {
359  PlainText,
360  Markdown,
361 };
362 bool fromJSON(const llvm::json::Value &, MarkupKind &);
363 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, MarkupKind);
364 
365 // This struct doesn't mirror LSP!
366 // The protocol defines deeply nested structures for client capabilities.
367 // Instead of mapping them all, this just parses out the bits we care about.
369  /// The supported set of SymbolKinds for workspace/symbol.
370  /// workspace.symbol.symbolKind.valueSet
371  llvm::Optional<SymbolKindBitset> WorkspaceSymbolKinds;
372 
373  /// Whether the client accepts diagnostics with codeActions attached inline.
374  /// textDocument.publishDiagnostics.codeActionsInline.
375  bool DiagnosticFixes = false;
376 
377  /// Whether the client accepts diagnostics with related locations.
378  /// textDocument.publishDiagnostics.relatedInformation.
380 
381  /// Whether the client accepts diagnostics with category attached to it
382  /// using the "category" extension.
383  /// textDocument.publishDiagnostics.categorySupport
384  bool DiagnosticCategory = false;
385 
386  /// Client supports snippets as insert text.
387  /// textDocument.completion.completionItem.snippetSupport
388  bool CompletionSnippets = false;
389 
390  /// Client supports completions with additionalTextEdit near the cursor.
391  /// This is a clangd extension. (LSP says this is for unrelated text only).
392  /// textDocument.completion.editsNearCursor
393  bool CompletionFixes = false;
394 
395  /// Client supports hierarchical document symbols.
396  /// textDocument.documentSymbol.hierarchicalDocumentSymbolSupport
397  bool HierarchicalDocumentSymbol = false;
398 
399  /// Client supports signature help.
400  /// textDocument.signatureHelp
401  bool HasSignatureHelp = false;
402 
403  /// Client supports processing label offsets instead of a simple label string.
404  /// textDocument.signatureHelp.signatureInformation.parameterInformation.labelOffsetSupport
405  bool OffsetsInSignatureHelp = false;
406 
407  /// The supported set of CompletionItemKinds for textDocument/completion.
408  /// textDocument.completion.completionItemKind.valueSet
409  llvm::Optional<CompletionItemKindBitset> CompletionItemKinds;
410 
411  /// Client supports CodeAction return value for textDocument/codeAction.
412  /// textDocument.codeAction.codeActionLiteralSupport.
413  bool CodeActionStructure = false;
414 
415  /// Client supports semantic highlighting.
416  /// textDocument.semanticHighlightingCapabilities.semanticHighlighting
417  bool SemanticHighlighting = false;
418 
419  /// Supported encodings for LSP character offsets. (clangd extension).
420  llvm::Optional<std::vector<OffsetEncoding>> offsetEncoding;
421 
422  /// The content format that should be used for Hover requests.
423  /// textDocument.hover.contentEncoding
424  MarkupKind HoverContentFormat = MarkupKind::PlainText;
425 };
426 bool fromJSON(const llvm::json::Value &, ClientCapabilities &);
427 
428 /// Clangd extension that's used in the 'compilationDatabaseChanges' in
429 /// workspace/didChangeConfiguration to record updates to the in-memory
430 /// compilation database.
432  std::string workingDirectory;
433  std::vector<std::string> compilationCommand;
434 };
435 bool fromJSON(const llvm::json::Value &, ClangdCompileCommand &);
436 
437 /// Clangd extension: parameters configurable at any time, via the
438 /// `workspace/didChangeConfiguration` notification.
439 /// LSP defines this type as `any`.
441  // Changes to the in-memory compilation database.
442  // The key of the map is a file name.
443  std::map<std::string, ClangdCompileCommand> compilationDatabaseChanges;
444 };
445 bool fromJSON(const llvm::json::Value &, ConfigurationSettings &);
446 
447 /// Clangd extension: parameters configurable at `initialize` time.
448 /// LSP defines this type as `any`.
450  // What we can change throught the didChangeConfiguration request, we can
451  // also set through the initialize request (initializationOptions field).
453 
454  llvm::Optional<std::string> compilationDatabasePath;
455  // Additional flags to be included in the "fallback command" used when
456  // the compilation database doesn't describe an opened file.
457  // The command used will be approximately `clang $FILE $fallbackFlags`.
458  std::vector<std::string> fallbackFlags;
459 
460  /// Clients supports show file status for textDocument/clangd.fileStatus.
461  bool FileStatus = false;
462 };
463 bool fromJSON(const llvm::json::Value &, InitializationOptions &);
464 
466  /// The process Id of the parent process that started
467  /// the server. Is null if the process has not been started by another
468  /// process. If the parent process is not alive then the server should exit
469  /// (see exit notification) its process.
470  llvm::Optional<int> processId;
471 
472  /// The rootPath of the workspace. Is null
473  /// if no folder is open.
474  ///
475  /// @deprecated in favour of rootUri.
476  llvm::Optional<std::string> rootPath;
477 
478  /// The rootUri of the workspace. Is null if no
479  /// folder is open. If both `rootPath` and `rootUri` are set
480  /// `rootUri` wins.
481  llvm::Optional<URIForFile> rootUri;
482 
483  // User provided initialization options.
484  // initializationOptions?: any;
485 
486  /// The capabilities provided by the client (editor or tool)
488 
489  /// The initial trace setting. If omitted trace is disabled ('off').
490  llvm::Optional<TraceLevel> trace;
491 
492  /// User-provided initialization options.
494 };
495 bool fromJSON(const llvm::json::Value &, InitializeParams &);
496 
497 enum class MessageType {
498  /// An error message.
499  Error = 1,
500  /// A warning message.
501  Warning = 2,
502  /// An information message.
503  Info = 3,
504  /// A log message.
505  Log = 4,
506 };
507 llvm::json::Value toJSON(const MessageType &);
508 
509 /// The show message notification is sent from a server to a client to ask the
510 /// client to display a particular message in the user interface.
512  /// The message type.
514  /// The actual message.
515  std::string message;
516 };
517 llvm::json::Value toJSON(const ShowMessageParams &);
518 
520  /// The document that was opened.
522 };
523 bool fromJSON(const llvm::json::Value &, DidOpenTextDocumentParams &);
524 
526  /// The document that was closed.
528 };
529 bool fromJSON(const llvm::json::Value &, DidCloseTextDocumentParams &);
530 
532  /// The range of the document that changed.
533  llvm::Optional<Range> range;
534 
535  /// The length of the range that got replaced.
536  llvm::Optional<int> rangeLength;
537 
538  /// The new text of the range/document.
539  std::string text;
540 };
541 bool fromJSON(const llvm::json::Value &, TextDocumentContentChangeEvent &);
542 
544  /// The document that did change. The version number points
545  /// to the version after all provided content changes have
546  /// been applied.
548 
549  /// The actual content changes.
550  std::vector<TextDocumentContentChangeEvent> contentChanges;
551 
552  /// Forces diagnostics to be generated, or to not be generated, for this
553  /// version of the file. If not set, diagnostics are eventually consistent:
554  /// either they will be provided for this version or some subsequent one.
555  /// This is a clangd extension.
556  llvm::Optional<bool> wantDiagnostics;
557 };
558 bool fromJSON(const llvm::json::Value &, DidChangeTextDocumentParams &);
559 
560 enum class FileChangeType {
561  /// The file got created.
562  Created = 1,
563  /// The file got changed.
564  Changed = 2,
565  /// The file got deleted.
566  Deleted = 3
567 };
568 bool fromJSON(const llvm::json::Value &E, FileChangeType &Out);
569 
570 struct FileEvent {
571  /// The file's URI.
573  /// The change type.
575 };
576 bool fromJSON(const llvm::json::Value &, FileEvent &);
577 
579  /// The actual file events.
580  std::vector<FileEvent> changes;
581 };
582 bool fromJSON(const llvm::json::Value &, DidChangeWatchedFilesParams &);
583 
586 };
587 bool fromJSON(const llvm::json::Value &, DidChangeConfigurationParams &);
588 
589 // Note: we do not parse FormattingOptions for *FormattingParams.
590 // In general, we use a clang-format style detected from common mechanisms
591 // (.clang-format files and the -fallback-style flag).
592 // It would be possible to override these with FormatOptions, but:
593 // - the protocol makes FormatOptions mandatory, so many clients set them to
594 // useless values, and we can't tell when to respect them
595 // - we also format in other places, where FormatOptions aren't available.
596 
598  /// The document to format.
600 
601  /// The range to format
603 };
604 bool fromJSON(const llvm::json::Value &, DocumentRangeFormattingParams &);
605 
607  /// The document to format.
609 
610  /// The position at which this request was sent.
612 
613  /// The character that has been typed.
614  std::string ch;
615 };
616 bool fromJSON(const llvm::json::Value &, DocumentOnTypeFormattingParams &);
617 
619  /// The document to format.
621 };
622 bool fromJSON(const llvm::json::Value &, DocumentFormattingParams &);
623 
625  // The text document to find symbols in.
627 };
628 bool fromJSON(const llvm::json::Value &, DocumentSymbolParams &);
629 
630 /// Represents a related message and source code location for a diagnostic.
631 /// This should be used to point to code locations that cause or related to a
632 /// diagnostics, e.g when duplicating a symbol in a scope.
634  /// The location of this related diagnostic information.
636  /// The message of this related diagnostic information.
637  std::string message;
638 };
639 llvm::json::Value toJSON(const DiagnosticRelatedInformation &);
640 
641 struct CodeAction;
642 struct Diagnostic {
643  /// The range at which the message applies.
645 
646  /// The diagnostic's severity. Can be omitted. If omitted it is up to the
647  /// client to interpret diagnostics as error, warning, info or hint.
648  int severity = 0;
649 
650  /// The diagnostic's code. Can be omitted.
651  std::string code;
652 
653  /// A human-readable string describing the source of this
654  /// diagnostic, e.g. 'typescript' or 'super lint'.
655  std::string source;
656 
657  /// The diagnostic's message.
658  std::string message;
659 
660  /// An array of related diagnostic information, e.g. when symbol-names within
661  /// a scope collide all definitions can be marked via this property.
662  llvm::Optional<std::vector<DiagnosticRelatedInformation>> relatedInformation;
663 
664  /// The diagnostic's category. Can be omitted.
665  /// An LSP extension that's used to send the name of the category over to the
666  /// client. The category typically describes the compilation stage during
667  /// which the issue was produced, e.g. "Semantic Issue" or "Parse Issue".
668  llvm::Optional<std::string> category;
669 
670  /// Clangd extension: code actions related to this diagnostic.
671  /// Only with capability textDocument.publishDiagnostics.codeActionsInline.
672  /// (These actions can also be obtained using textDocument/codeAction).
673  llvm::Optional<std::vector<CodeAction>> codeActions;
674 };
675 llvm::json::Value toJSON(const Diagnostic &);
676 
677 /// A LSP-specific comparator used to find diagnostic in a container like
678 /// std:map.
679 /// We only use the required fields of Diagnostic to do the comparsion to avoid
680 /// any regression issues from LSP clients (e.g. VScode), see
681 /// https://git.io/vbr29
683  bool operator()(const Diagnostic &LHS, const Diagnostic &RHS) const {
684  return std::tie(LHS.range, LHS.message) < std::tie(RHS.range, RHS.message);
685  }
686 };
687 bool fromJSON(const llvm::json::Value &, Diagnostic &);
688 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Diagnostic &);
689 
691  /// An array of diagnostics.
692  std::vector<Diagnostic> diagnostics;
693 };
694 bool fromJSON(const llvm::json::Value &, CodeActionContext &);
695 
697  /// The document in which the command was invoked.
699 
700  /// The range for which the command was invoked.
702 
703  /// Context carrying additional information.
705 };
706 bool fromJSON(const llvm::json::Value &, CodeActionParams &);
707 
709  /// Holds changes to existing resources.
710  llvm::Optional<std::map<std::string, std::vector<TextEdit>>> changes;
711 
712  /// Note: "documentChanges" is not currently used because currently there is
713  /// no support for versioned edits.
714 };
715 bool fromJSON(const llvm::json::Value &, WorkspaceEdit &);
716 llvm::json::Value toJSON(const WorkspaceEdit &WE);
717 
718 /// Arguments for the 'applyTweak' command. The server sends these commands as a
719 /// response to the textDocument/codeAction request. The client can later send a
720 /// command back to the server if the user requests to execute a particular code
721 /// tweak.
722 struct TweakArgs {
723  /// A file provided by the client on a textDocument/codeAction request.
725  /// A selection provided by the client on a textDocument/codeAction request.
727  /// ID of the tweak that should be executed. Corresponds to Tweak::id().
728  std::string tweakID;
729 };
730 bool fromJSON(const llvm::json::Value &, TweakArgs &);
731 llvm::json::Value toJSON(const TweakArgs &A);
732 
733 /// Exact commands are not specified in the protocol so we define the
734 /// ones supported by Clangd here. The protocol specifies the command arguments
735 /// to be "any[]" but to make this safer and more manageable, each command we
736 /// handle maps to a certain llvm::Optional of some struct to contain its
737 /// arguments. Different commands could reuse the same llvm::Optional as
738 /// arguments but a command that needs different arguments would simply add a
739 /// new llvm::Optional and not use any other ones. In practice this means only
740 /// one argument type will be parsed and set.
742  // Command to apply fix-its. Uses WorkspaceEdit as argument.
743  const static llvm::StringLiteral CLANGD_APPLY_FIX_COMMAND;
744  // Command to apply the code action. Uses TweakArgs as argument.
745  const static llvm::StringLiteral CLANGD_APPLY_TWEAK;
746 
747  /// The command identifier, e.g. CLANGD_APPLY_FIX_COMMAND
748  std::string command;
749 
750  // Arguments
751  llvm::Optional<WorkspaceEdit> workspaceEdit;
752  llvm::Optional<TweakArgs> tweakArgs;
753 };
754 bool fromJSON(const llvm::json::Value &, ExecuteCommandParams &);
755 
756 struct Command : public ExecuteCommandParams {
757  std::string title;
758 };
759 llvm::json::Value toJSON(const Command &C);
760 
761 /// A code action represents a change that can be performed in code, e.g. to fix
762 /// a problem or to refactor code.
763 ///
764 /// A CodeAction must set either `edit` and/or a `command`. If both are
765 /// supplied, the `edit` is applied first, then the `command` is executed.
766 struct CodeAction {
767  /// A short, human-readable, title for this code action.
768  std::string title;
769 
770  /// The kind of the code action.
771  /// Used to filter code actions.
772  llvm::Optional<std::string> kind;
773  const static llvm::StringLiteral QUICKFIX_KIND;
774  const static llvm::StringLiteral REFACTOR_KIND;
775  const static llvm::StringLiteral INFO_KIND;
776 
777  /// The diagnostics that this code action resolves.
778  llvm::Optional<std::vector<Diagnostic>> diagnostics;
779 
780  /// The workspace edit this code action performs.
781  llvm::Optional<WorkspaceEdit> edit;
782 
783  /// A command this code action executes. If a code action provides an edit
784  /// and a command, first the edit is executed and then the command.
785  llvm::Optional<Command> command;
786 };
787 llvm::json::Value toJSON(const CodeAction &);
788 
789 /// Represents programming constructs like variables, classes, interfaces etc.
790 /// that appear in a document. Document symbols can be hierarchical and they
791 /// have two ranges: one that encloses its definition and one that points to its
792 /// most interesting range, e.g. the range of an identifier.
794  /// The name of this symbol.
795  std::string name;
796 
797  /// More detail for this symbol, e.g the signature of a function.
798  std::string detail;
799 
800  /// The kind of this symbol.
802 
803  /// Indicates if this symbol is deprecated.
805 
806  /// The range enclosing this symbol not including leading/trailing whitespace
807  /// but everything else like comments. This information is typically used to
808  /// determine if the clients cursor is inside the symbol to reveal in the
809  /// symbol in the UI.
811 
812  /// The range that should be selected and revealed when this symbol is being
813  /// picked, e.g the name of a function. Must be contained by the `range`.
815 
816  /// Children of this symbol, e.g. properties of a class.
817  std::vector<DocumentSymbol> children;
818 };
819 llvm::raw_ostream &operator<<(llvm::raw_ostream &O, const DocumentSymbol &S);
820 llvm::json::Value toJSON(const DocumentSymbol &S);
821 
822 /// Represents information about programming constructs like variables, classes,
823 /// interfaces etc.
825  /// The name of this symbol.
826  std::string name;
827 
828  /// The kind of this symbol.
830 
831  /// The location of this symbol.
833 
834  /// The name of the symbol containing this symbol.
835  std::string containerName;
836 };
837 llvm::json::Value toJSON(const SymbolInformation &);
838 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SymbolInformation &);
839 
840 /// Represents information about identifier.
841 /// This is returned from textDocument/symbolInfo, which is a clangd extension.
843  std::string name;
844 
845  std::string containerName;
846 
847  /// Unified Symbol Resolution identifier
848  /// This is an opaque string uniquely identifying a symbol.
849  /// Unlike SymbolID, it is variable-length and somewhat human-readable.
850  /// It is a common representation across several clang tools.
851  /// (See USRGeneration.h)
852  std::string USR;
853 
854  llvm::Optional<SymbolID> ID;
855 };
856 llvm::json::Value toJSON(const SymbolDetails &);
857 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SymbolDetails &);
858 bool operator==(const SymbolDetails &, const SymbolDetails &);
859 
860 /// The parameters of a Workspace Symbol Request.
862  /// A non-empty query string
863  std::string query;
864 };
865 bool fromJSON(const llvm::json::Value &, WorkspaceSymbolParams &);
866 
869 };
870 llvm::json::Value toJSON(const ApplyWorkspaceEditParams &);
871 
873  /// The text document.
875 
876  /// The position inside the text document.
878 };
879 bool fromJSON(const llvm::json::Value &, TextDocumentPositionParams &);
880 
882  /// Completion was triggered by typing an identifier (24x7 code
883  /// complete), manual invocation (e.g Ctrl+Space) or via API.
884  Invoked = 1,
885  /// Completion was triggered by a trigger character specified by
886  /// the `triggerCharacters` properties of the `CompletionRegistrationOptions`.
887  TriggerCharacter = 2,
888  /// Completion was re-triggered as the current completion list is incomplete.
890 };
891 
893  /// How the completion was triggered.
895  /// The trigger character (a single character) that has trigger code complete.
896  /// Is undefined if `triggerKind !== CompletionTriggerKind.TriggerCharacter`
897  std::string triggerCharacter;
898 };
899 bool fromJSON(const llvm::json::Value &, CompletionContext &);
900 
903 };
904 bool fromJSON(const llvm::json::Value &, CompletionParams &);
905 
908  std::string value;
909 };
910 llvm::json::Value toJSON(const MarkupContent &MC);
911 
912 struct Hover {
913  /// The hover's content
915 
916  /// An optional range is a range inside a text document
917  /// that is used to visualize a hover, e.g. by changing the background color.
918  llvm::Optional<Range> range;
919 };
920 llvm::json::Value toJSON(const Hover &H);
921 
922 /// Defines whether the insert text in a completion item should be interpreted
923 /// as plain text or a snippet.
924 enum class InsertTextFormat {
925  Missing = 0,
926  /// The primary text to be inserted is treated as a plain string.
927  PlainText = 1,
928  /// The primary text to be inserted is treated as a snippet.
929  ///
930  /// A snippet can define tab stops and placeholders with `$1`, `$2`
931  /// and `${3:foo}`. `$0` defines the final tab stop, it defaults to the end
932  /// of the snippet. Placeholders with equal identifiers are linked, that is
933  /// typing in one will update others too.
934  ///
935  /// See also:
936  /// https//github.com/Microsoft/vscode/blob/master/src/vs/editor/contrib/snippet/common/snippet.md
937  Snippet = 2,
938 };
939 
941  /// The label of this completion item. By default also the text that is
942  /// inserted when selecting this completion.
943  std::string label;
944 
945  /// The kind of this completion item. Based of the kind an icon is chosen by
946  /// the editor.
948 
949  /// A human-readable string with additional information about this item, like
950  /// type or symbol information.
951  std::string detail;
952 
953  /// A human-readable string that represents a doc-comment.
954  std::string documentation;
955 
956  /// A string that should be used when comparing this item with other items.
957  /// When `falsy` the label is used.
958  std::string sortText;
959 
960  /// A string that should be used when filtering a set of completion items.
961  /// When `falsy` the label is used.
962  std::string filterText;
963 
964  /// A string that should be inserted to a document when selecting this
965  /// completion. When `falsy` the label is used.
966  std::string insertText;
967 
968  /// The format of the insert text. The format applies to both the `insertText`
969  /// property and the `newText` property of a provided `textEdit`.
971 
972  /// An edit which is applied to a document when selecting this completion.
973  /// When an edit is provided `insertText` is ignored.
974  ///
975  /// Note: The range of the edit must be a single line range and it must
976  /// contain the position at which completion has been requested.
977  llvm::Optional<TextEdit> textEdit;
978 
979  /// An optional array of additional text edits that are applied when selecting
980  /// this completion. Edits must not overlap with the main edit nor with
981  /// themselves.
982  std::vector<TextEdit> additionalTextEdits;
983 
984  /// Indicates if this item is deprecated.
985  bool deprecated = false;
986 
987  // TODO(krasimir): The following optional fields defined by the language
988  // server protocol are unsupported:
989  //
990  // data?: any - A data entry field that is preserved on a completion item
991  // between a completion and a completion resolve request.
992 };
993 llvm::json::Value toJSON(const CompletionItem &);
994 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const CompletionItem &);
995 
996 bool operator<(const CompletionItem &, const CompletionItem &);
997 
998 /// Represents a collection of completion items to be presented in the editor.
1000  /// The list is not complete. Further typing should result in recomputing the
1001  /// list.
1002  bool isIncomplete = false;
1003 
1004  /// The completion items.
1005  std::vector<CompletionItem> items;
1006 };
1007 llvm::json::Value toJSON(const CompletionList &);
1008 
1009 /// A single parameter of a particular signature.
1011 
1012  /// The label of this parameter. Ignored when labelOffsets is set.
1013  std::string labelString;
1014 
1015  /// Inclusive start and exclusive end offsets withing the containing signature
1016  /// label.
1017  /// Offsets are computed by lspLength(), which counts UTF-16 code units by
1018  /// default but that can be overriden, see its documentation for details.
1019  llvm::Optional<std::pair<unsigned, unsigned>> labelOffsets;
1020 
1021  /// The documentation of this parameter. Optional.
1022  std::string documentation;
1023 };
1024 llvm::json::Value toJSON(const ParameterInformation &);
1025 
1026 /// Represents the signature of something callable.
1028 
1029  /// The label of this signature. Mandatory.
1030  std::string label;
1031 
1032  /// The documentation of this signature. Optional.
1033  std::string documentation;
1034 
1035  /// The parameters of this signature.
1036  std::vector<ParameterInformation> parameters;
1037 };
1038 llvm::json::Value toJSON(const SignatureInformation &);
1039 llvm::raw_ostream &operator<<(llvm::raw_ostream &,
1040  const SignatureInformation &);
1041 
1042 /// Represents the signature of a callable.
1044 
1045  /// The resulting signatures.
1046  std::vector<SignatureInformation> signatures;
1047 
1048  /// The active signature.
1049  int activeSignature = 0;
1050 
1051  /// The active parameter of the active signature.
1052  int activeParameter = 0;
1053 
1054  /// Position of the start of the argument list, including opening paren. e.g.
1055  /// foo("first arg", "second arg",
1056  /// ^-argListStart ^-cursor
1057  /// This is a clangd-specific extension, it is only available via C++ API and
1058  /// not currently serialized for the LSP.
1060 };
1061 llvm::json::Value toJSON(const SignatureHelp &);
1062 
1064  /// The document that was opened.
1066 
1067  /// The position at which this request was sent.
1069 
1070  /// The new name of the symbol.
1071  std::string newName;
1072 };
1073 bool fromJSON(const llvm::json::Value &, RenameParams &);
1074 
1075 enum class DocumentHighlightKind { Text = 1, Read = 2, Write = 3 };
1076 
1077 /// A document highlight is a range inside a text document which deserves
1078 /// special attention. Usually a document highlight is visualized by changing
1079 /// the background color of its range.
1080 
1082  /// The range this highlight applies to.
1084 
1085  /// The highlight kind, default is DocumentHighlightKind.Text.
1087 
1088  friend bool operator<(const DocumentHighlight &LHS,
1089  const DocumentHighlight &RHS) {
1090  int LHSKind = static_cast<int>(LHS.kind);
1091  int RHSKind = static_cast<int>(RHS.kind);
1092  return std::tie(LHS.range, LHSKind) < std::tie(RHS.range, RHSKind);
1093  }
1094 
1095  friend bool operator==(const DocumentHighlight &LHS,
1096  const DocumentHighlight &RHS) {
1097  return LHS.kind == RHS.kind && LHS.range == RHS.range;
1098  }
1099 };
1100 llvm::json::Value toJSON(const DocumentHighlight &DH);
1101 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const DocumentHighlight &);
1102 
1103 enum class TypeHierarchyDirection { Children = 0, Parents = 1, Both = 2 };
1104 bool fromJSON(const llvm::json::Value &E, TypeHierarchyDirection &Out);
1105 
1106 /// The type hierarchy params is an extension of the
1107 /// `TextDocumentPositionsParams` with optional properties which can be used to
1108 /// eagerly resolve the item when requesting from the server.
1110  /// The hierarchy levels to resolve. `0` indicates no level.
1111  int resolve = 0;
1112 
1113  /// The direction of the hierarchy levels to resolve.
1115 };
1116 bool fromJSON(const llvm::json::Value &, TypeHierarchyParams &);
1117 
1119  /// The human readable name of the hierarchy item.
1120  std::string name;
1121 
1122  /// Optional detail for the hierarchy item. It can be, for instance, the
1123  /// signature of a function or method.
1124  llvm::Optional<std::string> detail;
1125 
1126  /// The kind of the hierarchy item. For instance, class or interface.
1128 
1129  /// `true` if the hierarchy item is deprecated. Otherwise, `false`.
1130  bool deprecated = false;
1131 
1132  /// The URI of the text document where this type hierarchy item belongs to.
1134 
1135  /// The range enclosing this type hierarchy item not including
1136  /// leading/trailing whitespace but everything else like comments. This
1137  /// information is typically used to determine if the client's cursor is
1138  /// inside the type hierarch item to reveal in the symbol in the UI.
1140 
1141  /// The range that should be selected and revealed when this type hierarchy
1142  /// item is being picked, e.g. the name of a function. Must be contained by
1143  /// the `range`.
1145 
1146  /// If this type hierarchy item is resolved, it contains the direct parents.
1147  /// Could be empty if the item does not have direct parents. If not defined,
1148  /// the parents have not been resolved yet.
1149  llvm::Optional<std::vector<TypeHierarchyItem>> parents;
1150 
1151  /// If this type hierarchy item is resolved, it contains the direct children
1152  /// of the current item. Could be empty if the item does not have any
1153  /// descendants. If not defined, the children have not been resolved.
1154  llvm::Optional<std::vector<TypeHierarchyItem>> children;
1155 
1156  /// An optional 'data' filed, which can be used to identify a type hierarchy
1157  /// item in a resolve request.
1158  llvm::Optional<std::string> data;
1159 };
1160 llvm::json::Value toJSON(const TypeHierarchyItem &);
1161 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const TypeHierarchyItem &);
1162 bool fromJSON(const llvm::json::Value &, TypeHierarchyItem &);
1163 
1164 /// Parameters for the `typeHierarchy/resolve` request.
1166  /// The item to resolve.
1168 
1169  /// The hierarchy levels to resolve. `0` indicates no level.
1170  int resolve;
1171 
1172  /// The direction of the hierarchy levels to resolve.
1174 };
1175 bool fromJSON(const llvm::json::Value &, ResolveTypeHierarchyItemParams &);
1176 
1178  // For now, no options like context.includeDeclaration are supported.
1179 };
1180 bool fromJSON(const llvm::json::Value &, ReferenceParams &);
1181 
1182 /// Clangd extension: indicates the current state of the file in clangd,
1183 /// sent from server via the `textDocument/clangd.fileStatus` notification.
1184 struct FileStatus {
1185  /// The text document's URI.
1187  /// The human-readable string presents the current state of the file, can be
1188  /// shown in the UI (e.g. status bar).
1189  std::string state;
1190  // FIXME: add detail messages.
1191 };
1192 llvm::json::Value toJSON(const FileStatus &FStatus);
1193 
1194 /// Represents a semantic highlighting information that has to be applied on a
1195 /// specific line of the text document.
1197  /// The line these highlightings belong to.
1198  int Line;
1199  /// The base64 encoded string of highlighting tokens.
1200  std::string Tokens;
1201 };
1203  const SemanticHighlightingInformation &Rhs);
1204 llvm::json::Value toJSON(const SemanticHighlightingInformation &Highlighting);
1205 
1206 /// Parameters for the semantic highlighting (server-side) push notification.
1208  /// The textdocument these highlightings belong to.
1210  /// The lines of highlightings that should be sent.
1211  std::vector<SemanticHighlightingInformation> Lines;
1212 };
1213 llvm::json::Value toJSON(const SemanticHighlightingParams &Highlighting);
1214 
1215 } // namespace clangd
1216 } // namespace clang
1217 
1218 namespace llvm {
1219 template <> struct format_provider<clang::clangd::Position> {
1220  static void format(const clang::clangd::Position &Pos, raw_ostream &OS,
1221  StringRef Style) {
1222  assert(Style.empty() && "style modifiers for this type are not supported");
1223  OS << Pos;
1224  }
1225 };
1226 } // namespace llvm
1227 
1228 #endif
std::string insertText
A string that should be inserted to a document when selecting this completion.
Definition: Protocol.h:966
Range range
The range to format.
Definition: Protocol.h:602
std::string USR
Unified Symbol Resolution identifier This is an opaque string uniquely identifying a symbol...
Definition: Protocol.h:852
const tooling::CompileCommand & Command
friend bool operator<(const Location &LHS, const Location &RHS)
Definition: Protocol.h:194
llvm::Optional< std::vector< TypeHierarchyItem > > children
If this type hierarchy item is resolved, it contains the direct children of the current item...
Definition: Protocol.h:1154
TextDocumentIdentifier textDocument
The document to format.
Definition: Protocol.h:620
URIForFile uri
The file&#39;s URI.
Definition: Protocol.h:572
std::string code
The diagnostic&#39;s code. Can be omitted.
Definition: Protocol.h:651
llvm::json::Value toJSON(const FuzzyFindRequest &Request)
Definition: Index.cpp:48
Location location
The location of this symbol.
Definition: Protocol.h:832
friend bool operator==(const Location &LHS, const Location &RHS)
Definition: Protocol.h:186
llvm::Optional< TextEdit > textEdit
An edit which is applied to a document when selecting this completion.
Definition: Protocol.h:977
Exact commands are not specified in the protocol so we define the ones supported by Clangd here...
Definition: Protocol.h:741
TextDocumentIdentifier textDocument
The document to format.
Definition: Protocol.h:608
llvm::Optional< SymbolKindBitset > WorkspaceSymbolKinds
The supported set of SymbolKinds for workspace/symbol.
Definition: Protocol.h:371
Some operations such as code completion produce a set of candidates.
llvm::Optional< URIForFile > rootUri
The rootUri of the workspace.
Definition: Protocol.h:481
Position start
The range&#39;s start position.
Definition: Protocol.h:157
friend bool operator==(const URIForFile &LHS, const URIForFile &RHS)
Definition: Protocol.h:97
Represents a collection of completion items to be presented in the editor.
Definition: Protocol.h:999
Range range
The range this highlight applies to.
Definition: Protocol.h:1083
llvm::Optional< bool > wantDiagnostics
Forces diagnostics to be generated, or to not be generated, for this version of the file...
Definition: Protocol.h:556
friend bool operator<=(const Position &LHS, const Position &RHS)
Definition: Protocol.h:146
std::vector< std::string > compilationCommand
Definition: Protocol.h:433
Range range
The range for which the command was invoked.
Definition: Protocol.h:701
CodeActionContext context
Context carrying additional information.
Definition: Protocol.h:704
static const llvm::StringLiteral CLANGD_APPLY_FIX_COMMAND
Definition: Protocol.h:743
Clangd extension: parameters configurable at initialize time.
Definition: Protocol.h:449
std::string labelString
The label of this parameter. Ignored when labelOffsets is set.
Definition: Protocol.h:1013
std::string ch
The character that has been typed.
Definition: Protocol.h:614
std::vector< CompletionItem > items
The completion items.
Definition: Protocol.h:1005
Documents are synced by always sending the full content of the document.
Documents are synced by sending the full content on open.
llvm::Optional< std::vector< CodeAction > > codeActions
Clangd extension: code actions related to this diagnostic.
Definition: Protocol.h:673
clang::find_all_symbols::SymbolInfo::SymbolKind SymbolKind
Definition: SymbolInfo.cpp:21
llvm::Optional< std::map< std::string, std::vector< TextEdit > > > changes
Holds changes to existing resources.
Definition: Protocol.h:710
llvm::Optional< std::string > kind
The kind of the code action.
Definition: Protocol.h:772
bool operator()(const Diagnostic &LHS, const Diagnostic &RHS) const
Definition: Protocol.h:683
std::string title
A short, human-readable, title for this code action.
Definition: Protocol.h:768
Location location
The location of this related diagnostic information.
Definition: Protocol.h:635
llvm::Optional< Range > range
An optional range is a range inside a text document that is used to visualize a hover, e.g.
Definition: Protocol.h:918
TextDocumentIdentifier textDocument
The document that was closed.
Definition: Protocol.h:527
SymbolKind indexSymbolKindToSymbolKind(index::SymbolKind Kind)
Definition: Protocol.cpp:216
Represents a related message and source code location for a diagnostic.
Definition: Protocol.h:633
std::string tweakID
ID of the tweak that should be executed. Corresponds to Tweak::id().
Definition: Protocol.h:728
std::string label
The label of this signature. Mandatory.
Definition: Protocol.h:1030
std::string state
The human-readable string presents the current state of the file, can be shown in the UI (e...
Definition: Protocol.h:1189
An Event<T> allows events of type T to be broadcast to listeners.
Definition: Function.h:87
llvm::Optional< std::string > data
An optional &#39;data&#39; filed, which can be used to identify a type hierarchy item in a resolve request...
Definition: Protocol.h:1158
A code action represents a change that can be performed in code, e.g.
Definition: Protocol.h:766
constexpr llvm::StringLiteral Message
friend bool operator!=(const URIForFile &LHS, const URIForFile &RHS)
Definition: Protocol.h:101
URIForFile uri
The text document&#39;s URI.
Definition: Protocol.h:183
std::string text
The new text of the range/document.
Definition: Protocol.h:539
friend bool operator!=(const Position &LHS, const Position &RHS)
Definition: Protocol.h:139
llvm::Optional< WorkspaceEdit > edit
The workspace edit this code action performs.
Definition: Protocol.h:781
Range selectionRange
The range that should be selected and revealed when this symbol is being picked, e.g the name of a function.
Definition: Protocol.h:814
Values in a Context are indexed by typed keys.
Definition: Context.h:40
constexpr auto SymbolKindMin
Definition: Protocol.h:328
The show message notification is sent from a server to a client to ask the client to display a partic...
Definition: Protocol.h:511
llvm::Optional< std::string > compilationDatabasePath
Definition: Protocol.h:454
std::string sortText
A string that should be used when comparing this item with other items.
Definition: Protocol.h:958
constexpr auto CompletionItemKindMin
Definition: Protocol.h:288
std::string name
The human readable name of the hierarchy item.
Definition: Protocol.h:1120
std::string title
Definition: Protocol.h:757
friend bool operator!=(const Range &LHS, const Range &RHS)
Definition: Protocol.h:165
std::vector< ParameterInformation > parameters
The parameters of this signature.
Definition: Protocol.h:1036
std::bitset< CompletionItemKindMax+1 > CompletionItemKindBitset
Definition: Protocol.h:292
Documents should not be synced at all.
Range selectionRange
The range that should be selected and revealed when this type hierarchy item is being picked...
Definition: Protocol.h:1144
std::string documentation
A human-readable string that represents a doc-comment.
Definition: Protocol.h:954
InsertTextFormat
Defines whether the insert text in a completion item should be interpreted as plain text or a snippet...
Definition: Protocol.h:924
Range range
The range enclosing this symbol not including leading/trailing whitespace but everything else like co...
Definition: Protocol.h:810
URIForFile uri
The text document&#39;s URI.
Definition: Protocol.h:1186
std::vector< TextEdit > additionalTextEdits
An optional array of additional text edits that are applied when selecting this completion.
Definition: Protocol.h:982
constexpr auto CompletionItemKindMax
Definition: Protocol.h:290
Represents programming constructs like variables, classes, interfaces etc.
Definition: Protocol.h:793
static const llvm::StringLiteral CLANGD_APPLY_TWEAK
Definition: Protocol.h:745
std::string Tokens
The base64 encoded string of highlighting tokens.
Definition: Protocol.h:1200
llvm::Optional< int > processId
The process Id of the parent process that started the server.
Definition: Protocol.h:470
Range range
The range enclosing this type hierarchy item not including leading/trailing whitespace but everything...
Definition: Protocol.h:1139
CompletionItemKind
The kind of a completion entry.
Definition: Protocol.h:259
ConfigurationSettings ConfigSettings
Definition: Protocol.h:452
TextDocumentIdentifier TextDocument
The textdocument these highlightings belong to.
Definition: Protocol.h:1209
std::string uri() const
Definition: Protocol.h:95
BindArgumentKind Kind
TextDocumentSyncKind
Defines how the host (editor) should sync document changes to the language server.
Definition: Protocol.h:246
MarkupContent contents
The hover&#39;s content.
Definition: Protocol.h:914
std::error_code convertToErrorCode() const override
Definition: Protocol.h:66
A document highlight is a range inside a text document which deserves special attention.
Definition: Protocol.h:1081
URIForFile uri
The text document&#39;s URI.
Definition: Protocol.h:219
std::string detail
A human-readable string with additional information about this item, like type or symbol information...
Definition: Protocol.h:951
llvm::Optional< SymbolID > ID
Definition: Protocol.h:854
std::string source
A human-readable string describing the source of this diagnostic, e.g.
Definition: Protocol.h:655
llvm::Optional< TweakArgs > tweakArgs
Definition: Protocol.h:752
LSPError(std::string Message, ErrorCode Code)
Definition: Protocol.h:60
static URI createFile(llvm::StringRef AbsolutePath)
This creates a file:// URI for AbsolutePath. The path must be absolute.
Definition: URI.cpp:215
TextDocumentIdentifier textDocument
The document that was opened.
Definition: Protocol.h:1065
std::string newText
The string to be inserted.
Definition: Protocol.h:208
Parameters for the semantic highlighting (server-side) push notification.
Definition: Protocol.h:1207
std::string newName
The new name of the symbol.
Definition: Protocol.h:1071
Represents the signature of something callable.
Definition: Protocol.h:1027
Clangd extension: parameters configurable at any time, via the workspace/didChangeConfiguration notif...
Definition: Protocol.h:440
std::string command
The command identifier, e.g. CLANGD_APPLY_FIX_COMMAND.
Definition: Protocol.h:748
InitializationOptions initializationOptions
User-provided initialization options.
Definition: Protocol.h:493
TextDocumentIdentifier textDocument
Definition: Protocol.h:626
std::string filterText
A string that should be used when filtering a set of completion items.
Definition: Protocol.h:962
bool operator<(const Ref &L, const Ref &R)
Definition: Ref.h:58
friend bool operator<(const Position &LHS, const Position &RHS)
Definition: Protocol.h:142
TextDocumentIdentifier textDocument
The document in which the command was invoked.
Definition: Protocol.h:698
Range range
The range of the text document to be manipulated.
Definition: Protocol.h:204
bool operator==(const Ref &L, const Ref &R)
Definition: Ref.h:61
std::vector< std::string > fallbackFlags
Definition: Protocol.h:458
std::string Message
Definition: Protocol.h:56
friend bool operator<(const Range &LHS, const Range &RHS)
Definition: Protocol.h:168
llvm::Optional< Range > range
The range of the document that changed.
Definition: Protocol.h:533
llvm::Optional< std::string > category
The diagnostic&#39;s category.
Definition: Protocol.h:668
Position position
The position inside the text document.
Definition: Protocol.h:877
URIForFile file
A file provided by the client on a textDocument/codeAction request.
Definition: Protocol.h:724
int Line
The line these highlightings belong to.
Definition: Protocol.h:1198
std::vector< DocumentSymbol > children
Children of this symbol, e.g. properties of a class.
Definition: Protocol.h:817
Position argListStart
Position of the start of the argument list, including opening paren.
Definition: Protocol.h:1059
std::string message
The message of this related diagnostic information.
Definition: Protocol.h:637
std::string documentation
The documentation of this parameter. Optional.
Definition: Protocol.h:1022
SymbolKind kind
The kind of this symbol.
Definition: Protocol.h:829
static const llvm::StringLiteral REFACTOR_KIND
Definition: Protocol.h:774
std::vector< SignatureInformation > signatures
The resulting signatures.
Definition: Protocol.h:1046
llvm::Optional< int > rangeLength
The length of the range that got replaced.
Definition: Protocol.h:536
static llvm::SmallString< 128 > canonicalize(llvm::StringRef Path)
std::string name
The name of this symbol.
Definition: Protocol.h:795
Completion was triggered by typing an identifier (24x7 code complete), manual invocation (e...
ClientCapabilities capabilities
The capabilities provided by the client (editor or tool)
Definition: Protocol.h:487
TextDocumentItem textDocument
The document that was opened.
Definition: Protocol.h:521
llvm::Optional< std::string > detail
Optional detail for the hierarchy item.
Definition: Protocol.h:1124
TextDocumentIdentifier textDocument
The document that did change.
Definition: Protocol.h:547
std::map< std::string, ClangdCompileCommand > compilationDatabaseChanges
Definition: Protocol.h:443
std::string detail
More detail for this symbol, e.g the signature of a function.
Definition: Protocol.h:798
Completion was triggered by a trigger character specified by the triggerCharacters properties of the ...
std::vector< FileEvent > changes
The actual file events.
Definition: Protocol.h:580
std::vector< SemanticHighlightingInformation > Lines
The lines of highlightings that should be sent.
Definition: Protocol.h:1211
An information message.
llvm::Optional< CompletionItemKindBitset > CompletionItemKinds
The supported set of CompletionItemKinds for textDocument/completion.
Definition: Protocol.h:409
std::string languageId
The text document&#39;s language identifier.
Definition: Protocol.h:222
llvm::Optional< std::string > rootPath
The rootPath of the workspace.
Definition: Protocol.h:476
Position position
The position at which this request was sent.
Definition: Protocol.h:611
bool fromJSON(const llvm::json::Value &Parameters, FuzzyFindRequest &Request)
Definition: Index.cpp:34
A single parameter of a particular signature.
Definition: Protocol.h:1010
A LSP-specific comparator used to find diagnostic in a container like std:map.
Definition: Protocol.h:682
int line
Line position in a document (zero-based).
Definition: Protocol.h:128
std::vector< TextDocumentContentChangeEvent > contentChanges
The actual content changes.
Definition: Protocol.h:550
friend bool operator<(const DocumentHighlight &LHS, const DocumentHighlight &RHS)
Definition: Protocol.h:1088
int character
Character offset on a line in a document (zero-based).
Definition: Protocol.h:133
TypeHierarchyDirection direction
The direction of the hierarchy levels to resolve.
Definition: Protocol.h:1173
CompletionContext context
Definition: Protocol.h:902
bool contains(Position Pos) const
Definition: Protocol.h:172
Represents the signature of a callable.
Definition: Protocol.h:1043
std::string query
A non-empty query string.
Definition: Protocol.h:863
SymbolKind kind
The kind of this symbol.
Definition: Protocol.h:801
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::bitset< SymbolKindMax+1 > SymbolKindBitset
Definition: Protocol.h:330
SymbolKind
A symbol kind.
Definition: Protocol.h:299
std::string message
The diagnostic&#39;s message.
Definition: Protocol.h:658
std::string triggerCharacter
The trigger character (a single character) that has trigger code complete.
Definition: Protocol.h:897
TextDocumentIdentifier textDocument
The text document.
Definition: Protocol.h:874
static const llvm::StringLiteral INFO_KIND
Definition: Protocol.h:775
std::string label
The label of this completion item.
Definition: Protocol.h:943
friend bool operator==(const DocumentHighlight &LHS, const DocumentHighlight &RHS)
Definition: Protocol.h:1095
The type hierarchy params is an extension of the TextDocumentPositionsParams with optional properties...
Definition: Protocol.h:1109
llvm::Optional< std::pair< unsigned, unsigned > > labelOffsets
Inclusive start and exclusive end offsets withing the containing signature label. ...
Definition: Protocol.h:1019
DocumentHighlightKind kind
The highlight kind, default is DocumentHighlightKind.Text.
Definition: Protocol.h:1086
SymbolKind adjustKindToCapability(SymbolKind Kind, SymbolKindBitset &SupportedSymbolKinds)
Definition: Protocol.cpp:198
static const llvm::StringLiteral QUICKFIX_KIND
Definition: Protocol.h:773
bool contains(Range Rng) const
Definition: Protocol.h:173
A URI describes the location of a source file.
Definition: URI.h:28
Range selection
A selection provided by the client on a textDocument/codeAction request.
Definition: Protocol.h:726
std::vector< Diagnostic > diagnostics
An array of diagnostics.
Definition: Protocol.h:692
bool deprecated
Indicates if this symbol is deprecated.
Definition: Protocol.h:804
llvm::Optional< Command > command
A command this code action executes.
Definition: Protocol.h:785
The parameters of a Workspace Symbol Request.
Definition: Protocol.h:861
llvm::Optional< std::vector< TypeHierarchyItem > > parents
If this type hierarchy item is resolved, it contains the direct parents.
Definition: Protocol.h:1149
Parameters for the typeHierarchy/resolve request.
Definition: Protocol.h:1165
std::string text
The content of the opened text document.
Definition: Protocol.h:228
Clangd extension: indicates the current state of the file in clangd, sent from server via the textDoc...
Definition: Protocol.h:1184
std::string containerName
The name of the symbol containing this symbol.
Definition: Protocol.h:835
llvm::Optional< std::vector< Diagnostic > > diagnostics
The diagnostics that this code action resolves.
Definition: Protocol.h:778
SymbolKind kind
The kind of the hierarchy item. For instance, class or interface.
Definition: Protocol.h:1127
Position position
The position at which this request was sent.
Definition: Protocol.h:1068
URIForFile uri
The text document&#39;s URI.
Definition: Protocol.h:121
std::string message
The actual message.
Definition: Protocol.h:515
friend bool operator!=(const Location &LHS, const Location &RHS)
Definition: Protocol.h:190
TypeHierarchyItem item
The item to resolve.
Definition: Protocol.h:1167
Range range
The range at which the message applies.
Definition: Protocol.h:644
Represents a semantic highlighting information that has to be applied on a specific line of the text ...
Definition: Protocol.h:1196
friend bool operator<(const URIForFile &LHS, const URIForFile &RHS)
Definition: Protocol.h:105
TextDocumentIdentifier textDocument
The document to format.
Definition: Protocol.h:599
Position end
The range&#39;s end position.
Definition: Protocol.h:160
llvm::Optional< WorkspaceEdit > workspaceEdit
Definition: Protocol.h:751
int resolve
The hierarchy levels to resolve. 0 indicates no level.
Definition: Protocol.h:1170
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const CodeCompletion &C)
URIForFile uri
The URI of the text document where this type hierarchy item belongs to.
Definition: Protocol.h:1133
std::string name
The name of this symbol.
Definition: Protocol.h:826
Completion was re-triggered as the current completion list is incomplete.
std::string toString() const
Returns a string URI with all components percent-encoded.
Definition: URI.cpp:147
Clangd extension that&#39;s used in the &#39;compilationDatabaseChanges&#39; in workspace/didChangeConfiguration ...
Definition: Protocol.h:431
friend bool operator==(const Position &LHS, const Position &RHS)
Definition: Protocol.h:135
Arguments for the &#39;applyTweak&#39; command.
Definition: Protocol.h:722
void log(llvm::raw_ostream &OS) const override
Definition: Protocol.h:63
llvm::Optional< std::vector< DiagnosticRelatedInformation > > relatedInformation
An array of related diagnostic information, e.g.
Definition: Protocol.h:662
friend bool operator==(const Range &LHS, const Range &RHS)
Definition: Protocol.h:162
Represents information about identifier.
Definition: Protocol.h:842
constexpr auto SymbolKindMax
Definition: Protocol.h:329
llvm::Optional< std::vector< OffsetEncoding > > offsetEncoding
Supported encodings for LSP character offsets. (clangd extension).
Definition: Protocol.h:420
static void format(const clang::clangd::Position &Pos, raw_ostream &OS, StringRef Style)
Definition: Protocol.h:1220
llvm::Optional< TraceLevel > trace
The initial trace setting. If omitted trace is disabled (&#39;off&#39;).
Definition: Protocol.h:490
std::string documentation
The documentation of this signature. Optional.
Definition: Protocol.h:1033
llvm::StringRef file() const
Retrieves absolute path to the file.
Definition: Protocol.h:92
Represents information about programming constructs like variables, classes, interfaces etc...
Definition: Protocol.h:824