clang-tools  7.0.0
Protocol.h
Go to the documentation of this file.
1 //===--- Protocol.h - Language Server Protocol Implementation ---*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains structs based on the LSP specification at
11 // https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md
12 //
13 // This is not meant to be a complete implementation, new interfaces are added
14 // when they're needed.
15 //
16 // Each struct has a toJSON and fromJSON function, that converts between
17 // the struct and a JSON representation. (See JSON.h)
18 //
19 // Some structs also have operator<< serialization. This is for debugging and
20 // tests, and is not generally machine-readable.
21 //
22 //===----------------------------------------------------------------------===//
23 
24 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROTOCOL_H
25 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROTOCOL_H
26 
27 #include "URI.h"
28 #include "llvm/ADT/Optional.h"
29 #include "llvm/Support/JSON.h"
30 #include <bitset>
31 #include <string>
32 #include <vector>
33 
34 namespace clang {
35 namespace clangd {
36 
37 enum class ErrorCode {
38  // Defined by JSON RPC.
39  ParseError = -32700,
40  InvalidRequest = -32600,
41  MethodNotFound = -32601,
42  InvalidParams = -32602,
43  InternalError = -32603,
44 
45  ServerNotInitialized = -32002,
46  UnknownErrorCode = -32001,
47 
48  // Defined by the protocol.
49  RequestCancelled = -32800,
50 };
51 
52 struct URIForFile {
53  URIForFile() = default;
54  explicit URIForFile(std::string AbsPath);
55 
56  /// Retrieves absolute path to the file.
57  llvm::StringRef file() const { return File; }
58 
59  explicit operator bool() const { return !File.empty(); }
60  std::string uri() const { return URI::createFile(File).toString(); }
61 
62  friend bool operator==(const URIForFile &LHS, const URIForFile &RHS) {
63  return LHS.File == RHS.File;
64  }
65 
66  friend bool operator!=(const URIForFile &LHS, const URIForFile &RHS) {
67  return !(LHS == RHS);
68  }
69 
70  friend bool operator<(const URIForFile &LHS, const URIForFile &RHS) {
71  return LHS.File < RHS.File;
72  }
73 
74 private:
75  std::string File;
76 };
77 
78 /// Serialize/deserialize \p URIForFile to/from a string URI.
79 llvm::json::Value toJSON(const URIForFile &U);
80 bool fromJSON(const llvm::json::Value &, URIForFile &);
81 
83  /// The text document's URI.
85 };
86 llvm::json::Value toJSON(const TextDocumentIdentifier &);
87 bool fromJSON(const llvm::json::Value &, TextDocumentIdentifier &);
88 
89 struct Position {
90  /// Line position in a document (zero-based).
91  int line = 0;
92 
93  /// Character offset on a line in a document (zero-based).
94  /// WARNING: this is in UTF-16 codepoints, not bytes or characters!
95  /// Use the functions in SourceCode.h to construct/interpret Positions.
96  int character = 0;
97 
98  friend bool operator==(const Position &LHS, const Position &RHS) {
99  return std::tie(LHS.line, LHS.character) ==
100  std::tie(RHS.line, RHS.character);
101  }
102  friend bool operator!=(const Position &LHS, const Position &RHS) {
103  return !(LHS == RHS);
104  }
105  friend bool operator<(const Position &LHS, const Position &RHS) {
106  return std::tie(LHS.line, LHS.character) <
107  std::tie(RHS.line, RHS.character);
108  }
109  friend bool operator<=(const Position &LHS, const Position &RHS) {
110  return std::tie(LHS.line, LHS.character) <=
111  std::tie(RHS.line, RHS.character);
112  }
113 };
114 bool fromJSON(const llvm::json::Value &, Position &);
115 llvm::json::Value toJSON(const Position &);
116 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Position &);
117 
118 struct Range {
119  /// The range's start position.
121 
122  /// The range's end position.
124 
125  friend bool operator==(const Range &LHS, const Range &RHS) {
126  return std::tie(LHS.start, LHS.end) == std::tie(RHS.start, RHS.end);
127  }
128  friend bool operator!=(const Range &LHS, const Range &RHS) {
129  return !(LHS == RHS);
130  }
131  friend bool operator<(const Range &LHS, const Range &RHS) {
132  return std::tie(LHS.start, LHS.end) < std::tie(RHS.start, RHS.end);
133  }
134 
135  bool contains(Position Pos) const { return start <= Pos && Pos < end; }
136 };
137 bool fromJSON(const llvm::json::Value &, Range &);
138 llvm::json::Value toJSON(const Range &);
139 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Range &);
140 
141 struct Location {
142  /// The text document's URI.
145 
146  friend bool operator==(const Location &LHS, const Location &RHS) {
147  return LHS.uri == RHS.uri && LHS.range == RHS.range;
148  }
149 
150  friend bool operator!=(const Location &LHS, const Location &RHS) {
151  return !(LHS == RHS);
152  }
153 
154  friend bool operator<(const Location &LHS, const Location &RHS) {
155  return std::tie(LHS.uri, LHS.range) < std::tie(RHS.uri, RHS.range);
156  }
157 };
158 llvm::json::Value toJSON(const Location &);
159 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Location &);
160 
161 struct Metadata {
162  std::vector<std::string> extraFlags;
163 };
164 bool fromJSON(const llvm::json::Value &, Metadata &);
165 
166 struct TextEdit {
167  /// The range of the text document to be manipulated. To insert
168  /// text into a document create a range where start === end.
170 
171  /// The string to be inserted. For delete operations use an
172  /// empty string.
173  std::string newText;
174 };
175 bool fromJSON(const llvm::json::Value &, TextEdit &);
176 llvm::json::Value toJSON(const TextEdit &);
177 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const TextEdit &);
178 
180  /// The text document's URI.
182 
183  /// The text document's language identifier.
184  std::string languageId;
185 
186  /// The version number of this document (it will strictly increase after each
187  int version = 0;
188 
189  /// The content of the opened text document.
190  std::string text;
191 };
192 bool fromJSON(const llvm::json::Value &, TextDocumentItem &);
193 
194 enum class TraceLevel {
195  Off = 0,
196  Messages = 1,
197  Verbose = 2,
198 };
199 bool fromJSON(const llvm::json::Value &E, TraceLevel &Out);
200 
201 struct NoParams {};
202 inline bool fromJSON(const llvm::json::Value &, NoParams &) { return true; }
205 
206 /// Defines how the host (editor) should sync document changes to the language
207 /// server.
209  /// Documents should not be synced at all.
210  None = 0,
211 
212  /// Documents are synced by always sending the full content of the document.
213  Full = 1,
214 
215  /// Documents are synced by sending the full content on open. After that
216  /// only incremental updates to the document are send.
217  Incremental = 2,
218 };
219 
221  /// Client supports snippets as insert text.
222  bool snippetSupport = false;
223  /// Client supports commit characters on a completion item.
224  bool commitCharacterSupport = false;
225  // Client supports the follow content formats for the documentation property.
226  // The order describes the preferred format of the client.
227  // NOTE: not used by clangd at the moment.
228  // std::vector<MarkupKind> documentationFormat;
229 };
230 bool fromJSON(const llvm::json::Value &, CompletionItemClientCapabilities &);
231 
233  /// Whether completion supports dynamic registration.
234  bool dynamicRegistration = false;
235  /// The client supports the following `CompletionItem` specific capabilities.
237  // NOTE: not used by clangd at the moment.
238  // llvm::Optional<CompletionItemKindCapabilities> completionItemKind;
239 
240  /// The client supports to send additional context information for a
241  /// `textDocument/completion` request.
242  bool contextSupport = false;
243 };
244 bool fromJSON(const llvm::json::Value &, CompletionClientCapabilities &);
245 
246 /// A symbol kind.
247 enum class SymbolKind {
248  File = 1,
249  Module = 2,
250  Namespace = 3,
251  Package = 4,
252  Class = 5,
253  Method = 6,
254  Property = 7,
255  Field = 8,
256  Constructor = 9,
257  Enum = 10,
258  Interface = 11,
259  Function = 12,
260  Variable = 13,
261  Constant = 14,
262  String = 15,
263  Number = 16,
264  Boolean = 17,
265  Array = 18,
266  Object = 19,
267  Key = 20,
268  Null = 21,
269  EnumMember = 22,
270  Struct = 23,
271  Event = 24,
272  Operator = 25,
273  TypeParameter = 26
274 };
275 
276 constexpr auto SymbolKindMin = static_cast<size_t>(SymbolKind::File);
277 constexpr auto SymbolKindMax = static_cast<size_t>(SymbolKind::TypeParameter);
278 using SymbolKindBitset = std::bitset<SymbolKindMax + 1>;
279 
280 bool fromJSON(const llvm::json::Value &, SymbolKind &);
281 
283  /// The SymbolKinds that the client supports. If not set, the client only
284  /// supports <= SymbolKind::Array and will not fall back to a valid default
285  /// value.
286  llvm::Optional<std::vector<SymbolKind>> valueSet;
287 };
288 bool fromJSON(const llvm::json::Value &, std::vector<SymbolKind> &);
289 bool fromJSON(const llvm::json::Value &, SymbolKindCapabilities &);
291  SymbolKindBitset &supportedSymbolKinds);
292 
294  /// Capabilities SymbolKind.
295  llvm::Optional<SymbolKindCapabilities> symbolKind;
296 };
297 bool fromJSON(const llvm::json::Value &, WorkspaceSymbolCapabilities &);
298 
299 // FIXME: most of the capabilities are missing from this struct. Only the ones
300 // used by clangd are currently there.
302  /// Capabilities specific to `workspace/symbol`.
303  llvm::Optional<WorkspaceSymbolCapabilities> symbol;
304 };
305 bool fromJSON(const llvm::json::Value &, WorkspaceClientCapabilities &);
306 
307 // FIXME: most of the capabilities are missing from this struct. Only the ones
308 // used by clangd are currently there.
310  /// Capabilities specific to the `textDocument/completion`
312 };
313 bool fromJSON(const llvm::json::Value &, TextDocumentClientCapabilities &);
314 
316  // Workspace specific client capabilities.
317  llvm::Optional<WorkspaceClientCapabilities> workspace;
318 
319  // Text document specific client capabilities.
321 };
322 
323 bool fromJSON(const llvm::json::Value &, ClientCapabilities &);
324 
325 /// Clangd extension to set clangd-specific "initializationOptions" in the
326 /// "initialize" request and for the "workspace/didChangeConfiguration"
327 /// notification since the data received is described as 'any' type in LSP.
329  llvm::Optional<std::string> compilationDatabasePath;
330 };
331 bool fromJSON(const llvm::json::Value &, ClangdConfigurationParamsChange &);
332 
334 
336  /// The process Id of the parent process that started
337  /// the server. Is null if the process has not been started by another
338  /// process. If the parent process is not alive then the server should exit
339  /// (see exit notification) its process.
340  llvm::Optional<int> processId;
341 
342  /// The rootPath of the workspace. Is null
343  /// if no folder is open.
344  ///
345  /// @deprecated in favour of rootUri.
346  llvm::Optional<std::string> rootPath;
347 
348  /// The rootUri of the workspace. Is null if no
349  /// folder is open. If both `rootPath` and `rootUri` are set
350  /// `rootUri` wins.
351  llvm::Optional<URIForFile> rootUri;
352 
353  // User provided initialization options.
354  // initializationOptions?: any;
355 
356  /// The capabilities provided by the client (editor or tool)
358 
359  /// The initial trace setting. If omitted trace is disabled ('off').
360  llvm::Optional<TraceLevel> trace;
361 
362  // We use this predefined struct because it is easier to use
363  // than the protocol specified type of 'any'.
364  llvm::Optional<ClangdInitializationOptions> initializationOptions;
365 };
366 bool fromJSON(const llvm::json::Value &, InitializeParams &);
367 
369  /// The document that was opened.
371 
372  /// Extension storing per-file metadata, such as compilation flags.
373  llvm::Optional<Metadata> metadata;
374 };
375 bool fromJSON(const llvm::json::Value &, DidOpenTextDocumentParams &);
376 
378  /// The document that was closed.
380 };
381 bool fromJSON(const llvm::json::Value &, DidCloseTextDocumentParams &);
382 
384  /// The range of the document that changed.
385  llvm::Optional<Range> range;
386 
387  /// The length of the range that got replaced.
388  llvm::Optional<int> rangeLength;
389 
390  /// The new text of the range/document.
391  std::string text;
392 };
393 bool fromJSON(const llvm::json::Value &, TextDocumentContentChangeEvent &);
394 
396  /// The document that did change. The version number points
397  /// to the version after all provided content changes have
398  /// been applied.
400 
401  /// The actual content changes.
402  std::vector<TextDocumentContentChangeEvent> contentChanges;
403 
404  /// Forces diagnostics to be generated, or to not be generated, for this
405  /// version of the file. If not set, diagnostics are eventually consistent:
406  /// either they will be provided for this version or some subsequent one.
407  /// This is a clangd extension.
408  llvm::Optional<bool> wantDiagnostics;
409 };
410 bool fromJSON(const llvm::json::Value &, DidChangeTextDocumentParams &);
411 
412 enum class FileChangeType {
413  /// The file got created.
414  Created = 1,
415  /// The file got changed.
416  Changed = 2,
417  /// The file got deleted.
418  Deleted = 3
419 };
420 bool fromJSON(const llvm::json::Value &E, FileChangeType &Out);
421 
422 struct FileEvent {
423  /// The file's URI.
425  /// The change type.
427 };
428 bool fromJSON(const llvm::json::Value &, FileEvent &);
429 
431  /// The actual file events.
432  std::vector<FileEvent> changes;
433 };
434 bool fromJSON(const llvm::json::Value &, DidChangeWatchedFilesParams &);
435 
437  // We use this predefined struct because it is easier to use
438  // than the protocol specified type of 'any'.
440 };
441 bool fromJSON(const llvm::json::Value &, DidChangeConfigurationParams &);
442 
444  /// Size of a tab in spaces.
445  int tabSize = 0;
446 
447  /// Prefer spaces over tabs.
448  bool insertSpaces = false;
449 };
450 bool fromJSON(const llvm::json::Value &, FormattingOptions &);
451 llvm::json::Value toJSON(const FormattingOptions &);
452 
454  /// The document to format.
456 
457  /// The range to format
459 
460  /// The format options
462 };
463 bool fromJSON(const llvm::json::Value &, DocumentRangeFormattingParams &);
464 
466  /// The document to format.
468 
469  /// The position at which this request was sent.
471 
472  /// The character that has been typed.
473  std::string ch;
474 
475  /// The format options.
477 };
478 bool fromJSON(const llvm::json::Value &, DocumentOnTypeFormattingParams &);
479 
481  /// The document to format.
483 
484  /// The format options
486 };
487 bool fromJSON(const llvm::json::Value &, DocumentFormattingParams &);
488 
490  // The text document to find symbols in.
492 };
493 bool fromJSON(const llvm::json::Value &, DocumentSymbolParams &);
494 
495 struct Diagnostic {
496  /// The range at which the message applies.
498 
499  /// The diagnostic's severity. Can be omitted. If omitted it is up to the
500  /// client to interpret diagnostics as error, warning, info or hint.
501  int severity = 0;
502 
503  /// The diagnostic's code. Can be omitted.
504  /// Note: Not currently used by clangd
505  // std::string code;
506 
507  /// A human-readable string describing the source of this
508  /// diagnostic, e.g. 'typescript' or 'super lint'.
509  /// Note: Not currently used by clangd
510  // std::string source;
511 
512  /// The diagnostic's message.
513  std::string message;
514 };
515 
516 /// A LSP-specific comparator used to find diagnostic in a container like
517 /// std:map.
518 /// We only use the required fields of Diagnostic to do the comparsion to avoid
519 /// any regression issues from LSP clients (e.g. VScode), see
520 /// https://git.io/vbr29
522  bool operator()(const Diagnostic &LHS, const Diagnostic &RHS) const {
523  return std::tie(LHS.range, LHS.message) < std::tie(RHS.range, RHS.message);
524  }
525 };
526 bool fromJSON(const llvm::json::Value &, Diagnostic &);
527 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Diagnostic &);
528 
530  /// An array of diagnostics.
531  std::vector<Diagnostic> diagnostics;
532 };
533 bool fromJSON(const llvm::json::Value &, CodeActionContext &);
534 
536  /// The document in which the command was invoked.
538 
539  /// The range for which the command was invoked.
541 
542  /// Context carrying additional information.
544 };
545 bool fromJSON(const llvm::json::Value &, CodeActionParams &);
546 
548  /// Holds changes to existing resources.
549  llvm::Optional<std::map<std::string, std::vector<TextEdit>>> changes;
550 
551  /// Note: "documentChanges" is not currently used because currently there is
552  /// no support for versioned edits.
553 };
554 bool fromJSON(const llvm::json::Value &, WorkspaceEdit &);
555 llvm::json::Value toJSON(const WorkspaceEdit &WE);
556 
557 /// Exact commands are not specified in the protocol so we define the
558 /// ones supported by Clangd here. The protocol specifies the command arguments
559 /// to be "any[]" but to make this safer and more manageable, each command we
560 /// handle maps to a certain llvm::Optional of some struct to contain its
561 /// arguments. Different commands could reuse the same llvm::Optional as
562 /// arguments but a command that needs different arguments would simply add a
563 /// new llvm::Optional and not use any other ones. In practice this means only
564 /// one argument type will be parsed and set.
566  // Command to apply fix-its. Uses WorkspaceEdit as argument.
567  const static llvm::StringLiteral CLANGD_APPLY_FIX_COMMAND;
568 
569  /// The command identifier, e.g. CLANGD_APPLY_FIX_COMMAND
570  std::string command;
571 
572  // Arguments
573  llvm::Optional<WorkspaceEdit> workspaceEdit;
574 };
575 bool fromJSON(const llvm::json::Value &, ExecuteCommandParams &);
576 
577 struct Command : public ExecuteCommandParams {
578  std::string title;
579 };
580 
581 llvm::json::Value toJSON(const Command &C);
582 
583 /// Represents information about programming constructs like variables, classes,
584 /// interfaces etc.
586  /// The name of this symbol.
587  std::string name;
588 
589  /// The kind of this symbol.
591 
592  /// The location of this symbol.
594 
595  /// The name of the symbol containing this symbol.
596  std::string containerName;
597 };
598 llvm::json::Value toJSON(const SymbolInformation &);
599 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SymbolInformation &);
600 
601 /// The parameters of a Workspace Symbol Request.
603  /// A non-empty query string
604  std::string query;
605 };
606 bool fromJSON(const llvm::json::Value &, WorkspaceSymbolParams &);
607 
610 };
611 llvm::json::Value toJSON(const ApplyWorkspaceEditParams &);
612 
614  /// The text document.
616 
617  /// The position inside the text document.
619 };
620 bool fromJSON(const llvm::json::Value &, TextDocumentPositionParams &);
621 
622 enum class MarkupKind {
623  PlainText,
624  Markdown,
625 };
626 
629  std::string value;
630 };
631 llvm::json::Value toJSON(const MarkupContent &MC);
632 
633 struct Hover {
634  /// The hover's content
636 
637  /// An optional range is a range inside a text document
638  /// that is used to visualize a hover, e.g. by changing the background color.
639  llvm::Optional<Range> range;
640 };
641 llvm::json::Value toJSON(const Hover &H);
642 
643 /// The kind of a completion entry.
644 enum class CompletionItemKind {
645  Missing = 0,
646  Text = 1,
647  Method = 2,
648  Function = 3,
649  Constructor = 4,
650  Field = 5,
651  Variable = 6,
652  Class = 7,
653  Interface = 8,
654  Module = 9,
655  Property = 10,
656  Unit = 11,
657  Value = 12,
658  Enum = 13,
659  Keyword = 14,
660  Snippet = 15,
661  Color = 16,
662  File = 17,
663  Reference = 18,
664 };
665 
666 /// Defines whether the insert text in a completion item should be interpreted
667 /// as plain text or a snippet.
668 enum class InsertTextFormat {
669  Missing = 0,
670  /// The primary text to be inserted is treated as a plain string.
671  PlainText = 1,
672  /// The primary text to be inserted is treated as a snippet.
673  ///
674  /// A snippet can define tab stops and placeholders with `$1`, `$2`
675  /// and `${3:foo}`. `$0` defines the final tab stop, it defaults to the end
676  /// of the snippet. Placeholders with equal identifiers are linked, that is
677  /// typing in one will update others too.
678  ///
679  /// See also:
680  /// https//github.com/Microsoft/vscode/blob/master/src/vs/editor/contrib/snippet/common/snippet.md
681  Snippet = 2,
682 };
683 
685  /// The label of this completion item. By default also the text that is
686  /// inserted when selecting this completion.
687  std::string label;
688 
689  /// The kind of this completion item. Based of the kind an icon is chosen by
690  /// the editor.
692 
693  /// A human-readable string with additional information about this item, like
694  /// type or symbol information.
695  std::string detail;
696 
697  /// A human-readable string that represents a doc-comment.
698  std::string documentation;
699 
700  /// A string that should be used when comparing this item with other items.
701  /// When `falsy` the label is used.
702  std::string sortText;
703 
704  /// A string that should be used when filtering a set of completion items.
705  /// When `falsy` the label is used.
706  std::string filterText;
707 
708  /// A string that should be inserted to a document when selecting this
709  /// completion. When `falsy` the label is used.
710  std::string insertText;
711 
712  /// The format of the insert text. The format applies to both the `insertText`
713  /// property and the `newText` property of a provided `textEdit`.
715 
716  /// An edit which is applied to a document when selecting this completion.
717  /// When an edit is provided `insertText` is ignored.
718  ///
719  /// Note: The range of the edit must be a single line range and it must
720  /// contain the position at which completion has been requested.
721  llvm::Optional<TextEdit> textEdit;
722 
723  /// An optional array of additional text edits that are applied when selecting
724  /// this completion. Edits must not overlap with the main edit nor with
725  /// themselves.
726  std::vector<TextEdit> additionalTextEdits;
727 
728  // TODO(krasimir): The following optional fields defined by the language
729  // server protocol are unsupported:
730  //
731  // data?: any - A data entry field that is preserved on a completion item
732  // between a completion and a completion resolve request.
733 };
734 llvm::json::Value toJSON(const CompletionItem &);
735 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const CompletionItem &);
736 
737 bool operator<(const CompletionItem &, const CompletionItem &);
738 
739 /// Represents a collection of completion items to be presented in the editor.
741  /// The list is not complete. Further typing should result in recomputing the
742  /// list.
743  bool isIncomplete = false;
744 
745  /// The completion items.
746  std::vector<CompletionItem> items;
747 };
748 llvm::json::Value toJSON(const CompletionList &);
749 
750 /// A single parameter of a particular signature.
752 
753  /// The label of this parameter. Mandatory.
754  std::string label;
755 
756  /// The documentation of this parameter. Optional.
757  std::string documentation;
758 };
759 llvm::json::Value toJSON(const ParameterInformation &);
760 
761 /// Represents the signature of something callable.
763 
764  /// The label of this signature. Mandatory.
765  std::string label;
766 
767  /// The documentation of this signature. Optional.
768  std::string documentation;
769 
770  /// The parameters of this signature.
771  std::vector<ParameterInformation> parameters;
772 };
773 llvm::json::Value toJSON(const SignatureInformation &);
774 llvm::raw_ostream &operator<<(llvm::raw_ostream &,
775  const SignatureInformation &);
776 
777 /// Represents the signature of a callable.
779 
780  /// The resulting signatures.
781  std::vector<SignatureInformation> signatures;
782 
783  /// The active signature.
784  int activeSignature = 0;
785 
786  /// The active parameter of the active signature.
787  int activeParameter = 0;
788 };
789 llvm::json::Value toJSON(const SignatureHelp &);
790 
791 struct RenameParams {
792  /// The document that was opened.
794 
795  /// The position at which this request was sent.
797 
798  /// The new name of the symbol.
799  std::string newName;
800 };
801 bool fromJSON(const llvm::json::Value &, RenameParams &);
802 
803 enum class DocumentHighlightKind { Text = 1, Read = 2, Write = 3 };
804 
805 /// A document highlight is a range inside a text document which deserves
806 /// special attention. Usually a document highlight is visualized by changing
807 /// the background color of its range.
808 
810  /// The range this highlight applies to.
812 
813  /// The highlight kind, default is DocumentHighlightKind.Text.
815 
816  friend bool operator<(const DocumentHighlight &LHS,
817  const DocumentHighlight &RHS) {
818  int LHSKind = static_cast<int>(LHS.kind);
819  int RHSKind = static_cast<int>(RHS.kind);
820  return std::tie(LHS.range, LHSKind) < std::tie(RHS.range, RHSKind);
821  }
822 
823  friend bool operator==(const DocumentHighlight &LHS,
824  const DocumentHighlight &RHS) {
825  return LHS.kind == RHS.kind && LHS.range == RHS.range;
826  }
827 };
828 llvm::json::Value toJSON(const DocumentHighlight &DH);
829 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const DocumentHighlight &);
830 
831 } // namespace clangd
832 } // namespace clang
833 
834 namespace llvm {
835 template <> struct format_provider<clang::clangd::Position> {
836  static void format(const clang::clangd::Position &Pos, raw_ostream &OS,
837  StringRef Style) {
838  assert(Style.empty() && "style modifiers for this type are not supported");
839  OS << Pos;
840  }
841 };
842 } // namespace llvm
843 
844 #endif
std::string insertText
A string that should be inserted to a document when selecting this completion.
Definition: Protocol.h:710
Range range
The range to format.
Definition: Protocol.h:458
friend bool operator<(const Location &LHS, const Location &RHS)
Definition: Protocol.h:154
TextDocumentIdentifier textDocument
The document to format.
Definition: Protocol.h:482
URIForFile uri
The file&#39;s URI.
Definition: Protocol.h:424
CompletionClientCapabilities completion
Capabilities specific to the textDocument/completion
Definition: Protocol.h:311
Location location
The location of this symbol.
Definition: Protocol.h:593
friend bool operator==(const Location &LHS, const Location &RHS)
Definition: Protocol.h:146
llvm::Optional< TextEdit > textEdit
An edit which is applied to a document when selecting this completion.
Definition: Protocol.h:721
Exact commands are not specified in the protocol so we define the ones supported by Clangd here...
Definition: Protocol.h:565
TextDocumentIdentifier textDocument
The document to format.
Definition: Protocol.h:467
Some operations such as code completion produce a set of candidates.
llvm::Optional< URIForFile > rootUri
The rootUri of the workspace.
Definition: Protocol.h:351
Position start
The range&#39;s start position.
Definition: Protocol.h:120
llvm::Optional< SymbolKindCapabilities > symbolKind
Capabilities SymbolKind.
Definition: Protocol.h:295
friend bool operator==(const URIForFile &LHS, const URIForFile &RHS)
Definition: Protocol.h:62
Represents a collection of completion items to be presented in the editor.
Definition: Protocol.h:740
Range range
The range this highlight applies to.
Definition: Protocol.h:811
std::string label
The label of this parameter. Mandatory.
Definition: Protocol.h:754
llvm::Optional< bool > wantDiagnostics
Forces diagnostics to be generated, or to not be generated, for this version of the file...
Definition: Protocol.h:408
friend bool operator<=(const Position &LHS, const Position &RHS)
Definition: Protocol.h:109
Range range
The range for which the command was invoked.
Definition: Protocol.h:540
CodeActionContext context
Context carrying additional information.
Definition: Protocol.h:543
static const llvm::StringLiteral CLANGD_APPLY_FIX_COMMAND
Definition: Protocol.h:567
Clangd extension to set clangd-specific "initializationOptions" in the "initialize" request and for t...
Definition: Protocol.h:328
std::string ch
The character that has been typed.
Definition: Protocol.h:473
llvm::Optional< WorkspaceSymbolCapabilities > symbol
Capabilities specific to workspace/symbol.
Definition: Protocol.h:303
std::vector< CompletionItem > items
The completion items.
Definition: Protocol.h:746
Documents are synced by always sending the full content of the document.
std::vector< std::string > extraFlags
Definition: Protocol.h:162
Documents are synced by sending the full content on open.
llvm::Optional< std::map< std::string, std::vector< TextEdit > > > changes
Holds changes to existing resources.
Definition: Protocol.h:549
bool operator()(const Diagnostic &LHS, const Diagnostic &RHS) const
Definition: Protocol.h:522
llvm::Optional< Range > range
An optional range is a range inside a text document that is used to visualize a hover, e.g.
Definition: Protocol.h:639
TextDocumentIdentifier textDocument
The document that was closed.
Definition: Protocol.h:379
llvm::Optional< ClangdInitializationOptions > initializationOptions
Definition: Protocol.h:364
std::string label
The label of this signature. Mandatory.
Definition: Protocol.h:765
friend bool operator!=(const URIForFile &LHS, const URIForFile &RHS)
Definition: Protocol.h:66
URIForFile uri
The text document&#39;s URI.
Definition: Protocol.h:143
std::string text
The new text of the range/document.
Definition: Protocol.h:391
friend bool operator!=(const Position &LHS, const Position &RHS)
Definition: Protocol.h:102
llvm::Optional< WorkspaceClientCapabilities > workspace
Definition: Protocol.h:317
Values in a Context are indexed by typed keys.
Definition: Context.h:41
constexpr auto SymbolKindMin
Definition: Protocol.h:276
std::string sortText
A string that should be used when comparing this item with other items.
Definition: Protocol.h:702
std::string title
Definition: Protocol.h:578
friend bool operator!=(const Range &LHS, const Range &RHS)
Definition: Protocol.h:128
std::vector< ParameterInformation > parameters
The parameters of this signature.
Definition: Protocol.h:771
Documents should not be synced at all.
llvm::Optional< Metadata > metadata
Extension storing per-file metadata, such as compilation flags.
Definition: Protocol.h:373
std::string documentation
A human-readable string that represents a doc-comment.
Definition: Protocol.h:698
InsertTextFormat
Defines whether the insert text in a completion item should be interpreted as plain text or a snippet...
Definition: Protocol.h:668
FormattingOptions options
The format options.
Definition: Protocol.h:476
std::vector< TextEdit > additionalTextEdits
An optional array of additional text edits that are applied when selecting this completion.
Definition: Protocol.h:726
llvm::Optional< int > processId
The process Id of the parent process that started the server.
Definition: Protocol.h:340
CompletionItemKind
The kind of a completion entry.
Definition: Protocol.h:644
std::string uri() const
Definition: Protocol.h:60
BindArgumentKind Kind
TextDocumentSyncKind
Defines how the host (editor) should sync document changes to the language server.
Definition: Protocol.h:208
MarkupContent contents
The hover&#39;s content.
Definition: Protocol.h:635
A document highlight is a range inside a text document which deserves special attention.
Definition: Protocol.h:809
TextDocumentClientCapabilities textDocument
Definition: Protocol.h:320
URIForFile uri
The text document&#39;s URI.
Definition: Protocol.h:181
std::string detail
A human-readable string with additional information about this item, like type or symbol information...
Definition: Protocol.h:695
static URI createFile(llvm::StringRef AbsolutePath)
This creates a file:// URI for AbsolutePath. The path must be absolute.
Definition: URI.cpp:184
TextDocumentIdentifier textDocument
The document that was opened.
Definition: Protocol.h:793
std::string newText
The string to be inserted.
Definition: Protocol.h:173
std::string newName
The new name of the symbol.
Definition: Protocol.h:799
Represents the signature of something callable.
Definition: Protocol.h:762
std::string command
The command identifier, e.g. CLANGD_APPLY_FIX_COMMAND.
Definition: Protocol.h:570
TextDocumentIdentifier textDocument
Definition: Protocol.h:491
std::string filterText
A string that should be used when filtering a set of completion items.
Definition: Protocol.h:706
friend bool operator<(const Position &LHS, const Position &RHS)
Definition: Protocol.h:105
TextDocumentIdentifier textDocument
The document in which the command was invoked.
Definition: Protocol.h:537
Range range
The range of the text document to be manipulated.
Definition: Protocol.h:169
CompletionItemClientCapabilities completionItem
The client supports the following CompletionItem specific capabilities.
Definition: Protocol.h:236
friend bool operator<(const Range &LHS, const Range &RHS)
Definition: Protocol.h:131
llvm::Optional< Range > range
The range of the document that changed.
Definition: Protocol.h:385
Position position
The position inside the text document.
Definition: Protocol.h:618
std::string documentation
The documentation of this parameter. Optional.
Definition: Protocol.h:757
SymbolKind kind
The kind of this symbol.
Definition: Protocol.h:590
std::vector< SignatureInformation > signatures
The resulting signatures.
Definition: Protocol.h:781
llvm::Optional< int > rangeLength
The length of the range that got replaced.
Definition: Protocol.h:388
ClientCapabilities capabilities
The capabilities provided by the client (editor or tool)
Definition: Protocol.h:357
TextDocumentItem textDocument
The document that was opened.
Definition: Protocol.h:370
TextDocumentIdentifier textDocument
The document that did change.
Definition: Protocol.h:399
std::vector< FileEvent > changes
The actual file events.
Definition: Protocol.h:432
FormattingOptions options
The format options.
Definition: Protocol.h:461
Position Pos
std::string languageId
The text document&#39;s language identifier.
Definition: Protocol.h:184
llvm::Optional< std::string > rootPath
The rootPath of the workspace.
Definition: Protocol.h:346
Position position
The position at which this request was sent.
Definition: Protocol.h:470
A single parameter of a particular signature.
Definition: Protocol.h:751
A LSP-specific comparator used to find diagnostic in a container like std:map.
Definition: Protocol.h:521
FormattingOptions options
The format options.
Definition: Protocol.h:485
int line
Line position in a document (zero-based).
Definition: Protocol.h:91
std::vector< TextDocumentContentChangeEvent > contentChanges
The actual content changes.
Definition: Protocol.h:402
friend bool operator<(const DocumentHighlight &LHS, const DocumentHighlight &RHS)
Definition: Protocol.h:816
int character
Character offset on a line in a document (zero-based).
Definition: Protocol.h:96
llvm::Optional< std::vector< SymbolKind > > valueSet
The SymbolKinds that the client supports.
Definition: Protocol.h:286
bool contains(Position Pos) const
Definition: Protocol.h:135
Represents the signature of a callable.
Definition: Protocol.h:778
std::string query
A non-empty query string.
Definition: Protocol.h:604
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::bitset< SymbolKindMax+1 > SymbolKindBitset
Definition: Protocol.h:278
SymbolKind
A symbol kind.
Definition: Protocol.h:247
std::string message
The diagnostic&#39;s code.
Definition: Protocol.h:513
TextDocumentIdentifier textDocument
The text document.
Definition: Protocol.h:615
json::Value toJSON(const URIForFile &U)
Serialize/deserialize URIForFile to/from a string URI.
Definition: Protocol.cpp:56
std::string label
The label of this completion item.
Definition: Protocol.h:687
friend bool operator==(const DocumentHighlight &LHS, const DocumentHighlight &RHS)
Definition: Protocol.h:823
DocumentHighlightKind kind
The highlight kind, default is DocumentHighlightKind.Text.
Definition: Protocol.h:814
SymbolKind adjustKindToCapability(SymbolKind Kind, SymbolKindBitset &SupportedSymbolKinds)
Definition: Protocol.cpp:210
std::vector< Diagnostic > diagnostics
An array of diagnostics.
Definition: Protocol.h:531
The parameters of a Workspace Symbol Request.
Definition: Protocol.h:602
std::string text
The content of the opened text document.
Definition: Protocol.h:190
std::string containerName
The name of the symbol containing this symbol.
Definition: Protocol.h:596
Position position
The position at which this request was sent.
Definition: Protocol.h:796
URIForFile uri
The text document&#39;s URI.
Definition: Protocol.h:84
friend bool operator!=(const Location &LHS, const Location &RHS)
Definition: Protocol.h:150
Range range
The range at which the message applies.
Definition: Protocol.h:497
friend bool operator<(const URIForFile &LHS, const URIForFile &RHS)
Definition: Protocol.h:70
TextDocumentIdentifier textDocument
The document to format.
Definition: Protocol.h:455
Position end
The range&#39;s end position.
Definition: Protocol.h:123
llvm::Optional< WorkspaceEdit > workspaceEdit
Definition: Protocol.h:573
std::string name
The name of this symbol.
Definition: Protocol.h:587
std::string toString() const
Returns a string URI with all components percent-encoded.
Definition: URI.cpp:141
ClangdConfigurationParamsChange settings
Definition: Protocol.h:439
bool operator<(const CompletionItem &L, const CompletionItem &R)
Definition: Protocol.cpp:517
bool fromJSON(const json::Value &E, URIForFile &R)
Definition: Protocol.cpp:33
friend bool operator==(const Position &LHS, const Position &RHS)
Definition: Protocol.h:98
friend bool operator==(const Range &LHS, const Range &RHS)
Definition: Protocol.h:125
llvm::Optional< std::string > compilationDatabasePath
Definition: Protocol.h:329
raw_ostream & operator<<(raw_ostream &OS, const CodeCompletion &C)
constexpr auto SymbolKindMax
Definition: Protocol.h:277
static void format(const clang::clangd::Position &Pos, raw_ostream &OS, StringRef Style)
Definition: Protocol.h:836
llvm::Optional< TraceLevel > trace
The initial trace setting. If omitted trace is disabled (&#39;off&#39;).
Definition: Protocol.h:360
std::string documentation
The documentation of this signature. Optional.
Definition: Protocol.h:768
llvm::StringRef file() const
Retrieves absolute path to the file.
Definition: Protocol.h:57
Represents information about programming constructs like variables, classes, interfaces etc...
Definition: Protocol.h:585