511eae1940c6e1595b4884715fc731e2f8ada8ee
[platform/upstream/llvm.git] / clang-tools-extra / clangd / Protocol.h
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/main/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 "support/MemoryTree.h"
29 #include "clang/Index/IndexSymbol.h"
30 #include "llvm/ADT/SmallVector.h"
31 #include "llvm/Support/JSON.h"
32 #include "llvm/Support/raw_ostream.h"
33 #include <bitset>
34 #include <memory>
35 #include <optional>
36 #include <string>
37 #include <vector>
38
39 // This file is using the LSP syntax for identifier names which is different
40 // from the LLVM coding standard. To avoid the clang-tidy warnings, we're
41 // disabling one check here.
42 // NOLINTBEGIN(readability-identifier-naming)
43
44 namespace clang {
45 namespace clangd {
46
47 enum class ErrorCode {
48   // Defined by JSON RPC.
49   ParseError = -32700,
50   InvalidRequest = -32600,
51   MethodNotFound = -32601,
52   InvalidParams = -32602,
53   InternalError = -32603,
54
55   ServerNotInitialized = -32002,
56   UnknownErrorCode = -32001,
57
58   // Defined by the protocol.
59   RequestCancelled = -32800,
60   ContentModified = -32801,
61 };
62 // Models an LSP error as an llvm::Error.
63 class LSPError : public llvm::ErrorInfo<LSPError> {
64 public:
65   std::string Message;
66   ErrorCode Code;
67   static char ID;
68
69   LSPError(std::string Message, ErrorCode Code)
70       : Message(std::move(Message)), Code(Code) {}
71
72   void log(llvm::raw_ostream &OS) const override {
73     OS << int(Code) << ": " << Message;
74   }
75   std::error_code convertToErrorCode() const override {
76     return llvm::inconvertibleErrorCode();
77   }
78 };
79
80 bool fromJSON(const llvm::json::Value &, SymbolID &, llvm::json::Path);
81 llvm::json::Value toJSON(const SymbolID &);
82
83 // URI in "file" scheme for a file.
84 struct URIForFile {
85   URIForFile() = default;
86
87   /// Canonicalizes \p AbsPath via URI.
88   ///
89   /// File paths in URIForFile can come from index or local AST. Path from
90   /// index goes through URI transformation, and the final path is resolved by
91   /// URI scheme and could potentially be different from the original path.
92   /// Hence, we do the same transformation for all paths.
93   ///
94   /// Files can be referred to by several paths (e.g. in the presence of links).
95   /// Which one we prefer may depend on where we're coming from. \p TUPath is a
96   /// hint, and should usually be the main entrypoint file we're processing.
97   static URIForFile canonicalize(llvm::StringRef AbsPath,
98                                  llvm::StringRef TUPath);
99
100   static llvm::Expected<URIForFile> fromURI(const URI &U,
101                                             llvm::StringRef HintPath);
102
103   /// Retrieves absolute path to the file.
104   llvm::StringRef file() const { return File; }
105
106   explicit operator bool() const { return !File.empty(); }
107   std::string uri() const { return URI::createFile(File).toString(); }
108
109   friend bool operator==(const URIForFile &LHS, const URIForFile &RHS) {
110     return LHS.File == RHS.File;
111   }
112
113   friend bool operator!=(const URIForFile &LHS, const URIForFile &RHS) {
114     return !(LHS == RHS);
115   }
116
117   friend bool operator<(const URIForFile &LHS, const URIForFile &RHS) {
118     return LHS.File < RHS.File;
119   }
120
121 private:
122   explicit URIForFile(std::string &&File) : File(std::move(File)) {}
123
124   std::string File;
125 };
126
127 /// Serialize/deserialize \p URIForFile to/from a string URI.
128 llvm::json::Value toJSON(const URIForFile &U);
129 bool fromJSON(const llvm::json::Value &, URIForFile &, llvm::json::Path);
130
131 struct TextDocumentIdentifier {
132   /// The text document's URI.
133   URIForFile uri;
134 };
135 llvm::json::Value toJSON(const TextDocumentIdentifier &);
136 bool fromJSON(const llvm::json::Value &, TextDocumentIdentifier &,
137               llvm::json::Path);
138
139 struct VersionedTextDocumentIdentifier : public TextDocumentIdentifier {
140   /// The version number of this document. If a versioned text document
141   /// identifier is sent from the server to the client and the file is not open
142   /// in the editor (the server has not received an open notification before)
143   /// the server can send `null` to indicate that the version is known and the
144   /// content on disk is the master (as speced with document content ownership).
145   ///
146   /// The version number of a document will increase after each change,
147   /// including undo/redo. The number doesn't need to be consecutive.
148   ///
149   /// clangd extension: versions are optional, and synthesized if missing.
150   std::optional<std::int64_t> version;
151 };
152 llvm::json::Value toJSON(const VersionedTextDocumentIdentifier &);
153 bool fromJSON(const llvm::json::Value &, VersionedTextDocumentIdentifier &,
154               llvm::json::Path);
155
156 struct Position {
157   /// Line position in a document (zero-based).
158   int line = 0;
159
160   /// Character offset on a line in a document (zero-based).
161   /// WARNING: this is in UTF-16 codepoints, not bytes or characters!
162   /// Use the functions in SourceCode.h to construct/interpret Positions.
163   int character = 0;
164
165   friend bool operator==(const Position &LHS, const Position &RHS) {
166     return std::tie(LHS.line, LHS.character) ==
167            std::tie(RHS.line, RHS.character);
168   }
169   friend bool operator!=(const Position &LHS, const Position &RHS) {
170     return !(LHS == RHS);
171   }
172   friend bool operator<(const Position &LHS, const Position &RHS) {
173     return std::tie(LHS.line, LHS.character) <
174            std::tie(RHS.line, RHS.character);
175   }
176   friend bool operator<=(const Position &LHS, const Position &RHS) {
177     return std::tie(LHS.line, LHS.character) <=
178            std::tie(RHS.line, RHS.character);
179   }
180 };
181 bool fromJSON(const llvm::json::Value &, Position &, llvm::json::Path);
182 llvm::json::Value toJSON(const Position &);
183 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Position &);
184
185 struct Range {
186   /// The range's start position.
187   Position start;
188
189   /// The range's end position.
190   Position end;
191
192   friend bool operator==(const Range &LHS, const Range &RHS) {
193     return std::tie(LHS.start, LHS.end) == std::tie(RHS.start, RHS.end);
194   }
195   friend bool operator!=(const Range &LHS, const Range &RHS) {
196     return !(LHS == RHS);
197   }
198   friend bool operator<(const Range &LHS, const Range &RHS) {
199     return std::tie(LHS.start, LHS.end) < std::tie(RHS.start, RHS.end);
200   }
201
202   bool contains(Position Pos) const { return start <= Pos && Pos < end; }
203   bool contains(Range Rng) const {
204     return start <= Rng.start && Rng.end <= end;
205   }
206 };
207 bool fromJSON(const llvm::json::Value &, Range &, llvm::json::Path);
208 llvm::json::Value toJSON(const Range &);
209 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Range &);
210
211 struct Location {
212   /// The text document's URI.
213   URIForFile uri;
214   Range range;
215
216   friend bool operator==(const Location &LHS, const Location &RHS) {
217     return LHS.uri == RHS.uri && LHS.range == RHS.range;
218   }
219
220   friend bool operator!=(const Location &LHS, const Location &RHS) {
221     return !(LHS == RHS);
222   }
223
224   friend bool operator<(const Location &LHS, const Location &RHS) {
225     return std::tie(LHS.uri, LHS.range) < std::tie(RHS.uri, RHS.range);
226   }
227 };
228 llvm::json::Value toJSON(const Location &);
229 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Location &);
230
231 /// Extends Locations returned by textDocument/references with extra info.
232 /// This is a clangd extension: LSP uses `Location`.
233 struct ReferenceLocation : Location {
234   /// clangd extension: contains the name of the function or class in which the
235   /// reference occurs
236   std::optional<std::string> containerName;
237 };
238 llvm::json::Value toJSON(const ReferenceLocation &);
239 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const ReferenceLocation &);
240
241 using ChangeAnnotationIdentifier = std::string;
242 // A combination of a LSP standard TextEdit and AnnotatedTextEdit.
243 struct TextEdit {
244   /// The range of the text document to be manipulated. To insert
245   /// text into a document create a range where start === end.
246   Range range;
247
248   /// The string to be inserted. For delete operations use an
249   /// empty string.
250   std::string newText;
251
252   /// The actual annotation identifier (optional)
253   /// If empty, then this field is nullopt.
254   ChangeAnnotationIdentifier annotationId = "";
255 };
256 inline bool operator==(const TextEdit &L, const TextEdit &R) {
257   return std::tie(L.newText, L.range, L.annotationId) ==
258          std::tie(R.newText, R.range, L.annotationId);
259 }
260 bool fromJSON(const llvm::json::Value &, TextEdit &, llvm::json::Path);
261 llvm::json::Value toJSON(const TextEdit &);
262 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const TextEdit &);
263
264 struct ChangeAnnotation {
265   /// A human-readable string describing the actual change. The string
266   /// is rendered prominent in the user interface.
267   std::string label;
268
269   /// A flag which indicates that user confirmation is needed
270   /// before applying the change.
271   std::optional<bool> needsConfirmation;
272
273   /// A human-readable string which is rendered less prominent in
274   /// the user interface.
275   std::string description;
276 };
277 bool fromJSON(const llvm::json::Value &, ChangeAnnotation &, llvm::json::Path);
278 llvm::json::Value toJSON(const ChangeAnnotation &);
279
280 struct TextDocumentEdit {
281   /// The text document to change.
282   VersionedTextDocumentIdentifier textDocument;
283
284         /// The edits to be applied.
285   /// FIXME: support the AnnotatedTextEdit variant.
286   std::vector<TextEdit> edits;
287 };
288 bool fromJSON(const llvm::json::Value &, TextDocumentEdit &, llvm::json::Path);
289 llvm::json::Value toJSON(const TextDocumentEdit &);
290
291 struct TextDocumentItem {
292   /// The text document's URI.
293   URIForFile uri;
294
295   /// The text document's language identifier.
296   std::string languageId;
297
298   /// The version number of this document (it will strictly increase after each
299   /// change, including undo/redo.
300   ///
301   /// clangd extension: versions are optional, and synthesized if missing.
302   std::optional<int64_t> version;
303
304   /// The content of the opened text document.
305   std::string text;
306 };
307 bool fromJSON(const llvm::json::Value &, TextDocumentItem &, llvm::json::Path);
308
309 enum class TraceLevel {
310   Off = 0,
311   Messages = 1,
312   Verbose = 2,
313 };
314 bool fromJSON(const llvm::json::Value &E, TraceLevel &Out, llvm::json::Path);
315
316 struct NoParams {};
317 inline llvm::json::Value toJSON(const NoParams &) { return nullptr; }
318 inline bool fromJSON(const llvm::json::Value &, NoParams &, llvm::json::Path) {
319   return true;
320 }
321 using InitializedParams = NoParams;
322
323 /// Defines how the host (editor) should sync document changes to the language
324 /// server.
325 enum class TextDocumentSyncKind {
326   /// Documents should not be synced at all.
327   None = 0,
328
329   /// Documents are synced by always sending the full content of the document.
330   Full = 1,
331
332   /// Documents are synced by sending the full content on open.  After that
333   /// only incremental updates to the document are send.
334   Incremental = 2,
335 };
336
337 /// The kind of a completion entry.
338 enum class CompletionItemKind {
339   Missing = 0,
340   Text = 1,
341   Method = 2,
342   Function = 3,
343   Constructor = 4,
344   Field = 5,
345   Variable = 6,
346   Class = 7,
347   Interface = 8,
348   Module = 9,
349   Property = 10,
350   Unit = 11,
351   Value = 12,
352   Enum = 13,
353   Keyword = 14,
354   Snippet = 15,
355   Color = 16,
356   File = 17,
357   Reference = 18,
358   Folder = 19,
359   EnumMember = 20,
360   Constant = 21,
361   Struct = 22,
362   Event = 23,
363   Operator = 24,
364   TypeParameter = 25,
365 };
366 bool fromJSON(const llvm::json::Value &, CompletionItemKind &,
367               llvm::json::Path);
368 constexpr auto CompletionItemKindMin =
369     static_cast<size_t>(CompletionItemKind::Text);
370 constexpr auto CompletionItemKindMax =
371     static_cast<size_t>(CompletionItemKind::TypeParameter);
372 using CompletionItemKindBitset = std::bitset<CompletionItemKindMax + 1>;
373 bool fromJSON(const llvm::json::Value &, CompletionItemKindBitset &,
374               llvm::json::Path);
375 CompletionItemKind
376 adjustKindToCapability(CompletionItemKind Kind,
377                        CompletionItemKindBitset &SupportedCompletionItemKinds);
378
379 /// A symbol kind.
380 enum class SymbolKind {
381   File = 1,
382   Module = 2,
383   Namespace = 3,
384   Package = 4,
385   Class = 5,
386   Method = 6,
387   Property = 7,
388   Field = 8,
389   Constructor = 9,
390   Enum = 10,
391   Interface = 11,
392   Function = 12,
393   Variable = 13,
394   Constant = 14,
395   String = 15,
396   Number = 16,
397   Boolean = 17,
398   Array = 18,
399   Object = 19,
400   Key = 20,
401   Null = 21,
402   EnumMember = 22,
403   Struct = 23,
404   Event = 24,
405   Operator = 25,
406   TypeParameter = 26
407 };
408 bool fromJSON(const llvm::json::Value &, SymbolKind &, llvm::json::Path);
409 constexpr auto SymbolKindMin = static_cast<size_t>(SymbolKind::File);
410 constexpr auto SymbolKindMax = static_cast<size_t>(SymbolKind::TypeParameter);
411 using SymbolKindBitset = std::bitset<SymbolKindMax + 1>;
412 bool fromJSON(const llvm::json::Value &, SymbolKindBitset &, llvm::json::Path);
413 SymbolKind adjustKindToCapability(SymbolKind Kind,
414                                   SymbolKindBitset &supportedSymbolKinds);
415
416 // Convert a index::SymbolKind to clangd::SymbolKind (LSP)
417 // Note, some are not perfect matches and should be improved when this LSP
418 // issue is addressed:
419 // https://github.com/Microsoft/language-server-protocol/issues/344
420 SymbolKind indexSymbolKindToSymbolKind(index::SymbolKind Kind);
421
422 // Determines the encoding used to measure offsets and lengths of source in LSP.
423 enum class OffsetEncoding {
424   // Any string is legal on the wire. Unrecognized encodings parse as this.
425   UnsupportedEncoding,
426   // Length counts code units of UTF-16 encoded text. (Standard LSP behavior).
427   UTF16,
428   // Length counts bytes of UTF-8 encoded text. (Clangd extension).
429   UTF8,
430   // Length counts codepoints in unicode text. (Clangd extension).
431   UTF32,
432 };
433 llvm::json::Value toJSON(const OffsetEncoding &);
434 bool fromJSON(const llvm::json::Value &, OffsetEncoding &, llvm::json::Path);
435 llvm::raw_ostream &operator<<(llvm::raw_ostream &, OffsetEncoding);
436
437 // Describes the content type that a client supports in various result literals
438 // like `Hover`, `ParameterInfo` or `CompletionItem`.
439 enum class MarkupKind {
440   PlainText,
441   Markdown,
442 };
443 bool fromJSON(const llvm::json::Value &, MarkupKind &, llvm::json::Path);
444 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, MarkupKind);
445
446 // This struct doesn't mirror LSP!
447 // The protocol defines deeply nested structures for client capabilities.
448 // Instead of mapping them all, this just parses out the bits we care about.
449 struct ClientCapabilities {
450   /// The supported set of SymbolKinds for workspace/symbol.
451   /// workspace.symbol.symbolKind.valueSet
452   std::optional<SymbolKindBitset> WorkspaceSymbolKinds;
453
454   /// Whether the client accepts diagnostics with codeActions attached inline.
455   /// textDocument.publishDiagnostics.codeActionsInline.
456   bool DiagnosticFixes = false;
457
458   /// Whether the client accepts diagnostics with related locations.
459   /// textDocument.publishDiagnostics.relatedInformation.
460   bool DiagnosticRelatedInformation = false;
461
462   /// Whether the client accepts diagnostics with category attached to it
463   /// using the "category" extension.
464   /// textDocument.publishDiagnostics.categorySupport
465   bool DiagnosticCategory = false;
466
467   /// Client supports snippets as insert text.
468   /// textDocument.completion.completionItem.snippetSupport
469   bool CompletionSnippets = false;
470
471   /// Client supports completions with additionalTextEdit near the cursor.
472   /// This is a clangd extension. (LSP says this is for unrelated text only).
473   /// textDocument.completion.editsNearCursor
474   bool CompletionFixes = false;
475
476   /// Client supports displaying a container string for results of
477   /// textDocument/reference (clangd extension)
478   bool ReferenceContainer = false;
479
480   /// Client supports hierarchical document symbols.
481   /// textDocument.documentSymbol.hierarchicalDocumentSymbolSupport
482   bool HierarchicalDocumentSymbol = false;
483
484   /// Client supports signature help.
485   /// textDocument.signatureHelp
486   bool HasSignatureHelp = false;
487
488   /// Client signals that it only supports folding complete lines.
489   /// Client will ignore specified `startCharacter` and `endCharacter`
490   /// properties in a FoldingRange.
491   /// textDocument.foldingRange.lineFoldingOnly
492   bool LineFoldingOnly = false;
493
494   /// Client supports processing label offsets instead of a simple label string.
495   /// textDocument.signatureHelp.signatureInformation.parameterInformation.labelOffsetSupport
496   bool OffsetsInSignatureHelp = false;
497
498   /// The documentation format that should be used for
499   /// textDocument/signatureHelp.
500   /// textDocument.signatureHelp.signatureInformation.documentationFormat
501   MarkupKind SignatureHelpDocumentationFormat = MarkupKind::PlainText;
502
503   /// The supported set of CompletionItemKinds for textDocument/completion.
504   /// textDocument.completion.completionItemKind.valueSet
505   std::optional<CompletionItemKindBitset> CompletionItemKinds;
506
507   /// The documentation format that should be used for textDocument/completion.
508   /// textDocument.completion.completionItem.documentationFormat
509   MarkupKind CompletionDocumentationFormat = MarkupKind::PlainText;
510
511   /// Client supports CodeAction return value for textDocument/codeAction.
512   /// textDocument.codeAction.codeActionLiteralSupport.
513   bool CodeActionStructure = false;
514
515   /// Client advertises support for the semanticTokens feature.
516   /// We support the textDocument/semanticTokens request in any case.
517   /// textDocument.semanticTokens
518   bool SemanticTokens = false;
519   /// Client supports Theia semantic highlighting extension.
520   /// https://github.com/microsoft/vscode-languageserver-node/pull/367
521   /// clangd no longer supports this, we detect it just to log a warning.
522   /// textDocument.semanticHighlightingCapabilities.semanticHighlighting
523   bool TheiaSemanticHighlighting = false;
524
525   /// Supported encodings for LSP character offsets. (clangd extension).
526   std::optional<std::vector<OffsetEncoding>> offsetEncoding;
527
528   /// The content format that should be used for Hover requests.
529   /// textDocument.hover.contentEncoding
530   MarkupKind HoverContentFormat = MarkupKind::PlainText;
531
532   /// The client supports testing for validity of rename operations
533   /// before execution.
534   bool RenamePrepareSupport = false;
535
536   /// The client supports progress notifications.
537   /// window.workDoneProgress
538   bool WorkDoneProgress = false;
539
540   /// The client supports implicit $/progress work-done progress streams,
541   /// without a preceding window/workDoneProgress/create.
542   /// This is a clangd extension.
543   /// window.implicitWorkDoneProgressCreate
544   bool ImplicitProgressCreation = false;
545
546   /// Whether the client claims to cancel stale requests.
547   /// general.staleRequestSupport.cancel
548   bool CancelsStaleRequests = false;
549
550   /// Whether the client implementation supports a refresh request sent from the
551   /// server to the client.
552   bool SemanticTokenRefreshSupport = false;
553
554   /// The client supports versioned document changes for WorkspaceEdit.
555   bool DocumentChanges = false;
556   
557   /// The client supports change annotations on text edits,
558   bool ChangeAnnotation = false;
559
560   /// Whether the client supports the textDocument/inactiveRegions
561   /// notification. This is a clangd extension.
562   bool InactiveRegions = false;
563 };
564 bool fromJSON(const llvm::json::Value &, ClientCapabilities &,
565               llvm::json::Path);
566
567 /// Clangd extension that's used in the 'compilationDatabaseChanges' in
568 /// workspace/didChangeConfiguration to record updates to the in-memory
569 /// compilation database.
570 struct ClangdCompileCommand {
571   std::string workingDirectory;
572   std::vector<std::string> compilationCommand;
573 };
574 bool fromJSON(const llvm::json::Value &, ClangdCompileCommand &,
575               llvm::json::Path);
576
577 /// Clangd extension: parameters configurable at any time, via the
578 /// `workspace/didChangeConfiguration` notification.
579 /// LSP defines this type as `any`.
580 struct ConfigurationSettings {
581   // Changes to the in-memory compilation database.
582   // The key of the map is a file name.
583   std::map<std::string, ClangdCompileCommand> compilationDatabaseChanges;
584 };
585 bool fromJSON(const llvm::json::Value &, ConfigurationSettings &,
586               llvm::json::Path);
587
588 /// Clangd extension: parameters configurable at `initialize` time.
589 /// LSP defines this type as `any`.
590 struct InitializationOptions {
591   // What we can change throught the didChangeConfiguration request, we can
592   // also set through the initialize request (initializationOptions field).
593   ConfigurationSettings ConfigSettings;
594
595   std::optional<std::string> compilationDatabasePath;
596   // Additional flags to be included in the "fallback command" used when
597   // the compilation database doesn't describe an opened file.
598   // The command used will be approximately `clang $FILE $fallbackFlags`.
599   std::vector<std::string> fallbackFlags;
600
601   /// Clients supports show file status for textDocument/clangd.fileStatus.
602   bool FileStatus = false;
603 };
604 bool fromJSON(const llvm::json::Value &, InitializationOptions &,
605               llvm::json::Path);
606
607 struct InitializeParams {
608   /// The process Id of the parent process that started
609   /// the server. Is null if the process has not been started by another
610   /// process. If the parent process is not alive then the server should exit
611   /// (see exit notification) its process.
612   std::optional<int> processId;
613
614   /// The rootPath of the workspace. Is null
615   /// if no folder is open.
616   ///
617   /// @deprecated in favour of rootUri.
618   std::optional<std::string> rootPath;
619
620   /// The rootUri of the workspace. Is null if no
621   /// folder is open. If both `rootPath` and `rootUri` are set
622   /// `rootUri` wins.
623   std::optional<URIForFile> rootUri;
624
625   // User provided initialization options.
626   // initializationOptions?: any;
627
628   /// The capabilities provided by the client (editor or tool)
629   ClientCapabilities capabilities;
630   /// The same data as capabilities, but not parsed (to expose to modules).
631   llvm::json::Object rawCapabilities;
632
633   /// The initial trace setting. If omitted trace is disabled ('off').
634   std::optional<TraceLevel> trace;
635
636   /// User-provided initialization options.
637   InitializationOptions initializationOptions;
638 };
639 bool fromJSON(const llvm::json::Value &, InitializeParams &, llvm::json::Path);
640
641 struct WorkDoneProgressCreateParams {
642   /// The token to be used to report progress.
643   llvm::json::Value token = nullptr;
644 };
645 llvm::json::Value toJSON(const WorkDoneProgressCreateParams &P);
646
647 template <typename T> struct ProgressParams {
648   /// The progress token provided by the client or server.
649   llvm::json::Value token = nullptr;
650
651   /// The progress data.
652   T value;
653 };
654 template <typename T> llvm::json::Value toJSON(const ProgressParams<T> &P) {
655   return llvm::json::Object{{"token", P.token}, {"value", P.value}};
656 }
657 /// To start progress reporting a $/progress notification with the following
658 /// payload must be sent.
659 struct WorkDoneProgressBegin {
660   /// Mandatory title of the progress operation. Used to briefly inform about
661   /// the kind of operation being performed.
662   ///
663   /// Examples: "Indexing" or "Linking dependencies".
664   std::string title;
665
666   /// Controls if a cancel button should show to allow the user to cancel the
667   /// long-running operation. Clients that don't support cancellation are
668   /// allowed to ignore the setting.
669   bool cancellable = false;
670
671   /// Optional progress percentage to display (value 100 is considered 100%).
672   /// If not provided infinite progress is assumed and clients are allowed
673   /// to ignore the `percentage` value in subsequent in report notifications.
674   ///
675   /// The value should be steadily rising. Clients are free to ignore values
676   /// that are not following this rule.
677   ///
678   /// Clangd implementation note: we only send nonzero percentages in
679   /// the WorkProgressReport. 'true' here means percentages will be used.
680   bool percentage = false;
681 };
682 llvm::json::Value toJSON(const WorkDoneProgressBegin &);
683
684 /// Reporting progress is done using the following payload.
685 struct WorkDoneProgressReport {
686   /// Mandatory title of the progress operation. Used to briefly inform about
687   /// the kind of operation being performed.
688   ///
689   /// Examples: "Indexing" or "Linking dependencies".
690   std::string title;
691
692   /// Controls enablement state of a cancel button. This property is only valid
693   /// if a cancel button got requested in the `WorkDoneProgressStart` payload.
694   ///
695   /// Clients that don't support cancellation or don't support control
696   /// the button's enablement state are allowed to ignore the setting.
697   std::optional<bool> cancellable;
698
699   /// Optional, more detailed associated progress message. Contains
700   /// complementary information to the `title`.
701   ///
702   /// Examples: "3/25 files", "project/src/module2", "node_modules/some_dep".
703   /// If unset, the previous progress message (if any) is still valid.
704   std::optional<std::string> message;
705
706   /// Optional progress percentage to display (value 100 is considered 100%).
707   /// If not provided infinite progress is assumed and clients are allowed
708   /// to ignore the `percentage` value in subsequent in report notifications.
709   ///
710   /// The value should be steadily rising. Clients are free to ignore values
711   /// that are not following this rule.
712   std::optional<unsigned> percentage;
713 };
714 llvm::json::Value toJSON(const WorkDoneProgressReport &);
715 //
716 /// Signals the end of progress reporting.
717 struct WorkDoneProgressEnd {
718   /// Optional, a final message indicating to for example indicate the outcome
719   /// of the operation.
720   std::optional<std::string> message;
721 };
722 llvm::json::Value toJSON(const WorkDoneProgressEnd &);
723
724 enum class MessageType {
725   /// An error message.
726   Error = 1,
727   /// A warning message.
728   Warning = 2,
729   /// An information message.
730   Info = 3,
731   /// A log message.
732   Log = 4,
733 };
734 llvm::json::Value toJSON(const MessageType &);
735
736 /// The show message notification is sent from a server to a client to ask the
737 /// client to display a particular message in the user interface.
738 struct ShowMessageParams {
739   /// The message type.
740   MessageType type = MessageType::Info;
741   /// The actual message.
742   std::string message;
743 };
744 llvm::json::Value toJSON(const ShowMessageParams &);
745
746 struct DidOpenTextDocumentParams {
747   /// The document that was opened.
748   TextDocumentItem textDocument;
749 };
750 bool fromJSON(const llvm::json::Value &, DidOpenTextDocumentParams &,
751               llvm::json::Path);
752
753 struct DidCloseTextDocumentParams {
754   /// The document that was closed.
755   TextDocumentIdentifier textDocument;
756 };
757 bool fromJSON(const llvm::json::Value &, DidCloseTextDocumentParams &,
758               llvm::json::Path);
759
760 struct DidSaveTextDocumentParams {
761   /// The document that was saved.
762   TextDocumentIdentifier textDocument;
763 };
764 bool fromJSON(const llvm::json::Value &, DidSaveTextDocumentParams &,
765               llvm::json::Path);
766
767 struct TextDocumentContentChangeEvent {
768   /// The range of the document that changed.
769   std::optional<Range> range;
770
771   /// The length of the range that got replaced.
772   std::optional<int> rangeLength;
773
774   /// The new text of the range/document.
775   std::string text;
776 };
777 bool fromJSON(const llvm::json::Value &, TextDocumentContentChangeEvent &,
778               llvm::json::Path);
779
780 struct DidChangeTextDocumentParams {
781   /// The document that did change. The version number points
782   /// to the version after all provided content changes have
783   /// been applied.
784   VersionedTextDocumentIdentifier textDocument;
785
786   /// The actual content changes.
787   std::vector<TextDocumentContentChangeEvent> contentChanges;
788
789   /// Forces diagnostics to be generated, or to not be generated, for this
790   /// version of the file. If not set, diagnostics are eventually consistent:
791   /// either they will be provided for this version or some subsequent one.
792   /// This is a clangd extension.
793   std::optional<bool> wantDiagnostics;
794
795   /// Force a complete rebuild of the file, ignoring all cached state. Slow!
796   /// This is useful to defeat clangd's assumption that missing headers will
797   /// stay missing.
798   /// This is a clangd extension.
799   bool forceRebuild = false;
800 };
801 bool fromJSON(const llvm::json::Value &, DidChangeTextDocumentParams &,
802               llvm::json::Path);
803
804 enum class FileChangeType {
805   /// The file got created.
806   Created = 1,
807   /// The file got changed.
808   Changed = 2,
809   /// The file got deleted.
810   Deleted = 3
811 };
812 bool fromJSON(const llvm::json::Value &E, FileChangeType &Out,
813               llvm::json::Path);
814
815 struct FileEvent {
816   /// The file's URI.
817   URIForFile uri;
818   /// The change type.
819   FileChangeType type = FileChangeType::Created;
820 };
821 bool fromJSON(const llvm::json::Value &, FileEvent &, llvm::json::Path);
822
823 struct DidChangeWatchedFilesParams {
824   /// The actual file events.
825   std::vector<FileEvent> changes;
826 };
827 bool fromJSON(const llvm::json::Value &, DidChangeWatchedFilesParams &,
828               llvm::json::Path);
829
830 struct DidChangeConfigurationParams {
831   ConfigurationSettings settings;
832 };
833 bool fromJSON(const llvm::json::Value &, DidChangeConfigurationParams &,
834               llvm::json::Path);
835
836 // Note: we do not parse FormattingOptions for *FormattingParams.
837 // In general, we use a clang-format style detected from common mechanisms
838 // (.clang-format files and the -fallback-style flag).
839 // It would be possible to override these with FormatOptions, but:
840 //  - the protocol makes FormatOptions mandatory, so many clients set them to
841 //    useless values, and we can't tell when to respect them
842 // - we also format in other places, where FormatOptions aren't available.
843
844 struct DocumentRangeFormattingParams {
845   /// The document to format.
846   TextDocumentIdentifier textDocument;
847
848   /// The range to format
849   Range range;
850 };
851 bool fromJSON(const llvm::json::Value &, DocumentRangeFormattingParams &,
852               llvm::json::Path);
853
854 struct DocumentOnTypeFormattingParams {
855   /// The document to format.
856   TextDocumentIdentifier textDocument;
857
858   /// The position at which this request was sent.
859   Position position;
860
861   /// The character that has been typed.
862   std::string ch;
863 };
864 bool fromJSON(const llvm::json::Value &, DocumentOnTypeFormattingParams &,
865               llvm::json::Path);
866
867 struct DocumentFormattingParams {
868   /// The document to format.
869   TextDocumentIdentifier textDocument;
870 };
871 bool fromJSON(const llvm::json::Value &, DocumentFormattingParams &,
872               llvm::json::Path);
873
874 struct DocumentSymbolParams {
875   // The text document to find symbols in.
876   TextDocumentIdentifier textDocument;
877 };
878 bool fromJSON(const llvm::json::Value &, DocumentSymbolParams &,
879               llvm::json::Path);
880
881 /// Represents a related message and source code location for a diagnostic.
882 /// This should be used to point to code locations that cause or related to a
883 /// diagnostics, e.g when duplicating a symbol in a scope.
884 struct DiagnosticRelatedInformation {
885   /// The location of this related diagnostic information.
886   Location location;
887   /// The message of this related diagnostic information.
888   std::string message;
889 };
890 llvm::json::Value toJSON(const DiagnosticRelatedInformation &);
891
892 enum DiagnosticTag {
893   /// Unused or unnecessary code.
894   ///
895   /// Clients are allowed to render diagnostics with this tag faded out instead
896   /// of having an error squiggle.
897   Unnecessary = 1,
898   /// Deprecated or obsolete code.
899   ///
900   /// Clients are allowed to rendered diagnostics with this tag strike through.
901   Deprecated = 2,
902 };
903 llvm::json::Value toJSON(DiagnosticTag Tag);
904
905 /// Structure to capture a description for an error code.
906 struct CodeDescription {
907   /// An URI to open with more information about the diagnostic error.
908   std::string href;
909 };
910 llvm::json::Value toJSON(const CodeDescription &);
911
912 struct CodeAction;
913 struct Diagnostic {
914   /// The range at which the message applies.
915   Range range;
916
917   /// The diagnostic's severity. Can be omitted. If omitted it is up to the
918   /// client to interpret diagnostics as error, warning, info or hint.
919   int severity = 0;
920
921   /// The diagnostic's code. Can be omitted.
922   std::string code;
923
924   /// An optional property to describe the error code.
925   std::optional<CodeDescription> codeDescription;
926
927   /// A human-readable string describing the source of this
928   /// diagnostic, e.g. 'typescript' or 'super lint'.
929   std::string source;
930
931   /// The diagnostic's message.
932   std::string message;
933
934   /// Additional metadata about the diagnostic.
935   llvm::SmallVector<DiagnosticTag, 1> tags;
936
937   /// An array of related diagnostic information, e.g. when symbol-names within
938   /// a scope collide all definitions can be marked via this property.
939   std::optional<std::vector<DiagnosticRelatedInformation>> relatedInformation;
940
941   /// The diagnostic's category. Can be omitted.
942   /// An LSP extension that's used to send the name of the category over to the
943   /// client. The category typically describes the compilation stage during
944   /// which the issue was produced, e.g. "Semantic Issue" or "Parse Issue".
945   std::optional<std::string> category;
946
947   /// Clangd extension: code actions related to this diagnostic.
948   /// Only with capability textDocument.publishDiagnostics.codeActionsInline.
949   /// (These actions can also be obtained using textDocument/codeAction).
950   std::optional<std::vector<CodeAction>> codeActions;
951
952   /// A data entry field that is preserved between a
953   /// `textDocument/publishDiagnostics` notification
954   /// and `textDocument/codeAction` request.
955   /// Mutating users should associate their data with a unique key they can use
956   /// to retrieve later on.
957   llvm::json::Object data;
958 };
959 llvm::json::Value toJSON(const Diagnostic &);
960
961 /// A LSP-specific comparator used to find diagnostic in a container like
962 /// std:map.
963 /// We only use the required fields of Diagnostic to do the comparison to avoid
964 /// any regression issues from LSP clients (e.g. VScode), see
965 /// https://git.io/vbr29
966 struct LSPDiagnosticCompare {
967   bool operator()(const Diagnostic &LHS, const Diagnostic &RHS) const {
968     return std::tie(LHS.range, LHS.message) < std::tie(RHS.range, RHS.message);
969   }
970 };
971 bool fromJSON(const llvm::json::Value &, Diagnostic &, llvm::json::Path);
972 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Diagnostic &);
973
974 struct PublishDiagnosticsParams {
975   /// The URI for which diagnostic information is reported.
976   URIForFile uri;
977   /// An array of diagnostic information items.
978   std::vector<Diagnostic> diagnostics;
979   /// The version number of the document the diagnostics are published for.
980   std::optional<int64_t> version;
981 };
982 llvm::json::Value toJSON(const PublishDiagnosticsParams &);
983
984 struct CodeActionContext {
985   /// An array of diagnostics known on the client side overlapping the range
986   /// provided to the `textDocument/codeAction` request. They are provided so
987   /// that the server knows which errors are currently presented to the user for
988   /// the given range. There is no guarantee that these accurately reflect the
989   /// error state of the resource. The primary parameter to compute code actions
990   /// is the provided range.
991   std::vector<Diagnostic> diagnostics;
992
993   /// Requested kind of actions to return.
994   ///
995   /// Actions not of this kind are filtered out by the client before being
996   /// shown. So servers can omit computing them.
997   std::vector<std::string> only;
998 };
999 bool fromJSON(const llvm::json::Value &, CodeActionContext &, llvm::json::Path);
1000
1001 struct CodeActionParams {
1002   /// The document in which the command was invoked.
1003   TextDocumentIdentifier textDocument;
1004
1005   /// The range for which the command was invoked.
1006   Range range;
1007
1008   /// Context carrying additional information.
1009   CodeActionContext context;
1010 };
1011 bool fromJSON(const llvm::json::Value &, CodeActionParams &, llvm::json::Path);
1012
1013 /// The edit should either provide changes or documentChanges. If the client
1014 /// can handle versioned document edits and if documentChanges are present,
1015 /// the latter are preferred over changes.
1016 struct WorkspaceEdit {
1017   /// Holds changes to existing resources.
1018   std::optional<std::map<std::string, std::vector<TextEdit>>> changes;
1019   /// Versioned document edits.
1020   ///
1021   /// If a client neither supports `documentChanges` nor
1022         /// `workspace.workspaceEdit.resourceOperations` then only plain `TextEdit`s
1023         /// using the `changes` property are supported.
1024   std::optional<std::vector<TextDocumentEdit>> documentChanges;
1025   
1026   /// A map of change annotations that can be referenced in
1027         /// AnnotatedTextEdit.
1028   std::map<std::string, ChangeAnnotation> changeAnnotations;
1029 };
1030 bool fromJSON(const llvm::json::Value &, WorkspaceEdit &, llvm::json::Path);
1031 llvm::json::Value toJSON(const WorkspaceEdit &WE);
1032
1033 /// Arguments for the 'applyTweak' command. The server sends these commands as a
1034 /// response to the textDocument/codeAction request. The client can later send a
1035 /// command back to the server if the user requests to execute a particular code
1036 /// tweak.
1037 struct TweakArgs {
1038   /// A file provided by the client on a textDocument/codeAction request.
1039   URIForFile file;
1040   /// A selection provided by the client on a textDocument/codeAction request.
1041   Range selection;
1042   /// ID of the tweak that should be executed. Corresponds to Tweak::id().
1043   std::string tweakID;
1044 };
1045 bool fromJSON(const llvm::json::Value &, TweakArgs &, llvm::json::Path);
1046 llvm::json::Value toJSON(const TweakArgs &A);
1047
1048 struct ExecuteCommandParams {
1049   /// The identifier of the actual command handler.
1050   std::string command;
1051
1052   // This is `arguments?: []any` in LSP.
1053   // All clangd's commands accept a single argument (or none => null).
1054   llvm::json::Value argument = nullptr;
1055 };
1056 bool fromJSON(const llvm::json::Value &, ExecuteCommandParams &,
1057               llvm::json::Path);
1058
1059 struct Command : public ExecuteCommandParams {
1060   std::string title;
1061 };
1062 llvm::json::Value toJSON(const Command &C);
1063
1064 /// A code action represents a change that can be performed in code, e.g. to fix
1065 /// a problem or to refactor code.
1066 ///
1067 /// A CodeAction must set either `edit` and/or a `command`. If both are
1068 /// supplied, the `edit` is applied first, then the `command` is executed.
1069 struct CodeAction {
1070   /// A short, human-readable, title for this code action.
1071   std::string title;
1072
1073   /// The kind of the code action.
1074   /// Used to filter code actions.
1075   std::optional<std::string> kind;
1076   const static llvm::StringLiteral QUICKFIX_KIND;
1077   const static llvm::StringLiteral REFACTOR_KIND;
1078   const static llvm::StringLiteral INFO_KIND;
1079
1080   /// The diagnostics that this code action resolves.
1081   std::optional<std::vector<Diagnostic>> diagnostics;
1082
1083   /// Marks this as a preferred action. Preferred actions are used by the
1084   /// `auto fix` command and can be targeted by keybindings.
1085   /// A quick fix should be marked preferred if it properly addresses the
1086   /// underlying error. A refactoring should be marked preferred if it is the
1087   /// most reasonable choice of actions to take.
1088   bool isPreferred = false;
1089
1090   /// The workspace edit this code action performs.
1091   std::optional<WorkspaceEdit> edit;
1092
1093   /// A command this code action executes. If a code action provides an edit
1094   /// and a command, first the edit is executed and then the command.
1095   std::optional<Command> command;
1096 };
1097 llvm::json::Value toJSON(const CodeAction &);
1098
1099 /// Represents programming constructs like variables, classes, interfaces etc.
1100 /// that appear in a document. Document symbols can be hierarchical and they
1101 /// have two ranges: one that encloses its definition and one that points to its
1102 /// most interesting range, e.g. the range of an identifier.
1103 struct DocumentSymbol {
1104   /// The name of this symbol.
1105   std::string name;
1106
1107   /// More detail for this symbol, e.g the signature of a function.
1108   std::string detail;
1109
1110   /// The kind of this symbol.
1111   SymbolKind kind;
1112
1113   /// Indicates if this symbol is deprecated.
1114   bool deprecated = false;
1115
1116   /// The range enclosing this symbol not including leading/trailing whitespace
1117   /// but everything else like comments. This information is typically used to
1118   /// determine if the clients cursor is inside the symbol to reveal in the
1119   /// symbol in the UI.
1120   Range range;
1121
1122   /// The range that should be selected and revealed when this symbol is being
1123   /// picked, e.g the name of a function. Must be contained by the `range`.
1124   Range selectionRange;
1125
1126   /// Children of this symbol, e.g. properties of a class.
1127   std::vector<DocumentSymbol> children;
1128 };
1129 llvm::raw_ostream &operator<<(llvm::raw_ostream &O, const DocumentSymbol &S);
1130 llvm::json::Value toJSON(const DocumentSymbol &S);
1131
1132 /// Represents information about programming constructs like variables, classes,
1133 /// interfaces etc.
1134 struct SymbolInformation {
1135   /// The name of this symbol.
1136   std::string name;
1137
1138   /// The kind of this symbol.
1139   SymbolKind kind;
1140
1141   /// The location of this symbol.
1142   Location location;
1143
1144   /// The name of the symbol containing this symbol.
1145   std::string containerName;
1146
1147   /// The score that clangd calculates to rank the returned symbols.
1148   /// This excludes the fuzzy-matching score between `name` and the query.
1149   /// (Specifically, the last ::-separated component).
1150   /// This can be used to re-rank results as the user types, using client-side
1151   /// fuzzy-matching (that score should be multiplied with this one).
1152   /// This is a clangd extension, set only for workspace/symbol responses.
1153   std::optional<float> score;
1154 };
1155 llvm::json::Value toJSON(const SymbolInformation &);
1156 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SymbolInformation &);
1157
1158 /// Represents information about identifier.
1159 /// This is returned from textDocument/symbolInfo, which is a clangd extension.
1160 struct SymbolDetails {
1161   std::string name;
1162
1163   std::string containerName;
1164
1165   /// Unified Symbol Resolution identifier
1166   /// This is an opaque string uniquely identifying a symbol.
1167   /// Unlike SymbolID, it is variable-length and somewhat human-readable.
1168   /// It is a common representation across several clang tools.
1169   /// (See USRGeneration.h)
1170   std::string USR;
1171
1172   SymbolID ID;
1173
1174   std::optional<Location> declarationRange;
1175
1176   std::optional<Location> definitionRange;
1177 };
1178 llvm::json::Value toJSON(const SymbolDetails &);
1179 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SymbolDetails &);
1180 bool operator==(const SymbolDetails &, const SymbolDetails &);
1181
1182 /// The parameters of a Workspace Symbol Request.
1183 struct WorkspaceSymbolParams {
1184   /// A query string to filter symbols by.
1185   /// Clients may send an empty string here to request all the symbols.
1186   std::string query;
1187
1188   /// Max results to return, overriding global default. 0 means no limit.
1189   /// Clangd extension.
1190   std::optional<int> limit;
1191 };
1192 bool fromJSON(const llvm::json::Value &, WorkspaceSymbolParams &,
1193               llvm::json::Path);
1194
1195 struct ApplyWorkspaceEditParams {
1196   WorkspaceEdit edit;
1197 };
1198 llvm::json::Value toJSON(const ApplyWorkspaceEditParams &);
1199
1200 struct ApplyWorkspaceEditResponse {
1201   bool applied = true;
1202   std::optional<std::string> failureReason;
1203 };
1204 bool fromJSON(const llvm::json::Value &, ApplyWorkspaceEditResponse &,
1205               llvm::json::Path);
1206
1207 struct TextDocumentPositionParams {
1208   /// The text document.
1209   TextDocumentIdentifier textDocument;
1210
1211   /// The position inside the text document.
1212   Position position;
1213 };
1214 bool fromJSON(const llvm::json::Value &, TextDocumentPositionParams &,
1215               llvm::json::Path);
1216
1217 enum class CompletionTriggerKind {
1218   /// Completion was triggered by typing an identifier (24x7 code
1219   /// complete), manual invocation (e.g Ctrl+Space) or via API.
1220   Invoked = 1,
1221   /// Completion was triggered by a trigger character specified by
1222   /// the `triggerCharacters` properties of the `CompletionRegistrationOptions`.
1223   TriggerCharacter = 2,
1224   /// Completion was re-triggered as the current completion list is incomplete.
1225   TriggerTriggerForIncompleteCompletions = 3
1226 };
1227
1228 struct CompletionContext {
1229   /// How the completion was triggered.
1230   CompletionTriggerKind triggerKind = CompletionTriggerKind::Invoked;
1231   /// The trigger character (a single character) that has trigger code complete.
1232   /// Is undefined if `triggerKind !== CompletionTriggerKind.TriggerCharacter`
1233   std::string triggerCharacter;
1234 };
1235 bool fromJSON(const llvm::json::Value &, CompletionContext &, llvm::json::Path);
1236
1237 struct CompletionParams : TextDocumentPositionParams {
1238   CompletionContext context;
1239
1240   /// Max results to return, overriding global default. 0 means no limit.
1241   /// Clangd extension.
1242   std::optional<int> limit;
1243 };
1244 bool fromJSON(const llvm::json::Value &, CompletionParams &, llvm::json::Path);
1245
1246 struct MarkupContent {
1247   MarkupKind kind = MarkupKind::PlainText;
1248   std::string value;
1249 };
1250 llvm::json::Value toJSON(const MarkupContent &MC);
1251
1252 struct Hover {
1253   /// The hover's content
1254   MarkupContent contents;
1255
1256   /// An optional range is a range inside a text document
1257   /// that is used to visualize a hover, e.g. by changing the background color.
1258   std::optional<Range> range;
1259 };
1260 llvm::json::Value toJSON(const Hover &H);
1261
1262 /// Defines whether the insert text in a completion item should be interpreted
1263 /// as plain text or a snippet.
1264 enum class InsertTextFormat {
1265   Missing = 0,
1266   /// The primary text to be inserted is treated as a plain string.
1267   PlainText = 1,
1268   /// The primary text to be inserted is treated as a snippet.
1269   ///
1270   /// A snippet can define tab stops and placeholders with `$1`, `$2`
1271   /// and `${3:foo}`. `$0` defines the final tab stop, it defaults to the end
1272   /// of the snippet. Placeholders with equal identifiers are linked, that is
1273   /// typing in one will update others too.
1274   ///
1275   /// See also:
1276   /// https://github.com/Microsoft/vscode/blob/main/src/vs/editor/contrib/snippet/snippet.md
1277   Snippet = 2,
1278 };
1279
1280 struct CompletionItem {
1281   /// The label of this completion item. By default also the text that is
1282   /// inserted when selecting this completion.
1283   std::string label;
1284
1285   /// The kind of this completion item. Based of the kind an icon is chosen by
1286   /// the editor.
1287   CompletionItemKind kind = CompletionItemKind::Missing;
1288
1289   /// A human-readable string with additional information about this item, like
1290   /// type or symbol information.
1291   std::string detail;
1292
1293   /// A human-readable string that represents a doc-comment.
1294   std::optional<MarkupContent> documentation;
1295
1296   /// A string that should be used when comparing this item with other items.
1297   /// When `falsy` the label is used.
1298   std::string sortText;
1299
1300   /// A string that should be used when filtering a set of completion items.
1301   /// When `falsy` the label is used.
1302   std::string filterText;
1303
1304   /// A string that should be inserted to a document when selecting this
1305   /// completion. When `falsy` the label is used.
1306   std::string insertText;
1307
1308   /// The format of the insert text. The format applies to both the `insertText`
1309   /// property and the `newText` property of a provided `textEdit`.
1310   InsertTextFormat insertTextFormat = InsertTextFormat::Missing;
1311
1312   /// An edit which is applied to a document when selecting this completion.
1313   /// When an edit is provided `insertText` is ignored.
1314   ///
1315   /// Note: The range of the edit must be a single line range and it must
1316   /// contain the position at which completion has been requested.
1317   std::optional<TextEdit> textEdit;
1318
1319   /// An optional array of additional text edits that are applied when selecting
1320   /// this completion. Edits must not overlap with the main edit nor with
1321   /// themselves.
1322   std::vector<TextEdit> additionalTextEdits;
1323
1324   /// Indicates if this item is deprecated.
1325   bool deprecated = false;
1326
1327   /// The score that clangd calculates to rank the returned completions.
1328   /// This excludes the fuzzy-match between `filterText` and the partial word.
1329   /// This can be used to re-rank results as the user types, using client-side
1330   /// fuzzy-matching (that score should be multiplied with this one).
1331   /// This is a clangd extension.
1332   float score = 0.f;
1333
1334   // TODO: Add custom commitCharacters for some of the completion items. For
1335   // example, it makes sense to use () only for the functions.
1336   // TODO(krasimir): The following optional fields defined by the language
1337   // server protocol are unsupported:
1338   //
1339   // data?: any - A data entry field that is preserved on a completion item
1340   //              between a completion and a completion resolve request.
1341 };
1342 llvm::json::Value toJSON(const CompletionItem &);
1343 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const CompletionItem &);
1344
1345 bool operator<(const CompletionItem &, const CompletionItem &);
1346
1347 /// Represents a collection of completion items to be presented in the editor.
1348 struct CompletionList {
1349   /// The list is not complete. Further typing should result in recomputing the
1350   /// list.
1351   bool isIncomplete = false;
1352
1353   /// The completion items.
1354   std::vector<CompletionItem> items;
1355 };
1356 llvm::json::Value toJSON(const CompletionList &);
1357
1358 /// A single parameter of a particular signature.
1359 struct ParameterInformation {
1360
1361   /// The label of this parameter. Ignored when labelOffsets is set.
1362   std::string labelString;
1363
1364   /// Inclusive start and exclusive end offsets withing the containing signature
1365   /// label.
1366   /// Offsets are computed by lspLength(), which counts UTF-16 code units by
1367   /// default but that can be overriden, see its documentation for details.
1368   std::optional<std::pair<unsigned, unsigned>> labelOffsets;
1369
1370   /// The documentation of this parameter. Optional.
1371   std::string documentation;
1372 };
1373 llvm::json::Value toJSON(const ParameterInformation &);
1374
1375 /// Represents the signature of something callable.
1376 struct SignatureInformation {
1377
1378   /// The label of this signature. Mandatory.
1379   std::string label;
1380
1381   /// The documentation of this signature. Optional.
1382   MarkupContent documentation;
1383
1384   /// The parameters of this signature.
1385   std::vector<ParameterInformation> parameters;
1386 };
1387 llvm::json::Value toJSON(const SignatureInformation &);
1388 llvm::raw_ostream &operator<<(llvm::raw_ostream &,
1389                               const SignatureInformation &);
1390
1391 /// Represents the signature of a callable.
1392 struct SignatureHelp {
1393
1394   /// The resulting signatures.
1395   std::vector<SignatureInformation> signatures;
1396
1397   /// The active signature.
1398   int activeSignature = 0;
1399
1400   /// The active parameter of the active signature.
1401   int activeParameter = 0;
1402
1403   /// Position of the start of the argument list, including opening paren. e.g.
1404   /// foo("first arg",   "second arg",
1405   ///    ^-argListStart   ^-cursor
1406   /// This is a clangd-specific extension, it is only available via C++ API and
1407   /// not currently serialized for the LSP.
1408   Position argListStart;
1409 };
1410 llvm::json::Value toJSON(const SignatureHelp &);
1411
1412 struct RenameParams {
1413   /// The document that was opened.
1414   TextDocumentIdentifier textDocument;
1415
1416   /// The position at which this request was sent.
1417   Position position;
1418
1419   /// The new name of the symbol.
1420   std::string newName;
1421 };
1422 bool fromJSON(const llvm::json::Value &, RenameParams &, llvm::json::Path);
1423
1424 enum class DocumentHighlightKind { Text = 1, Read = 2, Write = 3 };
1425
1426 /// A document highlight is a range inside a text document which deserves
1427 /// special attention. Usually a document highlight is visualized by changing
1428 /// the background color of its range.
1429
1430 struct DocumentHighlight {
1431   /// The range this highlight applies to.
1432   Range range;
1433
1434   /// The highlight kind, default is DocumentHighlightKind.Text.
1435   DocumentHighlightKind kind = DocumentHighlightKind::Text;
1436
1437   friend bool operator<(const DocumentHighlight &LHS,
1438                         const DocumentHighlight &RHS) {
1439     int LHSKind = static_cast<int>(LHS.kind);
1440     int RHSKind = static_cast<int>(RHS.kind);
1441     return std::tie(LHS.range, LHSKind) < std::tie(RHS.range, RHSKind);
1442   }
1443
1444   friend bool operator==(const DocumentHighlight &LHS,
1445                          const DocumentHighlight &RHS) {
1446     return LHS.kind == RHS.kind && LHS.range == RHS.range;
1447   }
1448 };
1449 llvm::json::Value toJSON(const DocumentHighlight &DH);
1450 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const DocumentHighlight &);
1451
1452 enum class TypeHierarchyDirection { Children = 0, Parents = 1, Both = 2 };
1453 bool fromJSON(const llvm::json::Value &E, TypeHierarchyDirection &Out,
1454               llvm::json::Path);
1455
1456 /// The type hierarchy params is an extension of the
1457 /// `TextDocumentPositionsParams` with optional properties which can be used to
1458 /// eagerly resolve the item when requesting from the server.
1459 struct TypeHierarchyPrepareParams : public TextDocumentPositionParams {
1460   /// The hierarchy levels to resolve. `0` indicates no level.
1461   /// This is a clangd extension.
1462   int resolve = 0;
1463
1464   /// The direction of the hierarchy levels to resolve.
1465   /// This is a clangd extension.
1466   TypeHierarchyDirection direction = TypeHierarchyDirection::Parents;
1467 };
1468 bool fromJSON(const llvm::json::Value &, TypeHierarchyPrepareParams &,
1469               llvm::json::Path);
1470
1471 struct TypeHierarchyItem {
1472   /// The name of this item.
1473   std::string name;
1474
1475   /// The kind of this item.
1476   SymbolKind kind;
1477
1478   /// More detail for this item, e.g. the signature of a function.
1479   std::optional<std::string> detail;
1480
1481   /// The resource identifier of this item.
1482   URIForFile uri;
1483
1484   /// The range enclosing this symbol not including leading/trailing whitespace
1485   /// but everything else, e.g. comments and code.
1486   Range range;
1487
1488   /// The range that should be selected and revealed when this symbol is being
1489   /// picked, e.g. the name of a function. Must be contained by the `range`.
1490   Range selectionRange;
1491
1492   /// Used to resolve a client provided item back.
1493   struct ResolveParams {
1494     SymbolID symbolID;
1495     /// std::nullopt means parents aren't resolved and empty is no parents.
1496     std::optional<std::vector<ResolveParams>> parents;
1497   };
1498   /// A data entry field that is preserved between a type hierarchy prepare and
1499   /// supertypes or subtypes requests. It could also be used to identify the
1500   /// type hierarchy in the server, helping improve the performance on resolving
1501   /// supertypes and subtypes.
1502   ResolveParams data;
1503
1504   /// `true` if the hierarchy item is deprecated. Otherwise, `false`.
1505   /// This is a clangd exntesion.
1506   bool deprecated = false;
1507
1508   /// This is a clangd exntesion.
1509   std::optional<std::vector<TypeHierarchyItem>> parents;
1510
1511   /// If this type hierarchy item is resolved, it contains the direct children
1512   /// of the current item. Could be empty if the item does not have any
1513   /// descendants. If not defined, the children have not been resolved.
1514   /// This is a clangd exntesion.
1515   std::optional<std::vector<TypeHierarchyItem>> children;
1516 };
1517 llvm::json::Value toJSON(const TypeHierarchyItem::ResolveParams &);
1518 bool fromJSON(const TypeHierarchyItem::ResolveParams &);
1519 llvm::json::Value toJSON(const TypeHierarchyItem &);
1520 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const TypeHierarchyItem &);
1521 bool fromJSON(const llvm::json::Value &, TypeHierarchyItem &, llvm::json::Path);
1522
1523 /// Parameters for the `typeHierarchy/resolve` request.
1524 struct ResolveTypeHierarchyItemParams {
1525   /// The item to resolve.
1526   TypeHierarchyItem item;
1527
1528   /// The hierarchy levels to resolve. `0` indicates no level.
1529   int resolve;
1530
1531   /// The direction of the hierarchy levels to resolve.
1532   TypeHierarchyDirection direction;
1533 };
1534 bool fromJSON(const llvm::json::Value &, ResolveTypeHierarchyItemParams &,
1535               llvm::json::Path);
1536
1537 enum class SymbolTag { Deprecated = 1 };
1538 llvm::json::Value toJSON(SymbolTag);
1539
1540 /// The parameter of a `textDocument/prepareCallHierarchy` request.
1541 struct CallHierarchyPrepareParams : public TextDocumentPositionParams {};
1542
1543 /// Represents programming constructs like functions or constructors
1544 /// in the context of call hierarchy.
1545 struct CallHierarchyItem {
1546   /// The name of this item.
1547   std::string name;
1548
1549   /// The kind of this item.
1550   SymbolKind kind;
1551
1552   /// Tags for this item.
1553   std::vector<SymbolTag> tags;
1554
1555   /// More detaill for this item, e.g. the signature of a function.
1556   std::string detail;
1557
1558   /// The resource identifier of this item.
1559   URIForFile uri;
1560
1561   /// The range enclosing this symbol not including leading / trailing
1562   /// whitespace but everything else, e.g. comments and code.
1563   Range range;
1564
1565   /// The range that should be selected and revealed when this symbol
1566   /// is being picked, e.g. the name of a function.
1567   /// Must be contained by `Rng`.
1568   Range selectionRange;
1569
1570   /// An optional 'data' field, which can be used to identify a call
1571   /// hierarchy item in an incomingCalls or outgoingCalls request.
1572   std::string data;
1573 };
1574 llvm::json::Value toJSON(const CallHierarchyItem &);
1575 bool fromJSON(const llvm::json::Value &, CallHierarchyItem &, llvm::json::Path);
1576
1577 /// The parameter of a `callHierarchy/incomingCalls` request.
1578 struct CallHierarchyIncomingCallsParams {
1579   CallHierarchyItem item;
1580 };
1581 bool fromJSON(const llvm::json::Value &, CallHierarchyIncomingCallsParams &,
1582               llvm::json::Path);
1583
1584 /// Represents an incoming call, e.g. a caller of a method or constructor.
1585 struct CallHierarchyIncomingCall {
1586   /// The item that makes the call.
1587   CallHierarchyItem from;
1588
1589   /// The range at which the calls appear.
1590   /// This is relative to the caller denoted by `From`.
1591   std::vector<Range> fromRanges;
1592 };
1593 llvm::json::Value toJSON(const CallHierarchyIncomingCall &);
1594
1595 /// The parameter of a `callHierarchy/outgoingCalls` request.
1596 struct CallHierarchyOutgoingCallsParams {
1597   CallHierarchyItem item;
1598 };
1599 bool fromJSON(const llvm::json::Value &, CallHierarchyOutgoingCallsParams &,
1600               llvm::json::Path);
1601
1602 /// Represents an outgoing call, e.g. calling a getter from a method or
1603 /// a method from a constructor etc.
1604 struct CallHierarchyOutgoingCall {
1605   /// The item that is called.
1606   CallHierarchyItem to;
1607
1608   /// The range at which this item is called.
1609   /// This is the range relative to the caller, and not `To`.
1610   std::vector<Range> fromRanges;
1611 };
1612 llvm::json::Value toJSON(const CallHierarchyOutgoingCall &);
1613
1614 /// A parameter literal used in inlay hint requests.
1615 struct InlayHintsParams {
1616   /// The text document.
1617   TextDocumentIdentifier textDocument;
1618
1619   /// The visible document range for which inlay hints should be computed.
1620   ///
1621   /// std::nullopt is a clangd extension, which hints for computing hints on the
1622   /// whole file.
1623   std::optional<Range> range;
1624 };
1625 bool fromJSON(const llvm::json::Value &, InlayHintsParams &, llvm::json::Path);
1626
1627 /// Inlay hint kinds.
1628 enum class InlayHintKind {
1629   /// An inlay hint that for a type annotation.
1630   ///
1631   /// An example of a type hint is a hint in this position:
1632   ///    auto var ^ = expr;
1633   /// which shows the deduced type of the variable.
1634   Type = 1,
1635
1636   /// An inlay hint that is for a parameter.
1637   ///
1638   /// An example of a parameter hint is a hint in this position:
1639   ///    func(^arg);
1640   /// which shows the name of the corresponding parameter.
1641   Parameter = 2,
1642
1643   /// A hint before an element of an aggregate braced initializer list,
1644   /// indicating what it is initializing.
1645   ///   Pair{^1, ^2};
1646   /// Uses designator syntax, e.g. `.first:`.
1647   /// This is a clangd extension.
1648   Designator = 3,
1649
1650   /// Other ideas for hints that are not currently implemented:
1651   ///
1652   /// * Chaining hints, showing the types of intermediate expressions
1653   ///   in a chain of function calls.
1654   /// * Hints indicating implicit conversions or implicit constructor calls.
1655 };
1656 llvm::json::Value toJSON(const InlayHintKind &);
1657
1658 /// Inlay hint information.
1659 struct InlayHint {
1660   /// The position of this hint.
1661   Position position;
1662
1663   /// The label of this hint. A human readable string or an array of
1664   /// InlayHintLabelPart label parts.
1665   ///
1666   /// *Note* that neither the string nor the label part can be empty.
1667   std::string label;
1668
1669   /// The kind of this hint. Can be omitted in which case the client should fall
1670   /// back to a reasonable default.
1671   InlayHintKind kind;
1672
1673   /// Render padding before the hint.
1674   ///
1675   /// Note: Padding should use the editor's background color, not the
1676   /// background color of the hint itself. That means padding can be used
1677   /// to visually align/separate an inlay hint.
1678   bool paddingLeft = false;
1679
1680   /// Render padding after the hint.
1681   ///
1682   /// Note: Padding should use the editor's background color, not the
1683   /// background color of the hint itself. That means padding can be used
1684   /// to visually align/separate an inlay hint.
1685   bool paddingRight = false;
1686
1687   /// The range of source code to which the hint applies.
1688   ///
1689   /// For example, a parameter hint may have the argument as its range.
1690   /// The range allows clients more flexibility of when/how to display the hint.
1691   /// This is an (unserialized) clangd extension.
1692   Range range;
1693 };
1694 llvm::json::Value toJSON(const InlayHint &);
1695 bool operator==(const InlayHint &, const InlayHint &);
1696 bool operator<(const InlayHint &, const InlayHint &);
1697 llvm::raw_ostream &operator<<(llvm::raw_ostream &, InlayHintKind);
1698
1699 struct ReferenceContext {
1700   /// Include the declaration of the current symbol.
1701   bool includeDeclaration = false;
1702 };
1703
1704 struct ReferenceParams : public TextDocumentPositionParams {
1705   ReferenceContext context;
1706 };
1707 bool fromJSON(const llvm::json::Value &, ReferenceParams &, llvm::json::Path);
1708
1709 /// Clangd extension: indicates the current state of the file in clangd,
1710 /// sent from server via the `textDocument/clangd.fileStatus` notification.
1711 struct FileStatus {
1712   /// The text document's URI.
1713   URIForFile uri;
1714   /// The human-readable string presents the current state of the file, can be
1715   /// shown in the UI (e.g. status bar).
1716   std::string state;
1717   // FIXME: add detail messages.
1718 };
1719 llvm::json::Value toJSON(const FileStatus &);
1720
1721 /// Specifies a single semantic token in the document.
1722 /// This struct is not part of LSP, which just encodes lists of tokens as
1723 /// arrays of numbers directly.
1724 struct SemanticToken {
1725   /// token line number, relative to the previous token
1726   unsigned deltaLine = 0;
1727   /// token start character, relative to the previous token
1728   /// (relative to 0 or the previous token's start if they are on the same line)
1729   unsigned deltaStart = 0;
1730   /// the length of the token. A token cannot be multiline
1731   unsigned length = 0;
1732   /// will be looked up in `SemanticTokensLegend.tokenTypes`
1733   unsigned tokenType = 0;
1734   /// each set bit will be looked up in `SemanticTokensLegend.tokenModifiers`
1735   unsigned tokenModifiers = 0;
1736 };
1737 bool operator==(const SemanticToken &, const SemanticToken &);
1738
1739 /// A versioned set of tokens.
1740 struct SemanticTokens {
1741   // An optional result id. If provided and clients support delta updating
1742   // the client will include the result id in the next semantic token request.
1743   // A server can then instead of computing all semantic tokens again simply
1744   // send a delta.
1745   std::string resultId;
1746
1747   /// The actual tokens.
1748   std::vector<SemanticToken> tokens; // encoded as a flat integer array.
1749 };
1750 llvm::json::Value toJSON(const SemanticTokens &);
1751
1752 /// Body of textDocument/semanticTokens/full request.
1753 struct SemanticTokensParams {
1754   /// The text document.
1755   TextDocumentIdentifier textDocument;
1756 };
1757 bool fromJSON(const llvm::json::Value &, SemanticTokensParams &,
1758               llvm::json::Path);
1759
1760 /// Body of textDocument/semanticTokens/full/delta request.
1761 /// Requests the changes in semantic tokens since a previous response.
1762 struct SemanticTokensDeltaParams {
1763   /// The text document.
1764   TextDocumentIdentifier textDocument;
1765   /// The previous result id.
1766   std::string previousResultId;
1767 };
1768 bool fromJSON(const llvm::json::Value &Params, SemanticTokensDeltaParams &R,
1769               llvm::json::Path);
1770
1771 /// Describes a replacement of a contiguous range of semanticTokens.
1772 struct SemanticTokensEdit {
1773   // LSP specifies `start` and `deleteCount` which are relative to the array
1774   // encoding of the previous tokens.
1775   // We use token counts instead, and translate when serializing this struct.
1776   unsigned startToken = 0;
1777   unsigned deleteTokens = 0;
1778   std::vector<SemanticToken> tokens; // encoded as a flat integer array
1779 };
1780 llvm::json::Value toJSON(const SemanticTokensEdit &);
1781
1782 /// This models LSP SemanticTokensDelta | SemanticTokens, which is the result of
1783 /// textDocument/semanticTokens/full/delta.
1784 struct SemanticTokensOrDelta {
1785   std::string resultId;
1786   /// Set if we computed edits relative to a previous set of tokens.
1787   std::optional<std::vector<SemanticTokensEdit>> edits;
1788   /// Set if we computed a fresh set of tokens.
1789   std::optional<std::vector<SemanticToken>> tokens; // encoded as integer array
1790 };
1791 llvm::json::Value toJSON(const SemanticTokensOrDelta &);
1792
1793 /// Parameters for the inactive regions (server-side) push notification.
1794 /// This is a clangd extension.
1795 struct InactiveRegionsParams {
1796   /// The textdocument these inactive regions belong to.
1797   TextDocumentIdentifier TextDocument;
1798   /// The inactive regions that should be sent.
1799   std::vector<Range> InactiveRegions;
1800 };
1801 llvm::json::Value toJSON(const InactiveRegionsParams &InactiveRegions);
1802
1803 struct SelectionRangeParams {
1804   /// The text document.
1805   TextDocumentIdentifier textDocument;
1806
1807   /// The positions inside the text document.
1808   std::vector<Position> positions;
1809 };
1810 bool fromJSON(const llvm::json::Value &, SelectionRangeParams &,
1811               llvm::json::Path);
1812
1813 struct SelectionRange {
1814   /**
1815    * The range of this selection range.
1816    */
1817   Range range;
1818   /**
1819    * The parent selection range containing this range. Therefore `parent.range`
1820    * must contain `this.range`.
1821    */
1822   std::unique_ptr<SelectionRange> parent;
1823 };
1824 llvm::json::Value toJSON(const SelectionRange &);
1825
1826 /// Parameters for the document link request.
1827 struct DocumentLinkParams {
1828   /// The document to provide document links for.
1829   TextDocumentIdentifier textDocument;
1830 };
1831 bool fromJSON(const llvm::json::Value &, DocumentLinkParams &,
1832               llvm::json::Path);
1833
1834 /// A range in a text document that links to an internal or external resource,
1835 /// like another text document or a web site.
1836 struct DocumentLink {
1837   /// The range this link applies to.
1838   Range range;
1839
1840   /// The uri this link points to. If missing a resolve request is sent later.
1841   URIForFile target;
1842
1843   // TODO(forster): The following optional fields defined by the language
1844   // server protocol are unsupported:
1845   //
1846   // data?: any - A data entry field that is preserved on a document link
1847   //              between a DocumentLinkRequest and a
1848   //              DocumentLinkResolveRequest.
1849
1850   friend bool operator==(const DocumentLink &LHS, const DocumentLink &RHS) {
1851     return LHS.range == RHS.range && LHS.target == RHS.target;
1852   }
1853
1854   friend bool operator!=(const DocumentLink &LHS, const DocumentLink &RHS) {
1855     return !(LHS == RHS);
1856   }
1857 };
1858 llvm::json::Value toJSON(const DocumentLink &DocumentLink);
1859
1860 // FIXME(kirillbobyrev): Add FoldingRangeClientCapabilities so we can support
1861 // per-line-folding editors.
1862 struct FoldingRangeParams {
1863   TextDocumentIdentifier textDocument;
1864 };
1865 bool fromJSON(const llvm::json::Value &, FoldingRangeParams &,
1866               llvm::json::Path);
1867
1868 /// Stores information about a region of code that can be folded.
1869 struct FoldingRange {
1870   unsigned startLine = 0;
1871   unsigned startCharacter;
1872   unsigned endLine = 0;
1873   unsigned endCharacter;
1874
1875   const static llvm::StringLiteral REGION_KIND;
1876   const static llvm::StringLiteral COMMENT_KIND;
1877   const static llvm::StringLiteral IMPORT_KIND;
1878   std::string kind;
1879 };
1880 llvm::json::Value toJSON(const FoldingRange &Range);
1881
1882 /// Keys starting with an underscore(_) represent leaves, e.g. _total or _self
1883 /// for memory usage of whole subtree or only that specific node in bytes. All
1884 /// other keys represents children. An example:
1885 ///   {
1886 ///     "_self": 0,
1887 ///     "_total": 8,
1888 ///     "child1": {
1889 ///       "_self": 4,
1890 ///       "_total": 4,
1891 ///     }
1892 ///     "child2": {
1893 ///       "_self": 2,
1894 ///       "_total": 4,
1895 ///       "child_deep": {
1896 ///         "_self": 2,
1897 ///         "_total": 2,
1898 ///       }
1899 ///     }
1900 ///   }
1901 llvm::json::Value toJSON(const MemoryTree &MT);
1902
1903 /// Payload for textDocument/ast request.
1904 /// This request is a clangd extension.
1905 struct ASTParams {
1906   /// The text document.
1907   TextDocumentIdentifier textDocument;
1908
1909   /// The position of the node to be dumped.
1910   /// The highest-level node that entirely contains the range will be returned.
1911   /// If no range is given, the root translation unit node will be returned.
1912   std::optional<Range> range;
1913 };
1914 bool fromJSON(const llvm::json::Value &, ASTParams &, llvm::json::Path);
1915
1916 /// Simplified description of a clang AST node.
1917 /// This is clangd's internal representation of C++ code.
1918 struct ASTNode {
1919   /// The general kind of node, such as "expression"
1920   /// Corresponds to the base AST node type such as Expr.
1921   std::string role;
1922   /// The specific kind of node this is, such as "BinaryOperator".
1923   /// This is usually a concrete node class (with Expr etc suffix dropped).
1924   /// When there's no hierarchy (e.g. TemplateName), the variant (NameKind).
1925   std::string kind;
1926   /// Brief additional information, such as "||" for the particular operator.
1927   /// The information included depends on the node kind, and may be empty.
1928   std::string detail;
1929   /// A one-line dump of detailed information about the node.
1930   /// This includes role/kind/description information, but is rather cryptic.
1931   /// It is similar to the output from `clang -Xclang -ast-dump`.
1932   /// May be empty for certain types of nodes.
1933   std::string arcana;
1934   /// The range of the original source file covered by this node.
1935   /// May be missing for implicit nodes, or those created by macro expansion.
1936   std::optional<Range> range;
1937   /// Nodes nested within this one, such as the operands of a BinaryOperator.
1938   std::vector<ASTNode> children;
1939 };
1940 llvm::json::Value toJSON(const ASTNode &);
1941 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const ASTNode &);
1942
1943 } // namespace clangd
1944 } // namespace clang
1945
1946 namespace llvm {
1947 template <> struct format_provider<clang::clangd::Position> {
1948   static void format(const clang::clangd::Position &Pos, raw_ostream &OS,
1949                      StringRef Style) {
1950     assert(Style.empty() && "style modifiers for this type are not supported");
1951     OS << Pos;
1952   }
1953 };
1954 } // namespace llvm
1955
1956 // NOLINTEND(readability-identifier-naming)
1957
1958 #endif