Mercurial > hg > CbC > CbC_llvm
comparison clang-tools-extra/clangd/Protocol.h @ 221:79ff65ed7e25
LLVM12 Original
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 15 Jun 2021 19:15:29 +0900 |
parents | 0572611fdcc8 |
children | c4bab56944e8 |
comparison
equal
deleted
inserted
replaced
220:42394fc6a535 | 221:79ff65ed7e25 |
---|---|
23 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROTOCOL_H | 23 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROTOCOL_H |
24 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROTOCOL_H | 24 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROTOCOL_H |
25 | 25 |
26 #include "URI.h" | 26 #include "URI.h" |
27 #include "index/SymbolID.h" | 27 #include "index/SymbolID.h" |
28 #include "support/MemoryTree.h" | |
28 #include "clang/Index/IndexSymbol.h" | 29 #include "clang/Index/IndexSymbol.h" |
29 #include "llvm/ADT/Optional.h" | 30 #include "llvm/ADT/Optional.h" |
30 #include "llvm/Support/JSON.h" | 31 #include "llvm/Support/JSON.h" |
31 #include "llvm/Support/raw_ostream.h" | 32 #include "llvm/Support/raw_ostream.h" |
32 #include <bitset> | 33 #include <bitset> |
114 std::string File; | 115 std::string File; |
115 }; | 116 }; |
116 | 117 |
117 /// Serialize/deserialize \p URIForFile to/from a string URI. | 118 /// Serialize/deserialize \p URIForFile to/from a string URI. |
118 llvm::json::Value toJSON(const URIForFile &U); | 119 llvm::json::Value toJSON(const URIForFile &U); |
119 bool fromJSON(const llvm::json::Value &, URIForFile &); | 120 bool fromJSON(const llvm::json::Value &, URIForFile &, llvm::json::Path); |
120 | 121 |
121 struct TextDocumentIdentifier { | 122 struct TextDocumentIdentifier { |
122 /// The text document's URI. | 123 /// The text document's URI. |
123 URIForFile uri; | 124 URIForFile uri; |
124 }; | 125 }; |
125 llvm::json::Value toJSON(const TextDocumentIdentifier &); | 126 llvm::json::Value toJSON(const TextDocumentIdentifier &); |
126 bool fromJSON(const llvm::json::Value &, TextDocumentIdentifier &); | 127 bool fromJSON(const llvm::json::Value &, TextDocumentIdentifier &, |
128 llvm::json::Path); | |
127 | 129 |
128 struct VersionedTextDocumentIdentifier : public TextDocumentIdentifier { | 130 struct VersionedTextDocumentIdentifier : public TextDocumentIdentifier { |
129 /// The version number of this document. If a versioned text document | 131 /// The version number of this document. If a versioned text document |
130 /// identifier is sent from the server to the client and the file is not open | 132 /// identifier is sent from the server to the client and the file is not open |
131 /// in the editor (the server has not received an open notification before) | 133 /// in the editor (the server has not received an open notification before) |
137 /// | 139 /// |
138 /// clangd extension: versions are optional, and synthesized if missing. | 140 /// clangd extension: versions are optional, and synthesized if missing. |
139 llvm::Optional<std::int64_t> version; | 141 llvm::Optional<std::int64_t> version; |
140 }; | 142 }; |
141 llvm::json::Value toJSON(const VersionedTextDocumentIdentifier &); | 143 llvm::json::Value toJSON(const VersionedTextDocumentIdentifier &); |
142 bool fromJSON(const llvm::json::Value &, VersionedTextDocumentIdentifier &); | 144 bool fromJSON(const llvm::json::Value &, VersionedTextDocumentIdentifier &, |
145 llvm::json::Path); | |
143 | 146 |
144 struct Position { | 147 struct Position { |
145 /// Line position in a document (zero-based). | 148 /// Line position in a document (zero-based). |
146 int line = 0; | 149 int line = 0; |
147 | 150 |
164 friend bool operator<=(const Position &LHS, const Position &RHS) { | 167 friend bool operator<=(const Position &LHS, const Position &RHS) { |
165 return std::tie(LHS.line, LHS.character) <= | 168 return std::tie(LHS.line, LHS.character) <= |
166 std::tie(RHS.line, RHS.character); | 169 std::tie(RHS.line, RHS.character); |
167 } | 170 } |
168 }; | 171 }; |
169 bool fromJSON(const llvm::json::Value &, Position &); | 172 bool fromJSON(const llvm::json::Value &, Position &, llvm::json::Path); |
170 llvm::json::Value toJSON(const Position &); | 173 llvm::json::Value toJSON(const Position &); |
171 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Position &); | 174 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Position &); |
172 | 175 |
173 struct Range { | 176 struct Range { |
174 /// The range's start position. | 177 /// The range's start position. |
190 bool contains(Position Pos) const { return start <= Pos && Pos < end; } | 193 bool contains(Position Pos) const { return start <= Pos && Pos < end; } |
191 bool contains(Range Rng) const { | 194 bool contains(Range Rng) const { |
192 return start <= Rng.start && Rng.end <= end; | 195 return start <= Rng.start && Rng.end <= end; |
193 } | 196 } |
194 }; | 197 }; |
195 bool fromJSON(const llvm::json::Value &, Range &); | 198 bool fromJSON(const llvm::json::Value &, Range &, llvm::json::Path); |
196 llvm::json::Value toJSON(const Range &); | 199 llvm::json::Value toJSON(const Range &); |
197 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Range &); | 200 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Range &); |
198 | 201 |
199 struct Location { | 202 struct Location { |
200 /// The text document's URI. | 203 /// The text document's URI. |
226 std::string newText; | 229 std::string newText; |
227 }; | 230 }; |
228 inline bool operator==(const TextEdit &L, const TextEdit &R) { | 231 inline bool operator==(const TextEdit &L, const TextEdit &R) { |
229 return std::tie(L.newText, L.range) == std::tie(R.newText, R.range); | 232 return std::tie(L.newText, L.range) == std::tie(R.newText, R.range); |
230 } | 233 } |
231 bool fromJSON(const llvm::json::Value &, TextEdit &); | 234 bool fromJSON(const llvm::json::Value &, TextEdit &, llvm::json::Path); |
232 llvm::json::Value toJSON(const TextEdit &); | 235 llvm::json::Value toJSON(const TextEdit &); |
233 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const TextEdit &); | 236 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const TextEdit &); |
234 | 237 |
235 struct TextDocumentItem { | 238 struct TextDocumentItem { |
236 /// The text document's URI. | 239 /// The text document's URI. |
246 llvm::Optional<int64_t> version; | 249 llvm::Optional<int64_t> version; |
247 | 250 |
248 /// The content of the opened text document. | 251 /// The content of the opened text document. |
249 std::string text; | 252 std::string text; |
250 }; | 253 }; |
251 bool fromJSON(const llvm::json::Value &, TextDocumentItem &); | 254 bool fromJSON(const llvm::json::Value &, TextDocumentItem &, llvm::json::Path); |
252 | 255 |
253 enum class TraceLevel { | 256 enum class TraceLevel { |
254 Off = 0, | 257 Off = 0, |
255 Messages = 1, | 258 Messages = 1, |
256 Verbose = 2, | 259 Verbose = 2, |
257 }; | 260 }; |
258 bool fromJSON(const llvm::json::Value &E, TraceLevel &Out); | 261 bool fromJSON(const llvm::json::Value &E, TraceLevel &Out, llvm::json::Path); |
259 | 262 |
260 struct NoParams {}; | 263 struct NoParams {}; |
261 inline bool fromJSON(const llvm::json::Value &, NoParams &) { return true; } | 264 inline llvm::json::Value toJSON(const NoParams &) { return nullptr; } |
265 inline bool fromJSON(const llvm::json::Value &, NoParams &, llvm::json::Path) { | |
266 return true; | |
267 } | |
262 using InitializedParams = NoParams; | 268 using InitializedParams = NoParams; |
263 using ShutdownParams = NoParams; | |
264 using ExitParams = NoParams; | |
265 | 269 |
266 /// Defines how the host (editor) should sync document changes to the language | 270 /// Defines how the host (editor) should sync document changes to the language |
267 /// server. | 271 /// server. |
268 enum class TextDocumentSyncKind { | 272 enum class TextDocumentSyncKind { |
269 /// Documents should not be synced at all. | 273 /// Documents should not be synced at all. |
304 Struct = 22, | 308 Struct = 22, |
305 Event = 23, | 309 Event = 23, |
306 Operator = 24, | 310 Operator = 24, |
307 TypeParameter = 25, | 311 TypeParameter = 25, |
308 }; | 312 }; |
309 bool fromJSON(const llvm::json::Value &, CompletionItemKind &); | 313 bool fromJSON(const llvm::json::Value &, CompletionItemKind &, |
314 llvm::json::Path); | |
310 constexpr auto CompletionItemKindMin = | 315 constexpr auto CompletionItemKindMin = |
311 static_cast<size_t>(CompletionItemKind::Text); | 316 static_cast<size_t>(CompletionItemKind::Text); |
312 constexpr auto CompletionItemKindMax = | 317 constexpr auto CompletionItemKindMax = |
313 static_cast<size_t>(CompletionItemKind::TypeParameter); | 318 static_cast<size_t>(CompletionItemKind::TypeParameter); |
314 using CompletionItemKindBitset = std::bitset<CompletionItemKindMax + 1>; | 319 using CompletionItemKindBitset = std::bitset<CompletionItemKindMax + 1>; |
315 bool fromJSON(const llvm::json::Value &, CompletionItemKindBitset &); | 320 bool fromJSON(const llvm::json::Value &, CompletionItemKindBitset &, |
321 llvm::json::Path); | |
316 CompletionItemKind | 322 CompletionItemKind |
317 adjustKindToCapability(CompletionItemKind Kind, | 323 adjustKindToCapability(CompletionItemKind Kind, |
318 CompletionItemKindBitset &SupportedCompletionItemKinds); | 324 CompletionItemKindBitset &SupportedCompletionItemKinds); |
319 | 325 |
320 /// A symbol kind. | 326 /// A symbol kind. |
344 Struct = 23, | 350 Struct = 23, |
345 Event = 24, | 351 Event = 24, |
346 Operator = 25, | 352 Operator = 25, |
347 TypeParameter = 26 | 353 TypeParameter = 26 |
348 }; | 354 }; |
349 bool fromJSON(const llvm::json::Value &, SymbolKind &); | 355 bool fromJSON(const llvm::json::Value &, SymbolKind &, llvm::json::Path); |
350 constexpr auto SymbolKindMin = static_cast<size_t>(SymbolKind::File); | 356 constexpr auto SymbolKindMin = static_cast<size_t>(SymbolKind::File); |
351 constexpr auto SymbolKindMax = static_cast<size_t>(SymbolKind::TypeParameter); | 357 constexpr auto SymbolKindMax = static_cast<size_t>(SymbolKind::TypeParameter); |
352 using SymbolKindBitset = std::bitset<SymbolKindMax + 1>; | 358 using SymbolKindBitset = std::bitset<SymbolKindMax + 1>; |
353 bool fromJSON(const llvm::json::Value &, SymbolKindBitset &); | 359 bool fromJSON(const llvm::json::Value &, SymbolKindBitset &, llvm::json::Path); |
354 SymbolKind adjustKindToCapability(SymbolKind Kind, | 360 SymbolKind adjustKindToCapability(SymbolKind Kind, |
355 SymbolKindBitset &supportedSymbolKinds); | 361 SymbolKindBitset &supportedSymbolKinds); |
356 | 362 |
357 // Convert a index::SymbolKind to clangd::SymbolKind (LSP) | 363 // Convert a index::SymbolKind to clangd::SymbolKind (LSP) |
358 // Note, some are not perfect matches and should be improved when this LSP | 364 // Note, some are not perfect matches and should be improved when this LSP |
370 UTF8, | 376 UTF8, |
371 // Length counts codepoints in unicode text. (Clangd extension). | 377 // Length counts codepoints in unicode text. (Clangd extension). |
372 UTF32, | 378 UTF32, |
373 }; | 379 }; |
374 llvm::json::Value toJSON(const OffsetEncoding &); | 380 llvm::json::Value toJSON(const OffsetEncoding &); |
375 bool fromJSON(const llvm::json::Value &, OffsetEncoding &); | 381 bool fromJSON(const llvm::json::Value &, OffsetEncoding &, llvm::json::Path); |
376 llvm::raw_ostream &operator<<(llvm::raw_ostream &, OffsetEncoding); | 382 llvm::raw_ostream &operator<<(llvm::raw_ostream &, OffsetEncoding); |
377 | 383 |
378 // Describes the content type that a client supports in various result literals | 384 // Describes the content type that a client supports in various result literals |
379 // like `Hover`, `ParameterInfo` or `CompletionItem`. | 385 // like `Hover`, `ParameterInfo` or `CompletionItem`. |
380 enum class MarkupKind { | 386 enum class MarkupKind { |
381 PlainText, | 387 PlainText, |
382 Markdown, | 388 Markdown, |
383 }; | 389 }; |
384 bool fromJSON(const llvm::json::Value &, MarkupKind &); | 390 bool fromJSON(const llvm::json::Value &, MarkupKind &, llvm::json::Path); |
385 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, MarkupKind); | 391 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, MarkupKind); |
386 | 392 |
387 // This struct doesn't mirror LSP! | 393 // This struct doesn't mirror LSP! |
388 // The protocol defines deeply nested structures for client capabilities. | 394 // The protocol defines deeply nested structures for client capabilities. |
389 // Instead of mapping them all, this just parses out the bits we care about. | 395 // Instead of mapping them all, this just parses out the bits we care about. |
442 /// We support the textDocument/semanticTokens request in any case. | 448 /// We support the textDocument/semanticTokens request in any case. |
443 /// textDocument.semanticTokens | 449 /// textDocument.semanticTokens |
444 bool SemanticTokens = false; | 450 bool SemanticTokens = false; |
445 /// Client supports Theia semantic highlighting extension. | 451 /// Client supports Theia semantic highlighting extension. |
446 /// https://github.com/microsoft/vscode-languageserver-node/pull/367 | 452 /// https://github.com/microsoft/vscode-languageserver-node/pull/367 |
447 /// This will be ignored if the client also supports semanticTokens. | 453 /// clangd no longer supports this, we detect it just to log a warning. |
448 /// textDocument.semanticHighlightingCapabilities.semanticHighlighting | 454 /// textDocument.semanticHighlightingCapabilities.semanticHighlighting |
449 /// FIXME: drop this support once clients support LSP 3.16 Semantic Tokens. | |
450 bool TheiaSemanticHighlighting = false; | 455 bool TheiaSemanticHighlighting = false; |
451 | 456 |
452 /// Supported encodings for LSP character offsets. (clangd extension). | 457 /// Supported encodings for LSP character offsets. (clangd extension). |
453 llvm::Optional<std::vector<OffsetEncoding>> offsetEncoding; | 458 llvm::Optional<std::vector<OffsetEncoding>> offsetEncoding; |
454 | 459 |
467 /// The client supports implicit $/progress work-done progress streams, | 472 /// The client supports implicit $/progress work-done progress streams, |
468 /// without a preceding window/workDoneProgress/create. | 473 /// without a preceding window/workDoneProgress/create. |
469 /// This is a clangd extension. | 474 /// This is a clangd extension. |
470 /// window.implicitWorkDoneProgressCreate | 475 /// window.implicitWorkDoneProgressCreate |
471 bool ImplicitProgressCreation = false; | 476 bool ImplicitProgressCreation = false; |
472 }; | 477 |
473 bool fromJSON(const llvm::json::Value &, ClientCapabilities &); | 478 /// Whether the client claims to cancel stale requests. |
479 /// general.staleRequestSupport.cancel | |
480 bool CancelsStaleRequests = false; | |
481 | |
482 /// Whether the client implementation supports a refresh request sent from the | |
483 /// server to the client. | |
484 bool SemanticTokenRefreshSupport = false; | |
485 }; | |
486 bool fromJSON(const llvm::json::Value &, ClientCapabilities &, | |
487 llvm::json::Path); | |
474 | 488 |
475 /// Clangd extension that's used in the 'compilationDatabaseChanges' in | 489 /// Clangd extension that's used in the 'compilationDatabaseChanges' in |
476 /// workspace/didChangeConfiguration to record updates to the in-memory | 490 /// workspace/didChangeConfiguration to record updates to the in-memory |
477 /// compilation database. | 491 /// compilation database. |
478 struct ClangdCompileCommand { | 492 struct ClangdCompileCommand { |
479 std::string workingDirectory; | 493 std::string workingDirectory; |
480 std::vector<std::string> compilationCommand; | 494 std::vector<std::string> compilationCommand; |
481 }; | 495 }; |
482 bool fromJSON(const llvm::json::Value &, ClangdCompileCommand &); | 496 bool fromJSON(const llvm::json::Value &, ClangdCompileCommand &, |
497 llvm::json::Path); | |
483 | 498 |
484 /// Clangd extension: parameters configurable at any time, via the | 499 /// Clangd extension: parameters configurable at any time, via the |
485 /// `workspace/didChangeConfiguration` notification. | 500 /// `workspace/didChangeConfiguration` notification. |
486 /// LSP defines this type as `any`. | 501 /// LSP defines this type as `any`. |
487 struct ConfigurationSettings { | 502 struct ConfigurationSettings { |
488 // Changes to the in-memory compilation database. | 503 // Changes to the in-memory compilation database. |
489 // The key of the map is a file name. | 504 // The key of the map is a file name. |
490 std::map<std::string, ClangdCompileCommand> compilationDatabaseChanges; | 505 std::map<std::string, ClangdCompileCommand> compilationDatabaseChanges; |
491 }; | 506 }; |
492 bool fromJSON(const llvm::json::Value &, ConfigurationSettings &); | 507 bool fromJSON(const llvm::json::Value &, ConfigurationSettings &, |
508 llvm::json::Path); | |
493 | 509 |
494 /// Clangd extension: parameters configurable at `initialize` time. | 510 /// Clangd extension: parameters configurable at `initialize` time. |
495 /// LSP defines this type as `any`. | 511 /// LSP defines this type as `any`. |
496 struct InitializationOptions { | 512 struct InitializationOptions { |
497 // What we can change throught the didChangeConfiguration request, we can | 513 // What we can change throught the didChangeConfiguration request, we can |
505 std::vector<std::string> fallbackFlags; | 521 std::vector<std::string> fallbackFlags; |
506 | 522 |
507 /// Clients supports show file status for textDocument/clangd.fileStatus. | 523 /// Clients supports show file status for textDocument/clangd.fileStatus. |
508 bool FileStatus = false; | 524 bool FileStatus = false; |
509 }; | 525 }; |
510 bool fromJSON(const llvm::json::Value &, InitializationOptions &); | 526 bool fromJSON(const llvm::json::Value &, InitializationOptions &, |
527 llvm::json::Path); | |
511 | 528 |
512 struct InitializeParams { | 529 struct InitializeParams { |
513 /// The process Id of the parent process that started | 530 /// The process Id of the parent process that started |
514 /// the server. Is null if the process has not been started by another | 531 /// the server. Is null if the process has not been started by another |
515 /// process. If the parent process is not alive then the server should exit | 532 /// process. If the parent process is not alive then the server should exit |
530 // User provided initialization options. | 547 // User provided initialization options. |
531 // initializationOptions?: any; | 548 // initializationOptions?: any; |
532 | 549 |
533 /// The capabilities provided by the client (editor or tool) | 550 /// The capabilities provided by the client (editor or tool) |
534 ClientCapabilities capabilities; | 551 ClientCapabilities capabilities; |
552 /// The same data as capabilities, but not parsed (to expose to modules). | |
553 llvm::json::Object rawCapabilities; | |
535 | 554 |
536 /// The initial trace setting. If omitted trace is disabled ('off'). | 555 /// The initial trace setting. If omitted trace is disabled ('off'). |
537 llvm::Optional<TraceLevel> trace; | 556 llvm::Optional<TraceLevel> trace; |
538 | 557 |
539 /// User-provided initialization options. | 558 /// User-provided initialization options. |
540 InitializationOptions initializationOptions; | 559 InitializationOptions initializationOptions; |
541 }; | 560 }; |
542 bool fromJSON(const llvm::json::Value &, InitializeParams &); | 561 bool fromJSON(const llvm::json::Value &, InitializeParams &, llvm::json::Path); |
543 | 562 |
544 struct WorkDoneProgressCreateParams { | 563 struct WorkDoneProgressCreateParams { |
545 /// The token to be used to report progress. | 564 /// The token to be used to report progress. |
546 llvm::json::Value token = nullptr; | 565 llvm::json::Value token = nullptr; |
547 }; | 566 }; |
610 /// If not provided infinite progress is assumed and clients are allowed | 629 /// If not provided infinite progress is assumed and clients are allowed |
611 /// to ignore the `percentage` value in subsequent in report notifications. | 630 /// to ignore the `percentage` value in subsequent in report notifications. |
612 /// | 631 /// |
613 /// The value should be steadily rising. Clients are free to ignore values | 632 /// The value should be steadily rising. Clients are free to ignore values |
614 /// that are not following this rule. | 633 /// that are not following this rule. |
615 llvm::Optional<double> percentage; | 634 llvm::Optional<unsigned> percentage; |
616 }; | 635 }; |
617 llvm::json::Value toJSON(const WorkDoneProgressReport &); | 636 llvm::json::Value toJSON(const WorkDoneProgressReport &); |
618 // | 637 // |
619 /// Signals the end of progress reporting. | 638 /// Signals the end of progress reporting. |
620 struct WorkDoneProgressEnd { | 639 struct WorkDoneProgressEnd { |
648 | 667 |
649 struct DidOpenTextDocumentParams { | 668 struct DidOpenTextDocumentParams { |
650 /// The document that was opened. | 669 /// The document that was opened. |
651 TextDocumentItem textDocument; | 670 TextDocumentItem textDocument; |
652 }; | 671 }; |
653 bool fromJSON(const llvm::json::Value &, DidOpenTextDocumentParams &); | 672 bool fromJSON(const llvm::json::Value &, DidOpenTextDocumentParams &, |
673 llvm::json::Path); | |
654 | 674 |
655 struct DidCloseTextDocumentParams { | 675 struct DidCloseTextDocumentParams { |
656 /// The document that was closed. | 676 /// The document that was closed. |
657 TextDocumentIdentifier textDocument; | 677 TextDocumentIdentifier textDocument; |
658 }; | 678 }; |
659 bool fromJSON(const llvm::json::Value &, DidCloseTextDocumentParams &); | 679 bool fromJSON(const llvm::json::Value &, DidCloseTextDocumentParams &, |
680 llvm::json::Path); | |
660 | 681 |
661 struct DidSaveTextDocumentParams { | 682 struct DidSaveTextDocumentParams { |
662 /// The document that was saved. | 683 /// The document that was saved. |
663 TextDocumentIdentifier textDocument; | 684 TextDocumentIdentifier textDocument; |
664 }; | 685 }; |
665 bool fromJSON(const llvm::json::Value &, DidSaveTextDocumentParams &); | 686 bool fromJSON(const llvm::json::Value &, DidSaveTextDocumentParams &, |
687 llvm::json::Path); | |
666 | 688 |
667 struct TextDocumentContentChangeEvent { | 689 struct TextDocumentContentChangeEvent { |
668 /// The range of the document that changed. | 690 /// The range of the document that changed. |
669 llvm::Optional<Range> range; | 691 llvm::Optional<Range> range; |
670 | 692 |
672 llvm::Optional<int> rangeLength; | 694 llvm::Optional<int> rangeLength; |
673 | 695 |
674 /// The new text of the range/document. | 696 /// The new text of the range/document. |
675 std::string text; | 697 std::string text; |
676 }; | 698 }; |
677 bool fromJSON(const llvm::json::Value &, TextDocumentContentChangeEvent &); | 699 bool fromJSON(const llvm::json::Value &, TextDocumentContentChangeEvent &, |
700 llvm::json::Path); | |
678 | 701 |
679 struct DidChangeTextDocumentParams { | 702 struct DidChangeTextDocumentParams { |
680 /// The document that did change. The version number points | 703 /// The document that did change. The version number points |
681 /// to the version after all provided content changes have | 704 /// to the version after all provided content changes have |
682 /// been applied. | 705 /// been applied. |
695 /// This is useful to defeat clangd's assumption that missing headers will | 718 /// This is useful to defeat clangd's assumption that missing headers will |
696 /// stay missing. | 719 /// stay missing. |
697 /// This is a clangd extension. | 720 /// This is a clangd extension. |
698 bool forceRebuild = false; | 721 bool forceRebuild = false; |
699 }; | 722 }; |
700 bool fromJSON(const llvm::json::Value &, DidChangeTextDocumentParams &); | 723 bool fromJSON(const llvm::json::Value &, DidChangeTextDocumentParams &, |
724 llvm::json::Path); | |
701 | 725 |
702 enum class FileChangeType { | 726 enum class FileChangeType { |
703 /// The file got created. | 727 /// The file got created. |
704 Created = 1, | 728 Created = 1, |
705 /// The file got changed. | 729 /// The file got changed. |
706 Changed = 2, | 730 Changed = 2, |
707 /// The file got deleted. | 731 /// The file got deleted. |
708 Deleted = 3 | 732 Deleted = 3 |
709 }; | 733 }; |
710 bool fromJSON(const llvm::json::Value &E, FileChangeType &Out); | 734 bool fromJSON(const llvm::json::Value &E, FileChangeType &Out, |
735 llvm::json::Path); | |
711 | 736 |
712 struct FileEvent { | 737 struct FileEvent { |
713 /// The file's URI. | 738 /// The file's URI. |
714 URIForFile uri; | 739 URIForFile uri; |
715 /// The change type. | 740 /// The change type. |
716 FileChangeType type = FileChangeType::Created; | 741 FileChangeType type = FileChangeType::Created; |
717 }; | 742 }; |
718 bool fromJSON(const llvm::json::Value &, FileEvent &); | 743 bool fromJSON(const llvm::json::Value &, FileEvent &, llvm::json::Path); |
719 | 744 |
720 struct DidChangeWatchedFilesParams { | 745 struct DidChangeWatchedFilesParams { |
721 /// The actual file events. | 746 /// The actual file events. |
722 std::vector<FileEvent> changes; | 747 std::vector<FileEvent> changes; |
723 }; | 748 }; |
724 bool fromJSON(const llvm::json::Value &, DidChangeWatchedFilesParams &); | 749 bool fromJSON(const llvm::json::Value &, DidChangeWatchedFilesParams &, |
750 llvm::json::Path); | |
725 | 751 |
726 struct DidChangeConfigurationParams { | 752 struct DidChangeConfigurationParams { |
727 ConfigurationSettings settings; | 753 ConfigurationSettings settings; |
728 }; | 754 }; |
729 bool fromJSON(const llvm::json::Value &, DidChangeConfigurationParams &); | 755 bool fromJSON(const llvm::json::Value &, DidChangeConfigurationParams &, |
756 llvm::json::Path); | |
730 | 757 |
731 // Note: we do not parse FormattingOptions for *FormattingParams. | 758 // Note: we do not parse FormattingOptions for *FormattingParams. |
732 // In general, we use a clang-format style detected from common mechanisms | 759 // In general, we use a clang-format style detected from common mechanisms |
733 // (.clang-format files and the -fallback-style flag). | 760 // (.clang-format files and the -fallback-style flag). |
734 // It would be possible to override these with FormatOptions, but: | 761 // It would be possible to override these with FormatOptions, but: |
741 TextDocumentIdentifier textDocument; | 768 TextDocumentIdentifier textDocument; |
742 | 769 |
743 /// The range to format | 770 /// The range to format |
744 Range range; | 771 Range range; |
745 }; | 772 }; |
746 bool fromJSON(const llvm::json::Value &, DocumentRangeFormattingParams &); | 773 bool fromJSON(const llvm::json::Value &, DocumentRangeFormattingParams &, |
774 llvm::json::Path); | |
747 | 775 |
748 struct DocumentOnTypeFormattingParams { | 776 struct DocumentOnTypeFormattingParams { |
749 /// The document to format. | 777 /// The document to format. |
750 TextDocumentIdentifier textDocument; | 778 TextDocumentIdentifier textDocument; |
751 | 779 |
753 Position position; | 781 Position position; |
754 | 782 |
755 /// The character that has been typed. | 783 /// The character that has been typed. |
756 std::string ch; | 784 std::string ch; |
757 }; | 785 }; |
758 bool fromJSON(const llvm::json::Value &, DocumentOnTypeFormattingParams &); | 786 bool fromJSON(const llvm::json::Value &, DocumentOnTypeFormattingParams &, |
787 llvm::json::Path); | |
759 | 788 |
760 struct DocumentFormattingParams { | 789 struct DocumentFormattingParams { |
761 /// The document to format. | 790 /// The document to format. |
762 TextDocumentIdentifier textDocument; | 791 TextDocumentIdentifier textDocument; |
763 }; | 792 }; |
764 bool fromJSON(const llvm::json::Value &, DocumentFormattingParams &); | 793 bool fromJSON(const llvm::json::Value &, DocumentFormattingParams &, |
794 llvm::json::Path); | |
765 | 795 |
766 struct DocumentSymbolParams { | 796 struct DocumentSymbolParams { |
767 // The text document to find symbols in. | 797 // The text document to find symbols in. |
768 TextDocumentIdentifier textDocument; | 798 TextDocumentIdentifier textDocument; |
769 }; | 799 }; |
770 bool fromJSON(const llvm::json::Value &, DocumentSymbolParams &); | 800 bool fromJSON(const llvm::json::Value &, DocumentSymbolParams &, |
801 llvm::json::Path); | |
771 | 802 |
772 /// Represents a related message and source code location for a diagnostic. | 803 /// Represents a related message and source code location for a diagnostic. |
773 /// This should be used to point to code locations that cause or related to a | 804 /// This should be used to point to code locations that cause or related to a |
774 /// diagnostics, e.g when duplicating a symbol in a scope. | 805 /// diagnostics, e.g when duplicating a symbol in a scope. |
775 struct DiagnosticRelatedInformation { | 806 struct DiagnosticRelatedInformation { |
811 | 842 |
812 /// Clangd extension: code actions related to this diagnostic. | 843 /// Clangd extension: code actions related to this diagnostic. |
813 /// Only with capability textDocument.publishDiagnostics.codeActionsInline. | 844 /// Only with capability textDocument.publishDiagnostics.codeActionsInline. |
814 /// (These actions can also be obtained using textDocument/codeAction). | 845 /// (These actions can also be obtained using textDocument/codeAction). |
815 llvm::Optional<std::vector<CodeAction>> codeActions; | 846 llvm::Optional<std::vector<CodeAction>> codeActions; |
847 | |
848 /// A data entry field that is preserved between a | |
849 /// `textDocument/publishDiagnostics` notification | |
850 /// and`textDocument/codeAction` request. | |
851 /// Mutating users should associate their data with a unique key they can use | |
852 /// to retrieve later on. | |
853 llvm::json::Object data; | |
816 }; | 854 }; |
817 llvm::json::Value toJSON(const Diagnostic &); | 855 llvm::json::Value toJSON(const Diagnostic &); |
818 | 856 |
819 /// A LSP-specific comparator used to find diagnostic in a container like | 857 /// A LSP-specific comparator used to find diagnostic in a container like |
820 /// std:map. | 858 /// std:map. |
824 struct LSPDiagnosticCompare { | 862 struct LSPDiagnosticCompare { |
825 bool operator()(const Diagnostic &LHS, const Diagnostic &RHS) const { | 863 bool operator()(const Diagnostic &LHS, const Diagnostic &RHS) const { |
826 return std::tie(LHS.range, LHS.message) < std::tie(RHS.range, RHS.message); | 864 return std::tie(LHS.range, LHS.message) < std::tie(RHS.range, RHS.message); |
827 } | 865 } |
828 }; | 866 }; |
829 bool fromJSON(const llvm::json::Value &, Diagnostic &); | 867 bool fromJSON(const llvm::json::Value &, Diagnostic &, llvm::json::Path); |
830 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Diagnostic &); | 868 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Diagnostic &); |
831 | 869 |
832 struct PublishDiagnosticsParams { | 870 struct PublishDiagnosticsParams { |
833 /// The URI for which diagnostic information is reported. | 871 /// The URI for which diagnostic information is reported. |
834 URIForFile uri; | 872 URIForFile uri; |
838 llvm::Optional<int64_t> version; | 876 llvm::Optional<int64_t> version; |
839 }; | 877 }; |
840 llvm::json::Value toJSON(const PublishDiagnosticsParams &); | 878 llvm::json::Value toJSON(const PublishDiagnosticsParams &); |
841 | 879 |
842 struct CodeActionContext { | 880 struct CodeActionContext { |
843 /// An array of diagnostics. | 881 /// An array of diagnostics known on the client side overlapping the range |
882 /// provided to the `textDocument/codeAction` request. They are provided so | |
883 /// that the server knows which errors are currently presented to the user for | |
884 /// the given range. There is no guarantee that these accurately reflect the | |
885 /// error state of the resource. The primary parameter to compute code actions | |
886 /// is the provided range. | |
844 std::vector<Diagnostic> diagnostics; | 887 std::vector<Diagnostic> diagnostics; |
845 }; | 888 |
846 bool fromJSON(const llvm::json::Value &, CodeActionContext &); | 889 /// Requested kind of actions to return. |
890 /// | |
891 /// Actions not of this kind are filtered out by the client before being | |
892 /// shown. So servers can omit computing them. | |
893 std::vector<std::string> only; | |
894 }; | |
895 bool fromJSON(const llvm::json::Value &, CodeActionContext &, llvm::json::Path); | |
847 | 896 |
848 struct CodeActionParams { | 897 struct CodeActionParams { |
849 /// The document in which the command was invoked. | 898 /// The document in which the command was invoked. |
850 TextDocumentIdentifier textDocument; | 899 TextDocumentIdentifier textDocument; |
851 | 900 |
853 Range range; | 902 Range range; |
854 | 903 |
855 /// Context carrying additional information. | 904 /// Context carrying additional information. |
856 CodeActionContext context; | 905 CodeActionContext context; |
857 }; | 906 }; |
858 bool fromJSON(const llvm::json::Value &, CodeActionParams &); | 907 bool fromJSON(const llvm::json::Value &, CodeActionParams &, llvm::json::Path); |
859 | 908 |
860 struct WorkspaceEdit { | 909 struct WorkspaceEdit { |
861 /// Holds changes to existing resources. | 910 /// Holds changes to existing resources. |
862 llvm::Optional<std::map<std::string, std::vector<TextEdit>>> changes; | 911 std::map<std::string, std::vector<TextEdit>> changes; |
863 | 912 |
864 /// Note: "documentChanges" is not currently used because currently there is | 913 /// Note: "documentChanges" is not currently used because currently there is |
865 /// no support for versioned edits. | 914 /// no support for versioned edits. |
866 }; | 915 }; |
867 bool fromJSON(const llvm::json::Value &, WorkspaceEdit &); | 916 bool fromJSON(const llvm::json::Value &, WorkspaceEdit &, llvm::json::Path); |
868 llvm::json::Value toJSON(const WorkspaceEdit &WE); | 917 llvm::json::Value toJSON(const WorkspaceEdit &WE); |
869 | 918 |
870 /// Arguments for the 'applyTweak' command. The server sends these commands as a | 919 /// Arguments for the 'applyTweak' command. The server sends these commands as a |
871 /// response to the textDocument/codeAction request. The client can later send a | 920 /// response to the textDocument/codeAction request. The client can later send a |
872 /// command back to the server if the user requests to execute a particular code | 921 /// command back to the server if the user requests to execute a particular code |
877 /// A selection provided by the client on a textDocument/codeAction request. | 926 /// A selection provided by the client on a textDocument/codeAction request. |
878 Range selection; | 927 Range selection; |
879 /// ID of the tweak that should be executed. Corresponds to Tweak::id(). | 928 /// ID of the tweak that should be executed. Corresponds to Tweak::id(). |
880 std::string tweakID; | 929 std::string tweakID; |
881 }; | 930 }; |
882 bool fromJSON(const llvm::json::Value &, TweakArgs &); | 931 bool fromJSON(const llvm::json::Value &, TweakArgs &, llvm::json::Path); |
883 llvm::json::Value toJSON(const TweakArgs &A); | 932 llvm::json::Value toJSON(const TweakArgs &A); |
884 | 933 |
885 /// Exact commands are not specified in the protocol so we define the | |
886 /// ones supported by Clangd here. The protocol specifies the command arguments | |
887 /// to be "any[]" but to make this safer and more manageable, each command we | |
888 /// handle maps to a certain llvm::Optional of some struct to contain its | |
889 /// arguments. Different commands could reuse the same llvm::Optional as | |
890 /// arguments but a command that needs different arguments would simply add a | |
891 /// new llvm::Optional and not use any other ones. In practice this means only | |
892 /// one argument type will be parsed and set. | |
893 struct ExecuteCommandParams { | 934 struct ExecuteCommandParams { |
894 // Command to apply fix-its. Uses WorkspaceEdit as argument. | 935 /// The identifier of the actual command handler. |
895 const static llvm::StringLiteral CLANGD_APPLY_FIX_COMMAND; | |
896 // Command to apply the code action. Uses TweakArgs as argument. | |
897 const static llvm::StringLiteral CLANGD_APPLY_TWEAK; | |
898 | |
899 /// The command identifier, e.g. CLANGD_APPLY_FIX_COMMAND | |
900 std::string command; | 936 std::string command; |
901 | 937 |
902 // Arguments | 938 // This is `arguments?: []any` in LSP. |
903 llvm::Optional<WorkspaceEdit> workspaceEdit; | 939 // All clangd's commands accept a single argument (or none => null). |
904 llvm::Optional<TweakArgs> tweakArgs; | 940 llvm::json::Value argument = nullptr; |
905 }; | 941 }; |
906 bool fromJSON(const llvm::json::Value &, ExecuteCommandParams &); | 942 bool fromJSON(const llvm::json::Value &, ExecuteCommandParams &, |
943 llvm::json::Path); | |
907 | 944 |
908 struct Command : public ExecuteCommandParams { | 945 struct Command : public ExecuteCommandParams { |
909 std::string title; | 946 std::string title; |
910 }; | 947 }; |
911 llvm::json::Value toJSON(const Command &C); | 948 llvm::json::Value toJSON(const Command &C); |
927 const static llvm::StringLiteral INFO_KIND; | 964 const static llvm::StringLiteral INFO_KIND; |
928 | 965 |
929 /// The diagnostics that this code action resolves. | 966 /// The diagnostics that this code action resolves. |
930 llvm::Optional<std::vector<Diagnostic>> diagnostics; | 967 llvm::Optional<std::vector<Diagnostic>> diagnostics; |
931 | 968 |
969 /// Marks this as a preferred action. Preferred actions are used by the | |
970 /// `auto fix` command and can be targeted by keybindings. | |
971 /// A quick fix should be marked preferred if it properly addresses the | |
972 /// underlying error. A refactoring should be marked preferred if it is the | |
973 /// most reasonable choice of actions to take. | |
974 bool isPreferred = false; | |
975 | |
932 /// The workspace edit this code action performs. | 976 /// The workspace edit this code action performs. |
933 llvm::Optional<WorkspaceEdit> edit; | 977 llvm::Optional<WorkspaceEdit> edit; |
934 | 978 |
935 /// A command this code action executes. If a code action provides an edit | 979 /// A command this code action executes. If a code action provides an edit |
936 /// and a command, first the edit is executed and then the command. | 980 /// and a command, first the edit is executed and then the command. |
951 | 995 |
952 /// The kind of this symbol. | 996 /// The kind of this symbol. |
953 SymbolKind kind; | 997 SymbolKind kind; |
954 | 998 |
955 /// Indicates if this symbol is deprecated. | 999 /// Indicates if this symbol is deprecated. |
956 bool deprecated; | 1000 bool deprecated = false; |
957 | 1001 |
958 /// The range enclosing this symbol not including leading/trailing whitespace | 1002 /// The range enclosing this symbol not including leading/trailing whitespace |
959 /// but everything else like comments. This information is typically used to | 1003 /// but everything else like comments. This information is typically used to |
960 /// determine if the clients cursor is inside the symbol to reveal in the | 1004 /// determine if the clients cursor is inside the symbol to reveal in the |
961 /// symbol in the UI. | 1005 /// symbol in the UI. |
983 /// The location of this symbol. | 1027 /// The location of this symbol. |
984 Location location; | 1028 Location location; |
985 | 1029 |
986 /// The name of the symbol containing this symbol. | 1030 /// The name of the symbol containing this symbol. |
987 std::string containerName; | 1031 std::string containerName; |
1032 | |
1033 /// The score that clangd calculates to rank the returned symbols. | |
1034 /// This excludes the fuzzy-matching score between `name` and the query. | |
1035 /// (Specifically, the last ::-separated component). | |
1036 /// This can be used to re-rank results as the user types, using client-side | |
1037 /// fuzzy-matching (that score should be multiplied with this one). | |
1038 /// This is a clangd extension, set only for workspace/symbol responses. | |
1039 llvm::Optional<float> score; | |
988 }; | 1040 }; |
989 llvm::json::Value toJSON(const SymbolInformation &); | 1041 llvm::json::Value toJSON(const SymbolInformation &); |
990 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SymbolInformation &); | 1042 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SymbolInformation &); |
991 | 1043 |
992 /// Represents information about identifier. | 1044 /// Represents information about identifier. |
1001 /// Unlike SymbolID, it is variable-length and somewhat human-readable. | 1053 /// Unlike SymbolID, it is variable-length and somewhat human-readable. |
1002 /// It is a common representation across several clang tools. | 1054 /// It is a common representation across several clang tools. |
1003 /// (See USRGeneration.h) | 1055 /// (See USRGeneration.h) |
1004 std::string USR; | 1056 std::string USR; |
1005 | 1057 |
1006 llvm::Optional<SymbolID> ID; | 1058 SymbolID ID; |
1007 }; | 1059 }; |
1008 llvm::json::Value toJSON(const SymbolDetails &); | 1060 llvm::json::Value toJSON(const SymbolDetails &); |
1009 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SymbolDetails &); | 1061 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SymbolDetails &); |
1010 bool operator==(const SymbolDetails &, const SymbolDetails &); | 1062 bool operator==(const SymbolDetails &, const SymbolDetails &); |
1011 | 1063 |
1012 /// The parameters of a Workspace Symbol Request. | 1064 /// The parameters of a Workspace Symbol Request. |
1013 struct WorkspaceSymbolParams { | 1065 struct WorkspaceSymbolParams { |
1014 /// A non-empty query string | 1066 /// A query string to filter symbols by. |
1067 /// Clients may send an empty string here to request all the symbols. | |
1015 std::string query; | 1068 std::string query; |
1016 }; | 1069 |
1017 bool fromJSON(const llvm::json::Value &, WorkspaceSymbolParams &); | 1070 /// Max results to return, overriding global default. 0 means no limit. |
1071 /// Clangd extension. | |
1072 llvm::Optional<int> limit; | |
1073 }; | |
1074 bool fromJSON(const llvm::json::Value &, WorkspaceSymbolParams &, | |
1075 llvm::json::Path); | |
1018 | 1076 |
1019 struct ApplyWorkspaceEditParams { | 1077 struct ApplyWorkspaceEditParams { |
1020 WorkspaceEdit edit; | 1078 WorkspaceEdit edit; |
1021 }; | 1079 }; |
1022 llvm::json::Value toJSON(const ApplyWorkspaceEditParams &); | 1080 llvm::json::Value toJSON(const ApplyWorkspaceEditParams &); |
1023 | 1081 |
1024 struct ApplyWorkspaceEditResponse { | 1082 struct ApplyWorkspaceEditResponse { |
1025 bool applied = true; | 1083 bool applied = true; |
1026 llvm::Optional<std::string> failureReason; | 1084 llvm::Optional<std::string> failureReason; |
1027 }; | 1085 }; |
1028 bool fromJSON(const llvm::json::Value &, ApplyWorkspaceEditResponse &); | 1086 bool fromJSON(const llvm::json::Value &, ApplyWorkspaceEditResponse &, |
1087 llvm::json::Path); | |
1029 | 1088 |
1030 struct TextDocumentPositionParams { | 1089 struct TextDocumentPositionParams { |
1031 /// The text document. | 1090 /// The text document. |
1032 TextDocumentIdentifier textDocument; | 1091 TextDocumentIdentifier textDocument; |
1033 | 1092 |
1034 /// The position inside the text document. | 1093 /// The position inside the text document. |
1035 Position position; | 1094 Position position; |
1036 }; | 1095 }; |
1037 bool fromJSON(const llvm::json::Value &, TextDocumentPositionParams &); | 1096 bool fromJSON(const llvm::json::Value &, TextDocumentPositionParams &, |
1097 llvm::json::Path); | |
1038 | 1098 |
1039 enum class CompletionTriggerKind { | 1099 enum class CompletionTriggerKind { |
1040 /// Completion was triggered by typing an identifier (24x7 code | 1100 /// Completion was triggered by typing an identifier (24x7 code |
1041 /// complete), manual invocation (e.g Ctrl+Space) or via API. | 1101 /// complete), manual invocation (e.g Ctrl+Space) or via API. |
1042 Invoked = 1, | 1102 Invoked = 1, |
1052 CompletionTriggerKind triggerKind = CompletionTriggerKind::Invoked; | 1112 CompletionTriggerKind triggerKind = CompletionTriggerKind::Invoked; |
1053 /// The trigger character (a single character) that has trigger code complete. | 1113 /// The trigger character (a single character) that has trigger code complete. |
1054 /// Is undefined if `triggerKind !== CompletionTriggerKind.TriggerCharacter` | 1114 /// Is undefined if `triggerKind !== CompletionTriggerKind.TriggerCharacter` |
1055 std::string triggerCharacter; | 1115 std::string triggerCharacter; |
1056 }; | 1116 }; |
1057 bool fromJSON(const llvm::json::Value &, CompletionContext &); | 1117 bool fromJSON(const llvm::json::Value &, CompletionContext &, llvm::json::Path); |
1058 | 1118 |
1059 struct CompletionParams : TextDocumentPositionParams { | 1119 struct CompletionParams : TextDocumentPositionParams { |
1060 CompletionContext context; | 1120 CompletionContext context; |
1061 }; | 1121 |
1062 bool fromJSON(const llvm::json::Value &, CompletionParams &); | 1122 /// Max results to return, overriding global default. 0 means no limit. |
1123 /// Clangd extension. | |
1124 llvm::Optional<int> limit; | |
1125 }; | |
1126 bool fromJSON(const llvm::json::Value &, CompletionParams &, llvm::json::Path); | |
1063 | 1127 |
1064 struct MarkupContent { | 1128 struct MarkupContent { |
1065 MarkupKind kind = MarkupKind::PlainText; | 1129 MarkupKind kind = MarkupKind::PlainText; |
1066 std::string value; | 1130 std::string value; |
1067 }; | 1131 }; |
1140 std::vector<TextEdit> additionalTextEdits; | 1204 std::vector<TextEdit> additionalTextEdits; |
1141 | 1205 |
1142 /// Indicates if this item is deprecated. | 1206 /// Indicates if this item is deprecated. |
1143 bool deprecated = false; | 1207 bool deprecated = false; |
1144 | 1208 |
1145 /// This is Clangd extension. | 1209 /// The score that clangd calculates to rank the returned completions. |
1146 /// The score that Clangd calculates to rank completion items. This score can | 1210 /// This excludes the fuzzy-match between `filterText` and the partial word. |
1147 /// be used to adjust the ranking on the client side. | 1211 /// This can be used to re-rank results as the user types, using client-side |
1148 /// NOTE: This excludes fuzzy matching score which is typically calculated on | 1212 /// fuzzy-matching (that score should be multiplied with this one). |
1149 /// the client side. | 1213 /// This is a clangd extension. |
1150 float score = 0.f; | 1214 float score = 0.f; |
1151 | 1215 |
1152 // TODO: Add custom commitCharacters for some of the completion items. For | 1216 // TODO: Add custom commitCharacters for some of the completion items. For |
1153 // example, it makes sense to use () only for the functions. | 1217 // example, it makes sense to use () only for the functions. |
1154 // TODO(krasimir): The following optional fields defined by the language | 1218 // TODO(krasimir): The following optional fields defined by the language |
1235 Position position; | 1299 Position position; |
1236 | 1300 |
1237 /// The new name of the symbol. | 1301 /// The new name of the symbol. |
1238 std::string newName; | 1302 std::string newName; |
1239 }; | 1303 }; |
1240 bool fromJSON(const llvm::json::Value &, RenameParams &); | 1304 bool fromJSON(const llvm::json::Value &, RenameParams &, llvm::json::Path); |
1241 | 1305 |
1242 enum class DocumentHighlightKind { Text = 1, Read = 2, Write = 3 }; | 1306 enum class DocumentHighlightKind { Text = 1, Read = 2, Write = 3 }; |
1243 | 1307 |
1244 /// A document highlight is a range inside a text document which deserves | 1308 /// A document highlight is a range inside a text document which deserves |
1245 /// special attention. Usually a document highlight is visualized by changing | 1309 /// special attention. Usually a document highlight is visualized by changing |
1266 }; | 1330 }; |
1267 llvm::json::Value toJSON(const DocumentHighlight &DH); | 1331 llvm::json::Value toJSON(const DocumentHighlight &DH); |
1268 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const DocumentHighlight &); | 1332 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const DocumentHighlight &); |
1269 | 1333 |
1270 enum class TypeHierarchyDirection { Children = 0, Parents = 1, Both = 2 }; | 1334 enum class TypeHierarchyDirection { Children = 0, Parents = 1, Both = 2 }; |
1271 bool fromJSON(const llvm::json::Value &E, TypeHierarchyDirection &Out); | 1335 bool fromJSON(const llvm::json::Value &E, TypeHierarchyDirection &Out, |
1336 llvm::json::Path); | |
1272 | 1337 |
1273 /// The type hierarchy params is an extension of the | 1338 /// The type hierarchy params is an extension of the |
1274 /// `TextDocumentPositionsParams` with optional properties which can be used to | 1339 /// `TextDocumentPositionsParams` with optional properties which can be used to |
1275 /// eagerly resolve the item when requesting from the server. | 1340 /// eagerly resolve the item when requesting from the server. |
1276 struct TypeHierarchyParams : public TextDocumentPositionParams { | 1341 struct TypeHierarchyParams : public TextDocumentPositionParams { |
1278 int resolve = 0; | 1343 int resolve = 0; |
1279 | 1344 |
1280 /// The direction of the hierarchy levels to resolve. | 1345 /// The direction of the hierarchy levels to resolve. |
1281 TypeHierarchyDirection direction = TypeHierarchyDirection::Parents; | 1346 TypeHierarchyDirection direction = TypeHierarchyDirection::Parents; |
1282 }; | 1347 }; |
1283 bool fromJSON(const llvm::json::Value &, TypeHierarchyParams &); | 1348 bool fromJSON(const llvm::json::Value &, TypeHierarchyParams &, |
1349 llvm::json::Path); | |
1284 | 1350 |
1285 struct TypeHierarchyItem { | 1351 struct TypeHierarchyItem { |
1286 /// The human readable name of the hierarchy item. | 1352 /// The human readable name of the hierarchy item. |
1287 std::string name; | 1353 std::string name; |
1288 | 1354 |
1318 /// If this type hierarchy item is resolved, it contains the direct children | 1384 /// If this type hierarchy item is resolved, it contains the direct children |
1319 /// of the current item. Could be empty if the item does not have any | 1385 /// of the current item. Could be empty if the item does not have any |
1320 /// descendants. If not defined, the children have not been resolved. | 1386 /// descendants. If not defined, the children have not been resolved. |
1321 llvm::Optional<std::vector<TypeHierarchyItem>> children; | 1387 llvm::Optional<std::vector<TypeHierarchyItem>> children; |
1322 | 1388 |
1323 /// An optional 'data' filed, which can be used to identify a type hierarchy | 1389 /// An optional 'data' field, which can be used to identify a type hierarchy |
1324 /// item in a resolve request. | 1390 /// item in a resolve request. |
1325 llvm::Optional<std::string> data; | 1391 llvm::Optional<std::string> data; |
1326 }; | 1392 }; |
1327 llvm::json::Value toJSON(const TypeHierarchyItem &); | 1393 llvm::json::Value toJSON(const TypeHierarchyItem &); |
1328 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const TypeHierarchyItem &); | 1394 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const TypeHierarchyItem &); |
1329 bool fromJSON(const llvm::json::Value &, TypeHierarchyItem &); | 1395 bool fromJSON(const llvm::json::Value &, TypeHierarchyItem &, llvm::json::Path); |
1330 | 1396 |
1331 /// Parameters for the `typeHierarchy/resolve` request. | 1397 /// Parameters for the `typeHierarchy/resolve` request. |
1332 struct ResolveTypeHierarchyItemParams { | 1398 struct ResolveTypeHierarchyItemParams { |
1333 /// The item to resolve. | 1399 /// The item to resolve. |
1334 TypeHierarchyItem item; | 1400 TypeHierarchyItem item; |
1337 int resolve; | 1403 int resolve; |
1338 | 1404 |
1339 /// The direction of the hierarchy levels to resolve. | 1405 /// The direction of the hierarchy levels to resolve. |
1340 TypeHierarchyDirection direction; | 1406 TypeHierarchyDirection direction; |
1341 }; | 1407 }; |
1342 bool fromJSON(const llvm::json::Value &, ResolveTypeHierarchyItemParams &); | 1408 bool fromJSON(const llvm::json::Value &, ResolveTypeHierarchyItemParams &, |
1409 llvm::json::Path); | |
1410 | |
1411 enum class SymbolTag { Deprecated = 1 }; | |
1412 llvm::json::Value toJSON(SymbolTag); | |
1413 | |
1414 /// The parameter of a `textDocument/prepareCallHierarchy` request. | |
1415 struct CallHierarchyPrepareParams : public TextDocumentPositionParams {}; | |
1416 | |
1417 /// Represents programming constructs like functions or constructors | |
1418 /// in the context of call hierarchy. | |
1419 struct CallHierarchyItem { | |
1420 /// The name of this item. | |
1421 std::string name; | |
1422 | |
1423 /// The kind of this item. | |
1424 SymbolKind kind; | |
1425 | |
1426 /// Tags for this item. | |
1427 std::vector<SymbolTag> tags; | |
1428 | |
1429 /// More detaill for this item, e.g. the signature of a function. | |
1430 std::string detail; | |
1431 | |
1432 /// The resource identifier of this item. | |
1433 URIForFile uri; | |
1434 | |
1435 /// The range enclosing this symbol not including leading / trailing | |
1436 /// whitespace but everything else, e.g. comments and code. | |
1437 Range range; | |
1438 | |
1439 /// The range that should be selected and revealed when this symbol | |
1440 /// is being picked, e.g. the name of a function. | |
1441 /// Must be contained by `Rng`. | |
1442 Range selectionRange; | |
1443 | |
1444 /// An optional 'data' field, which can be used to identify a call | |
1445 /// hierarchy item in an incomingCalls or outgoingCalls request. | |
1446 std::string data; | |
1447 }; | |
1448 llvm::json::Value toJSON(const CallHierarchyItem &); | |
1449 bool fromJSON(const llvm::json::Value &, CallHierarchyItem &, llvm::json::Path); | |
1450 | |
1451 /// The parameter of a `callHierarchy/incomingCalls` request. | |
1452 struct CallHierarchyIncomingCallsParams { | |
1453 CallHierarchyItem item; | |
1454 }; | |
1455 bool fromJSON(const llvm::json::Value &, CallHierarchyIncomingCallsParams &, | |
1456 llvm::json::Path); | |
1457 | |
1458 /// Represents an incoming call, e.g. a caller of a method or constructor. | |
1459 struct CallHierarchyIncomingCall { | |
1460 /// The item that makes the call. | |
1461 CallHierarchyItem from; | |
1462 | |
1463 /// The range at which the calls appear. | |
1464 /// This is relative to the caller denoted by `From`. | |
1465 std::vector<Range> fromRanges; | |
1466 }; | |
1467 llvm::json::Value toJSON(const CallHierarchyIncomingCall &); | |
1468 | |
1469 /// The parameter of a `callHierarchy/outgoingCalls` request. | |
1470 struct CallHierarchyOutgoingCallsParams { | |
1471 CallHierarchyItem item; | |
1472 }; | |
1473 bool fromJSON(const llvm::json::Value &, CallHierarchyOutgoingCallsParams &, | |
1474 llvm::json::Path); | |
1475 | |
1476 /// Represents an outgoing call, e.g. calling a getter from a method or | |
1477 /// a method from a constructor etc. | |
1478 struct CallHierarchyOutgoingCall { | |
1479 /// The item that is called. | |
1480 CallHierarchyItem to; | |
1481 | |
1482 /// The range at which this item is called. | |
1483 /// This is the range relative to the caller, and not `To`. | |
1484 std::vector<Range> fromRanges; | |
1485 }; | |
1486 llvm::json::Value toJSON(const CallHierarchyOutgoingCall &); | |
1487 | |
1488 /// The parameter of a `textDocument/inlayHints` request. | |
1489 struct InlayHintsParams { | |
1490 /// The text document for which inlay hints are requested. | |
1491 TextDocumentIdentifier textDocument; | |
1492 }; | |
1493 bool fromJSON(const llvm::json::Value &, InlayHintsParams &, llvm::json::Path); | |
1494 | |
1495 /// A set of predefined hint kinds. | |
1496 enum class InlayHintKind { | |
1497 /// The hint corresponds to parameter information. | |
1498 /// An example of a parameter hint is a hint in this position: | |
1499 /// func(^arg); | |
1500 /// which shows the name of the corresponding parameter. | |
1501 ParameterHint, | |
1502 | |
1503 /// The hint corresponds to information about a deduced type. | |
1504 /// An example of a type hint is a hint in this position: | |
1505 /// auto var ^ = expr; | |
1506 /// which shows the deduced type of the variable. | |
1507 TypeHint, | |
1508 | |
1509 /// Other ideas for hints that are not currently implemented: | |
1510 /// | |
1511 /// * Chaining hints, showing the types of intermediate expressions | |
1512 /// in a chain of function calls. | |
1513 /// * Hints indicating implicit conversions or implicit constructor calls. | |
1514 }; | |
1515 llvm::json::Value toJSON(InlayHintKind); | |
1516 | |
1517 /// An annotation to be displayed inline next to a range of source code. | |
1518 struct InlayHint { | |
1519 /// The range of source code to which the hint applies. | |
1520 /// We provide the entire range, rather than just the endpoint | |
1521 /// relevant to `position` (e.g. the start of the range for | |
1522 /// InlayHintPosition::Before), to give clients the flexibility | |
1523 /// to make choices like only displaying the hint while the cursor | |
1524 /// is over the range, rather than displaying it all the time. | |
1525 Range range; | |
1526 | |
1527 /// The type of hint. | |
1528 InlayHintKind kind; | |
1529 | |
1530 /// The label that is displayed in the editor. | |
1531 std::string label; | |
1532 }; | |
1533 llvm::json::Value toJSON(const InlayHint &); | |
1534 | |
1535 struct ReferenceContext { | |
1536 /// Include the declaration of the current symbol. | |
1537 bool includeDeclaration = false; | |
1538 }; | |
1343 | 1539 |
1344 struct ReferenceParams : public TextDocumentPositionParams { | 1540 struct ReferenceParams : public TextDocumentPositionParams { |
1345 // For now, no options like context.includeDeclaration are supported. | 1541 ReferenceContext context; |
1346 }; | 1542 }; |
1347 bool fromJSON(const llvm::json::Value &, ReferenceParams &); | 1543 bool fromJSON(const llvm::json::Value &, ReferenceParams &, llvm::json::Path); |
1348 | 1544 |
1349 /// Clangd extension: indicates the current state of the file in clangd, | 1545 /// Clangd extension: indicates the current state of the file in clangd, |
1350 /// sent from server via the `textDocument/clangd.fileStatus` notification. | 1546 /// sent from server via the `textDocument/clangd.fileStatus` notification. |
1351 struct FileStatus { | 1547 struct FileStatus { |
1352 /// The text document's URI. | 1548 /// The text document's URI. |
1382 // the client will include the result id in the next semantic token request. | 1578 // the client will include the result id in the next semantic token request. |
1383 // A server can then instead of computing all semantic tokens again simply | 1579 // A server can then instead of computing all semantic tokens again simply |
1384 // send a delta. | 1580 // send a delta. |
1385 std::string resultId; | 1581 std::string resultId; |
1386 | 1582 |
1387 /// The actual tokens. For a detailed description about how the data is | 1583 /// The actual tokens. |
1388 /// structured pls see | 1584 std::vector<SemanticToken> tokens; // encoded as a flat integer array. |
1389 /// https://github.com/microsoft/vscode-extension-samples/blob/5ae1f7787122812dcc84e37427ca90af5ee09f14/semantic-tokens-sample/vscode.proposed.d.ts#L71 | |
1390 std::vector<SemanticToken> tokens; | |
1391 }; | 1585 }; |
1392 llvm::json::Value toJSON(const SemanticTokens &); | 1586 llvm::json::Value toJSON(const SemanticTokens &); |
1393 | 1587 |
1588 /// Body of textDocument/semanticTokens/full request. | |
1394 struct SemanticTokensParams { | 1589 struct SemanticTokensParams { |
1395 /// The text document. | 1590 /// The text document. |
1396 TextDocumentIdentifier textDocument; | 1591 TextDocumentIdentifier textDocument; |
1397 }; | 1592 }; |
1398 bool fromJSON(const llvm::json::Value &, SemanticTokensParams &); | 1593 bool fromJSON(const llvm::json::Value &, SemanticTokensParams &, |
1399 | 1594 llvm::json::Path); |
1595 | |
1596 /// Body of textDocument/semanticTokens/full/delta request. | |
1400 /// Requests the changes in semantic tokens since a previous response. | 1597 /// Requests the changes in semantic tokens since a previous response. |
1401 struct SemanticTokensEditsParams { | 1598 struct SemanticTokensDeltaParams { |
1402 /// The text document. | 1599 /// The text document. |
1403 TextDocumentIdentifier textDocument; | 1600 TextDocumentIdentifier textDocument; |
1404 /// The previous result id. | 1601 /// The previous result id. |
1405 std::string previousResultId; | 1602 std::string previousResultId; |
1406 }; | 1603 }; |
1407 bool fromJSON(const llvm::json::Value &Params, SemanticTokensEditsParams &R); | 1604 bool fromJSON(const llvm::json::Value &Params, SemanticTokensDeltaParams &R, |
1605 llvm::json::Path); | |
1408 | 1606 |
1409 /// Describes a a replacement of a contiguous range of semanticTokens. | 1607 /// Describes a a replacement of a contiguous range of semanticTokens. |
1410 struct SemanticTokensEdit { | 1608 struct SemanticTokensEdit { |
1411 // LSP specifies `start` and `deleteCount` which are relative to the array | 1609 // LSP specifies `start` and `deleteCount` which are relative to the array |
1412 // encoding of the previous tokens. | 1610 // encoding of the previous tokens. |
1413 // We use token counts instead, and translate when serializing this struct. | 1611 // We use token counts instead, and translate when serializing this struct. |
1414 unsigned startToken = 0; | 1612 unsigned startToken = 0; |
1415 unsigned deleteTokens = 0; | 1613 unsigned deleteTokens = 0; |
1416 std::vector<SemanticToken> tokens; | 1614 std::vector<SemanticToken> tokens; // encoded as a flat integer array |
1417 }; | 1615 }; |
1418 llvm::json::Value toJSON(const SemanticTokensEdit &); | 1616 llvm::json::Value toJSON(const SemanticTokensEdit &); |
1419 | 1617 |
1420 /// This models LSP SemanticTokensEdits | SemanticTokens, which is the result of | 1618 /// This models LSP SemanticTokensDelta | SemanticTokens, which is the result of |
1421 /// textDocument/semanticTokens/edits. | 1619 /// textDocument/semanticTokens/full/delta. |
1422 struct SemanticTokensOrEdits { | 1620 struct SemanticTokensOrDelta { |
1423 std::string resultId; | 1621 std::string resultId; |
1424 /// Set if we computed edits relative to a previous set of tokens. | 1622 /// Set if we computed edits relative to a previous set of tokens. |
1425 llvm::Optional<std::vector<SemanticTokensEdit>> edits; | 1623 llvm::Optional<std::vector<SemanticTokensEdit>> edits; |
1426 /// Set if we computed a fresh set of tokens. | 1624 /// Set if we computed a fresh set of tokens. |
1427 llvm::Optional<std::vector<SemanticToken>> tokens; | 1625 llvm::Optional<std::vector<SemanticToken>> tokens; // encoded as integer array |
1428 }; | 1626 }; |
1429 llvm::json::Value toJSON(const SemanticTokensOrEdits &); | 1627 llvm::json::Value toJSON(const SemanticTokensOrDelta &); |
1430 | |
1431 /// Represents a semantic highlighting information that has to be applied on a | |
1432 /// specific line of the text document. | |
1433 struct TheiaSemanticHighlightingInformation { | |
1434 /// The line these highlightings belong to. | |
1435 int Line = 0; | |
1436 /// The base64 encoded string of highlighting tokens. | |
1437 std::string Tokens; | |
1438 /// Is the line in an inactive preprocessor branch? | |
1439 /// This is a clangd extension. | |
1440 /// An inactive line can still contain highlighting tokens as well; | |
1441 /// clients should combine line style and token style if possible. | |
1442 bool IsInactive = false; | |
1443 }; | |
1444 bool operator==(const TheiaSemanticHighlightingInformation &Lhs, | |
1445 const TheiaSemanticHighlightingInformation &Rhs); | |
1446 llvm::json::Value | |
1447 toJSON(const TheiaSemanticHighlightingInformation &Highlighting); | |
1448 | |
1449 /// Parameters for the semantic highlighting (server-side) push notification. | |
1450 struct TheiaSemanticHighlightingParams { | |
1451 /// The textdocument these highlightings belong to. | |
1452 VersionedTextDocumentIdentifier TextDocument; | |
1453 /// The lines of highlightings that should be sent. | |
1454 std::vector<TheiaSemanticHighlightingInformation> Lines; | |
1455 }; | |
1456 llvm::json::Value toJSON(const TheiaSemanticHighlightingParams &Highlighting); | |
1457 | 1628 |
1458 struct SelectionRangeParams { | 1629 struct SelectionRangeParams { |
1459 /// The text document. | 1630 /// The text document. |
1460 TextDocumentIdentifier textDocument; | 1631 TextDocumentIdentifier textDocument; |
1461 | 1632 |
1462 /// The positions inside the text document. | 1633 /// The positions inside the text document. |
1463 std::vector<Position> positions; | 1634 std::vector<Position> positions; |
1464 }; | 1635 }; |
1465 bool fromJSON(const llvm::json::Value &, SelectionRangeParams &); | 1636 bool fromJSON(const llvm::json::Value &, SelectionRangeParams &, |
1637 llvm::json::Path); | |
1466 | 1638 |
1467 struct SelectionRange { | 1639 struct SelectionRange { |
1468 /** | 1640 /** |
1469 * The range of this selection range. | 1641 * The range of this selection range. |
1470 */ | 1642 */ |
1480 /// Parameters for the document link request. | 1652 /// Parameters for the document link request. |
1481 struct DocumentLinkParams { | 1653 struct DocumentLinkParams { |
1482 /// The document to provide document links for. | 1654 /// The document to provide document links for. |
1483 TextDocumentIdentifier textDocument; | 1655 TextDocumentIdentifier textDocument; |
1484 }; | 1656 }; |
1485 bool fromJSON(const llvm::json::Value &, DocumentLinkParams &); | 1657 bool fromJSON(const llvm::json::Value &, DocumentLinkParams &, |
1658 llvm::json::Path); | |
1486 | 1659 |
1487 /// A range in a text document that links to an internal or external resource, | 1660 /// A range in a text document that links to an internal or external resource, |
1488 /// like another text document or a web site. | 1661 /// like another text document or a web site. |
1489 struct DocumentLink { | 1662 struct DocumentLink { |
1490 /// The range this link applies to. | 1663 /// The range this link applies to. |
1508 return !(LHS == RHS); | 1681 return !(LHS == RHS); |
1509 } | 1682 } |
1510 }; | 1683 }; |
1511 llvm::json::Value toJSON(const DocumentLink &DocumentLink); | 1684 llvm::json::Value toJSON(const DocumentLink &DocumentLink); |
1512 | 1685 |
1686 // FIXME(kirillbobyrev): Add FoldingRangeClientCapabilities so we can support | |
1687 // per-line-folding editors. | |
1688 struct FoldingRangeParams { | |
1689 TextDocumentIdentifier textDocument; | |
1690 }; | |
1691 bool fromJSON(const llvm::json::Value &, FoldingRangeParams &, | |
1692 llvm::json::Path); | |
1693 | |
1694 /// Stores information about a region of code that can be folded. | |
1695 struct FoldingRange { | |
1696 unsigned startLine = 0; | |
1697 unsigned startCharacter; | |
1698 unsigned endLine = 0; | |
1699 unsigned endCharacter; | |
1700 llvm::Optional<std::string> kind; | |
1701 }; | |
1702 llvm::json::Value toJSON(const FoldingRange &Range); | |
1703 | |
1704 /// Keys starting with an underscore(_) represent leaves, e.g. _total or _self | |
1705 /// for memory usage of whole subtree or only that specific node in bytes. All | |
1706 /// other keys represents children. An example: | |
1707 /// { | |
1708 /// "_self": 0, | |
1709 /// "_total": 8, | |
1710 /// "child1": { | |
1711 /// "_self": 4, | |
1712 /// "_total": 4, | |
1713 /// } | |
1714 /// "child2": { | |
1715 /// "_self": 2, | |
1716 /// "_total": 4, | |
1717 /// "child_deep": { | |
1718 /// "_self": 2, | |
1719 /// "_total": 2, | |
1720 /// } | |
1721 /// } | |
1722 /// } | |
1723 llvm::json::Value toJSON(const MemoryTree &MT); | |
1724 | |
1725 /// Payload for textDocument/ast request. | |
1726 /// This request is a clangd extension. | |
1727 struct ASTParams { | |
1728 /// The text document. | |
1729 TextDocumentIdentifier textDocument; | |
1730 | |
1731 /// The position of the node to be dumped. | |
1732 /// The highest-level node that entirely contains the range will be returned. | |
1733 /// If no range is given, the root translation unit node will be returned. | |
1734 llvm::Optional<Range> range; | |
1735 }; | |
1736 bool fromJSON(const llvm::json::Value &, ASTParams &, llvm::json::Path); | |
1737 | |
1738 /// Simplified description of a clang AST node. | |
1739 /// This is clangd's internal representation of C++ code. | |
1740 struct ASTNode { | |
1741 /// The general kind of node, such as "expression" | |
1742 /// Corresponds to the base AST node type such as Expr. | |
1743 std::string role; | |
1744 /// The specific kind of node this is, such as "BinaryOperator". | |
1745 /// This is usually a concrete node class (with Expr etc suffix dropped). | |
1746 /// When there's no hierarchy (e.g. TemplateName), the variant (NameKind). | |
1747 std::string kind; | |
1748 /// Brief additional information, such as "||" for the particular operator. | |
1749 /// The information included depends on the node kind, and may be empty. | |
1750 std::string detail; | |
1751 /// A one-line dump of detailed information about the node. | |
1752 /// This includes role/kind/description information, but is rather cryptic. | |
1753 /// It is similar to the output from `clang -Xclang -ast-dump`. | |
1754 /// May be empty for certain types of nodes. | |
1755 std::string arcana; | |
1756 /// The range of the original source file covered by this node. | |
1757 /// May be missing for implicit nodes, or those created by macro expansion. | |
1758 llvm::Optional<Range> range; | |
1759 /// Nodes nested within this one, such as the operands of a BinaryOperator. | |
1760 std::vector<ASTNode> children; | |
1761 }; | |
1762 llvm::json::Value toJSON(const ASTNode &); | |
1763 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const ASTNode &); | |
1764 | |
1513 } // namespace clangd | 1765 } // namespace clangd |
1514 } // namespace clang | 1766 } // namespace clang |
1515 | 1767 |
1516 namespace llvm { | 1768 namespace llvm { |
1517 template <> struct format_provider<clang::clangd::Position> { | 1769 template <> struct format_provider<clang::clangd::Position> { |