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