LCOV - code coverage report
Current view: top level - clang/tools/extra/clangd - Protocol.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 0 13 0.0 %
Date: 2018-09-23 13:06:45 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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           0 : 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           0 :     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             : 
      82             : struct TextDocumentIdentifier {
      83             :   /// The text document's URI.
      84             :   URIForFile uri;
      85             : };
      86             : llvm::json::Value toJSON(const TextDocumentIdentifier &);
      87             : bool fromJSON(const llvm::json::Value &, TextDocumentIdentifier &);
      88             : 
      89           0 : 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.
     120             :   Position start;
     121             : 
     122             :   /// The range's end position.
     123             :   Position end;
     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           0 : struct Location {
     142             :   /// The text document's URI.
     143             :   URIForFile uri;
     144             :   Range range;
     145             : 
     146           0 :   friend bool operator==(const Location &LHS, const Location &RHS) {
     147           0 :     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           0 : 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.
     169             :   Range range;
     170             : 
     171             :   /// The string to be inserted. For delete operations use an
     172             :   /// empty string.
     173             :   std::string newText;
     174             : 
     175           0 :   bool operator==(const TextEdit &rhs) const {
     176           0 :     return newText == rhs.newText && range == rhs.range;
     177             :   }
     178             : };
     179             : bool fromJSON(const llvm::json::Value &, TextEdit &);
     180             : llvm::json::Value toJSON(const TextEdit &);
     181             : llvm::raw_ostream &operator<<(llvm::raw_ostream &, const TextEdit &);
     182             : 
     183             : struct TextDocumentItem {
     184             :   /// The text document's URI.
     185             :   URIForFile uri;
     186             : 
     187             :   /// The text document's language identifier.
     188             :   std::string languageId;
     189             : 
     190             :   /// The version number of this document (it will strictly increase after each
     191             :   int version = 0;
     192             : 
     193             :   /// The content of the opened text document.
     194             :   std::string text;
     195             : };
     196             : bool fromJSON(const llvm::json::Value &, TextDocumentItem &);
     197             : 
     198             : enum class TraceLevel {
     199             :   Off = 0,
     200             :   Messages = 1,
     201             :   Verbose = 2,
     202             : };
     203             : bool fromJSON(const llvm::json::Value &E, TraceLevel &Out);
     204             : 
     205             : struct NoParams {};
     206             : inline bool fromJSON(const llvm::json::Value &, NoParams &) { return true; }
     207             : using ShutdownParams = NoParams;
     208             : using ExitParams = NoParams;
     209             : 
     210             : /// Defines how the host (editor) should sync document changes to the language
     211             : /// server.
     212             : enum class TextDocumentSyncKind {
     213             :   /// Documents should not be synced at all.
     214             :   None = 0,
     215             : 
     216             :   /// Documents are synced by always sending the full content of the document.
     217             :   Full = 1,
     218             : 
     219             :   /// Documents are synced by sending the full content on open.  After that
     220             :   /// only incremental updates to the document are send.
     221             :   Incremental = 2,
     222             : };
     223             : 
     224             : struct CompletionItemClientCapabilities {
     225             :   /// Client supports snippets as insert text.
     226             :   bool snippetSupport = false;
     227             :   /// Client supports commit characters on a completion item.
     228             :   bool commitCharacterSupport = false;
     229             :   // Client supports the follow content formats for the documentation property.
     230             :   // The order describes the preferred format of the client.
     231             :   // NOTE: not used by clangd at the moment.
     232             :   // std::vector<MarkupKind> documentationFormat;
     233             : };
     234             : bool fromJSON(const llvm::json::Value &, CompletionItemClientCapabilities &);
     235             : 
     236             : struct CompletionClientCapabilities {
     237             :   /// Whether completion supports dynamic registration.
     238             :   bool dynamicRegistration = false;
     239             :   /// The client supports the following `CompletionItem` specific capabilities.
     240             :   CompletionItemClientCapabilities completionItem;
     241             :   // NOTE: not used by clangd at the moment.
     242             :   // llvm::Optional<CompletionItemKindCapabilities> completionItemKind;
     243             : 
     244             :   /// The client supports to send additional context information for a
     245             :   /// `textDocument/completion` request.
     246             :   bool contextSupport = false;
     247             : };
     248             : bool fromJSON(const llvm::json::Value &, CompletionClientCapabilities &);
     249             : 
     250             : struct PublishDiagnosticsClientCapabilities {
     251             :   // Whether the client accepts diagnostics with related information.
     252             :   // NOTE: not used by clangd at the moment.
     253             :   // bool relatedInformation;
     254             : 
     255             :   /// Whether the client accepts diagnostics with fixes attached using the
     256             :   /// "clangd_fixes" extension.
     257             :   bool clangdFixSupport = false;
     258             : 
     259             :   /// Whether the client accepts diagnostics with category attached to it
     260             :   /// using the "category" extension.
     261             :   bool categorySupport = false;
     262             : };
     263             : bool fromJSON(const llvm::json::Value &,
     264             :               PublishDiagnosticsClientCapabilities &);
     265             : 
     266             : /// A symbol kind.
     267             : enum class SymbolKind {
     268             :   File = 1,
     269             :   Module = 2,
     270             :   Namespace = 3,
     271             :   Package = 4,
     272             :   Class = 5,
     273             :   Method = 6,
     274             :   Property = 7,
     275             :   Field = 8,
     276             :   Constructor = 9,
     277             :   Enum = 10,
     278             :   Interface = 11,
     279             :   Function = 12,
     280             :   Variable = 13,
     281             :   Constant = 14,
     282             :   String = 15,
     283             :   Number = 16,
     284             :   Boolean = 17,
     285             :   Array = 18,
     286             :   Object = 19,
     287             :   Key = 20,
     288             :   Null = 21,
     289             :   EnumMember = 22,
     290             :   Struct = 23,
     291             :   Event = 24,
     292             :   Operator = 25,
     293             :   TypeParameter = 26
     294             : };
     295             : 
     296             : constexpr auto SymbolKindMin = static_cast<size_t>(SymbolKind::File);
     297             : constexpr auto SymbolKindMax = static_cast<size_t>(SymbolKind::TypeParameter);
     298             : using SymbolKindBitset = std::bitset<SymbolKindMax + 1>;
     299             : 
     300             : bool fromJSON(const llvm::json::Value &, SymbolKind &);
     301             : 
     302             : struct SymbolKindCapabilities {
     303             :   /// The SymbolKinds that the client supports. If not set, the client only
     304             :   /// supports <= SymbolKind::Array and will not fall back to a valid default
     305             :   /// value.
     306             :   llvm::Optional<std::vector<SymbolKind>> valueSet;
     307             : };
     308             : bool fromJSON(const llvm::json::Value &, std::vector<SymbolKind> &);
     309             : bool fromJSON(const llvm::json::Value &, SymbolKindCapabilities &);
     310             : SymbolKind adjustKindToCapability(SymbolKind Kind,
     311             :                                   SymbolKindBitset &supportedSymbolKinds);
     312             : 
     313             : struct WorkspaceSymbolCapabilities {
     314             :   /// Capabilities SymbolKind.
     315             :   llvm::Optional<SymbolKindCapabilities> symbolKind;
     316             : };
     317             : bool fromJSON(const llvm::json::Value &, WorkspaceSymbolCapabilities &);
     318             : 
     319             : // FIXME: most of the capabilities are missing from this struct. Only the ones
     320             : // used by clangd are currently there.
     321             : struct WorkspaceClientCapabilities {
     322             :   /// Capabilities specific to `workspace/symbol`.
     323             :   llvm::Optional<WorkspaceSymbolCapabilities> symbol;
     324             : };
     325             : bool fromJSON(const llvm::json::Value &, WorkspaceClientCapabilities &);
     326             : 
     327             : // FIXME: most of the capabilities are missing from this struct. Only the ones
     328             : // used by clangd are currently there.
     329             : struct TextDocumentClientCapabilities {
     330             :   /// Capabilities specific to the `textDocument/completion`
     331             :   CompletionClientCapabilities completion;
     332             : 
     333             :   /// Capabilities specific to the 'textDocument/publishDiagnostics'
     334             :   PublishDiagnosticsClientCapabilities publishDiagnostics;
     335             : };
     336             : bool fromJSON(const llvm::json::Value &, TextDocumentClientCapabilities &);
     337             : 
     338             : struct ClientCapabilities {
     339             :   // Workspace specific client capabilities.
     340             :   llvm::Optional<WorkspaceClientCapabilities> workspace;
     341             : 
     342             :   // Text document specific client capabilities.
     343             :   TextDocumentClientCapabilities textDocument;
     344             : };
     345             : 
     346             : bool fromJSON(const llvm::json::Value &, ClientCapabilities &);
     347             : 
     348             : /// Clangd extension that's used in the 'compilationDatabaseChanges' in
     349             : /// workspace/didChangeConfiguration to record updates to the in-memory
     350             : /// compilation database.
     351             : struct ClangdCompileCommand {
     352             :   std::string workingDirectory;
     353             :   std::vector<std::string> compilationCommand;
     354             : };
     355             : bool fromJSON(const llvm::json::Value &, ClangdCompileCommand &);
     356             : 
     357             : /// Clangd extension to set clangd-specific "initializationOptions" in the
     358             : /// "initialize" request and for the "workspace/didChangeConfiguration"
     359             : /// notification since the data received is described as 'any' type in LSP.
     360             : struct ClangdConfigurationParamsChange {
     361             :   llvm::Optional<std::string> compilationDatabasePath;
     362             : 
     363             :   // The changes that happened to the compilation database.
     364             :   // The key of the map is a file name.
     365             :   llvm::Optional<std::map<std::string, ClangdCompileCommand>>
     366             :       compilationDatabaseChanges;
     367             : };
     368             : bool fromJSON(const llvm::json::Value &, ClangdConfigurationParamsChange &);
     369             : 
     370             : struct ClangdInitializationOptions : public ClangdConfigurationParamsChange {};
     371             : 
     372             : struct InitializeParams {
     373             :   /// The process Id of the parent process that started
     374             :   /// the server. Is null if the process has not been started by another
     375             :   /// process. If the parent process is not alive then the server should exit
     376             :   /// (see exit notification) its process.
     377             :   llvm::Optional<int> processId;
     378             : 
     379             :   /// The rootPath of the workspace. Is null
     380             :   /// if no folder is open.
     381             :   ///
     382             :   /// @deprecated in favour of rootUri.
     383             :   llvm::Optional<std::string> rootPath;
     384             : 
     385             :   /// The rootUri of the workspace. Is null if no
     386             :   /// folder is open. If both `rootPath` and `rootUri` are set
     387             :   /// `rootUri` wins.
     388             :   llvm::Optional<URIForFile> rootUri;
     389             : 
     390             :   // User provided initialization options.
     391             :   // initializationOptions?: any;
     392             : 
     393             :   /// The capabilities provided by the client (editor or tool)
     394             :   ClientCapabilities capabilities;
     395             : 
     396             :   /// The initial trace setting. If omitted trace is disabled ('off').
     397             :   llvm::Optional<TraceLevel> trace;
     398             : 
     399             :   // We use this predefined struct because it is easier to use
     400             :   // than the protocol specified type of 'any'.
     401             :   llvm::Optional<ClangdInitializationOptions> initializationOptions;
     402             : };
     403             : bool fromJSON(const llvm::json::Value &, InitializeParams &);
     404             : 
     405             : struct DidOpenTextDocumentParams {
     406             :   /// The document that was opened.
     407             :   TextDocumentItem textDocument;
     408             : 
     409             :   /// Extension storing per-file metadata, such as compilation flags.
     410             :   llvm::Optional<Metadata> metadata;
     411             : };
     412             : bool fromJSON(const llvm::json::Value &, DidOpenTextDocumentParams &);
     413             : 
     414             : struct DidCloseTextDocumentParams {
     415             :   /// The document that was closed.
     416             :   TextDocumentIdentifier textDocument;
     417             : };
     418             : bool fromJSON(const llvm::json::Value &, DidCloseTextDocumentParams &);
     419             : 
     420           0 : struct TextDocumentContentChangeEvent {
     421             :   /// The range of the document that changed.
     422             :   llvm::Optional<Range> range;
     423             : 
     424             :   /// The length of the range that got replaced.
     425             :   llvm::Optional<int> rangeLength;
     426             : 
     427             :   /// The new text of the range/document.
     428             :   std::string text;
     429             : };
     430             : bool fromJSON(const llvm::json::Value &, TextDocumentContentChangeEvent &);
     431             : 
     432             : struct DidChangeTextDocumentParams {
     433             :   /// The document that did change. The version number points
     434             :   /// to the version after all provided content changes have
     435             :   /// been applied.
     436             :   TextDocumentIdentifier textDocument;
     437             : 
     438             :   /// The actual content changes.
     439             :   std::vector<TextDocumentContentChangeEvent> contentChanges;
     440             : 
     441             :   /// Forces diagnostics to be generated, or to not be generated, for this
     442             :   /// version of the file. If not set, diagnostics are eventually consistent:
     443             :   /// either they will be provided for this version or some subsequent one.
     444             :   /// This is a clangd extension.
     445             :   llvm::Optional<bool> wantDiagnostics;
     446             : };
     447             : bool fromJSON(const llvm::json::Value &, DidChangeTextDocumentParams &);
     448             : 
     449             : enum class FileChangeType {
     450             :   /// The file got created.
     451             :   Created = 1,
     452             :   /// The file got changed.
     453             :   Changed = 2,
     454             :   /// The file got deleted.
     455             :   Deleted = 3
     456             : };
     457             : bool fromJSON(const llvm::json::Value &E, FileChangeType &Out);
     458             : 
     459             : struct FileEvent {
     460             :   /// The file's URI.
     461             :   URIForFile uri;
     462             :   /// The change type.
     463             :   FileChangeType type = FileChangeType::Created;
     464             : };
     465             : bool fromJSON(const llvm::json::Value &, FileEvent &);
     466             : 
     467             : struct DidChangeWatchedFilesParams {
     468             :   /// The actual file events.
     469             :   std::vector<FileEvent> changes;
     470             : };
     471             : bool fromJSON(const llvm::json::Value &, DidChangeWatchedFilesParams &);
     472             : 
     473             : struct DidChangeConfigurationParams {
     474             :   // We use this predefined struct because it is easier to use
     475             :   // than the protocol specified type of 'any'.
     476             :   ClangdConfigurationParamsChange settings;
     477             : };
     478             : bool fromJSON(const llvm::json::Value &, DidChangeConfigurationParams &);
     479             : 
     480             : struct FormattingOptions {
     481             :   /// Size of a tab in spaces.
     482             :   int tabSize = 0;
     483             : 
     484             :   /// Prefer spaces over tabs.
     485             :   bool insertSpaces = false;
     486             : };
     487             : bool fromJSON(const llvm::json::Value &, FormattingOptions &);
     488             : llvm::json::Value toJSON(const FormattingOptions &);
     489             : 
     490             : struct DocumentRangeFormattingParams {
     491             :   /// The document to format.
     492             :   TextDocumentIdentifier textDocument;
     493             : 
     494             :   /// The range to format
     495             :   Range range;
     496             : 
     497             :   /// The format options
     498             :   FormattingOptions options;
     499             : };
     500             : bool fromJSON(const llvm::json::Value &, DocumentRangeFormattingParams &);
     501             : 
     502             : struct DocumentOnTypeFormattingParams {
     503             :   /// The document to format.
     504             :   TextDocumentIdentifier textDocument;
     505             : 
     506             :   /// The position at which this request was sent.
     507             :   Position position;
     508             : 
     509             :   /// The character that has been typed.
     510             :   std::string ch;
     511             : 
     512             :   /// The format options.
     513             :   FormattingOptions options;
     514             : };
     515             : bool fromJSON(const llvm::json::Value &, DocumentOnTypeFormattingParams &);
     516             : 
     517             : struct DocumentFormattingParams {
     518             :   /// The document to format.
     519             :   TextDocumentIdentifier textDocument;
     520             : 
     521             :   /// The format options
     522             :   FormattingOptions options;
     523             : };
     524             : bool fromJSON(const llvm::json::Value &, DocumentFormattingParams &);
     525             : 
     526             : struct DocumentSymbolParams {
     527             :   // The text document to find symbols in.
     528             :   TextDocumentIdentifier textDocument;
     529             : };
     530             : bool fromJSON(const llvm::json::Value &, DocumentSymbolParams &);
     531             : 
     532             : struct Diagnostic {
     533             :   /// The range at which the message applies.
     534             :   Range range;
     535             : 
     536             :   /// The diagnostic's severity. Can be omitted. If omitted it is up to the
     537             :   /// client to interpret diagnostics as error, warning, info or hint.
     538             :   int severity = 0;
     539             : 
     540             :   /// The diagnostic's code. Can be omitted.
     541             :   /// Note: Not currently used by clangd
     542             :   // std::string code;
     543             : 
     544             :   /// A human-readable string describing the source of this
     545             :   /// diagnostic, e.g. 'typescript' or 'super lint'.
     546             :   /// Note: Not currently used by clangd
     547             :   // std::string source;
     548             : 
     549             :   /// The diagnostic's message.
     550             :   std::string message;
     551             : 
     552             :   /// The diagnostic's category. Can be omitted.
     553             :   /// An LSP extension that's used to send the name of the category over to the
     554             :   /// client. The category typically describes the compilation stage during
     555             :   /// which the issue was produced, e.g. "Semantic Issue" or "Parse Issue".
     556             :   std::string category;
     557             : };
     558             : 
     559             : /// A LSP-specific comparator used to find diagnostic in a container like
     560             : /// std:map.
     561             : /// We only use the required fields of Diagnostic to do the comparsion to avoid
     562             : /// any regression issues from LSP clients (e.g. VScode), see
     563             : /// https://git.io/vbr29
     564             : struct LSPDiagnosticCompare {
     565             :   bool operator()(const Diagnostic &LHS, const Diagnostic &RHS) const {
     566             :     return std::tie(LHS.range, LHS.message) < std::tie(RHS.range, RHS.message);
     567             :   }
     568             : };
     569             : bool fromJSON(const llvm::json::Value &, Diagnostic &);
     570             : llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Diagnostic &);
     571             : 
     572             : struct CodeActionContext {
     573             :   /// An array of diagnostics.
     574             :   std::vector<Diagnostic> diagnostics;
     575             : };
     576             : bool fromJSON(const llvm::json::Value &, CodeActionContext &);
     577             : 
     578             : struct CodeActionParams {
     579             :   /// The document in which the command was invoked.
     580             :   TextDocumentIdentifier textDocument;
     581             : 
     582             :   /// The range for which the command was invoked.
     583             :   Range range;
     584             : 
     585             :   /// Context carrying additional information.
     586             :   CodeActionContext context;
     587             : };
     588             : bool fromJSON(const llvm::json::Value &, CodeActionParams &);
     589             : 
     590             : struct WorkspaceEdit {
     591             :   /// Holds changes to existing resources.
     592             :   llvm::Optional<std::map<std::string, std::vector<TextEdit>>> changes;
     593             : 
     594             :   /// Note: "documentChanges" is not currently used because currently there is
     595             :   /// no support for versioned edits.
     596             : };
     597             : bool fromJSON(const llvm::json::Value &, WorkspaceEdit &);
     598             : llvm::json::Value toJSON(const WorkspaceEdit &WE);
     599             : 
     600             : /// Exact commands are not specified in the protocol so we define the
     601             : /// ones supported by Clangd here. The protocol specifies the command arguments
     602             : /// to be "any[]" but to make this safer and more manageable, each command we
     603             : /// handle maps to a certain llvm::Optional of some struct to contain its
     604             : /// arguments. Different commands could reuse the same llvm::Optional as
     605             : /// arguments but a command that needs different arguments would simply add a
     606             : /// new llvm::Optional and not use any other ones. In practice this means only
     607             : /// one argument type will be parsed and set.
     608             : struct ExecuteCommandParams {
     609             :   // Command to apply fix-its. Uses WorkspaceEdit as argument.
     610             :   const static llvm::StringLiteral CLANGD_APPLY_FIX_COMMAND;
     611             : 
     612             :   /// The command identifier, e.g. CLANGD_APPLY_FIX_COMMAND
     613             :   std::string command;
     614             : 
     615             :   // Arguments
     616             :   llvm::Optional<WorkspaceEdit> workspaceEdit;
     617             : };
     618             : bool fromJSON(const llvm::json::Value &, ExecuteCommandParams &);
     619             : 
     620             : struct Command : public ExecuteCommandParams {
     621             :   std::string title;
     622             : };
     623             : 
     624             : llvm::json::Value toJSON(const Command &C);
     625             : 
     626             : /// Represents information about programming constructs like variables, classes,
     627             : /// interfaces etc.
     628             : struct SymbolInformation {
     629             :   /// The name of this symbol.
     630             :   std::string name;
     631             : 
     632             :   /// The kind of this symbol.
     633             :   SymbolKind kind;
     634             : 
     635             :   /// The location of this symbol.
     636             :   Location location;
     637             : 
     638             :   /// The name of the symbol containing this symbol.
     639             :   std::string containerName;
     640             : };
     641             : llvm::json::Value toJSON(const SymbolInformation &);
     642             : llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SymbolInformation &);
     643             : 
     644             : /// The parameters of a Workspace Symbol Request.
     645             : struct WorkspaceSymbolParams {
     646             :   /// A non-empty query string
     647             :   std::string query;
     648             : };
     649             : bool fromJSON(const llvm::json::Value &, WorkspaceSymbolParams &);
     650             : 
     651             : struct ApplyWorkspaceEditParams {
     652             :   WorkspaceEdit edit;
     653             : };
     654             : llvm::json::Value toJSON(const ApplyWorkspaceEditParams &);
     655             : 
     656             : struct TextDocumentPositionParams {
     657             :   /// The text document.
     658             :   TextDocumentIdentifier textDocument;
     659             : 
     660             :   /// The position inside the text document.
     661             :   Position position;
     662             : };
     663             : bool fromJSON(const llvm::json::Value &, TextDocumentPositionParams &);
     664             : 
     665             : enum class MarkupKind {
     666             :   PlainText,
     667             :   Markdown,
     668             : };
     669             : 
     670             : struct MarkupContent {
     671             :   MarkupKind kind = MarkupKind::PlainText;
     672             :   std::string value;
     673             : };
     674             : llvm::json::Value toJSON(const MarkupContent &MC);
     675             : 
     676             : struct Hover {
     677             :   /// The hover's content
     678             :   MarkupContent contents;
     679             : 
     680             :   /// An optional range is a range inside a text document
     681             :   /// that is used to visualize a hover, e.g. by changing the background color.
     682             :   llvm::Optional<Range> range;
     683             : };
     684             : llvm::json::Value toJSON(const Hover &H);
     685             : 
     686             : /// The kind of a completion entry.
     687             : enum class CompletionItemKind {
     688             :   Missing = 0,
     689             :   Text = 1,
     690             :   Method = 2,
     691             :   Function = 3,
     692             :   Constructor = 4,
     693             :   Field = 5,
     694             :   Variable = 6,
     695             :   Class = 7,
     696             :   Interface = 8,
     697             :   Module = 9,
     698             :   Property = 10,
     699             :   Unit = 11,
     700             :   Value = 12,
     701             :   Enum = 13,
     702             :   Keyword = 14,
     703             :   Snippet = 15,
     704             :   Color = 16,
     705             :   File = 17,
     706             :   Reference = 18,
     707             : };
     708             : 
     709             : /// Defines whether the insert text in a completion item should be interpreted
     710             : /// as plain text or a snippet.
     711             : enum class InsertTextFormat {
     712             :   Missing = 0,
     713             :   /// The primary text to be inserted is treated as a plain string.
     714             :   PlainText = 1,
     715             :   /// The primary text to be inserted is treated as a snippet.
     716             :   ///
     717             :   /// A snippet can define tab stops and placeholders with `$1`, `$2`
     718             :   /// and `${3:foo}`. `$0` defines the final tab stop, it defaults to the end
     719             :   /// of the snippet. Placeholders with equal identifiers are linked, that is
     720             :   /// typing in one will update others too.
     721             :   ///
     722             :   /// See also:
     723             :   /// https//github.com/Microsoft/vscode/blob/master/src/vs/editor/contrib/snippet/common/snippet.md
     724             :   Snippet = 2,
     725             : };
     726             : 
     727             : struct CompletionItem {
     728             :   /// The label of this completion item. By default also the text that is
     729             :   /// inserted when selecting this completion.
     730             :   std::string label;
     731             : 
     732             :   /// The kind of this completion item. Based of the kind an icon is chosen by
     733             :   /// the editor.
     734             :   CompletionItemKind kind = CompletionItemKind::Missing;
     735             : 
     736             :   /// A human-readable string with additional information about this item, like
     737             :   /// type or symbol information.
     738             :   std::string detail;
     739             : 
     740             :   /// A human-readable string that represents a doc-comment.
     741             :   std::string documentation;
     742             : 
     743             :   /// A string that should be used when comparing this item with other items.
     744             :   /// When `falsy` the label is used.
     745             :   std::string sortText;
     746             : 
     747             :   /// A string that should be used when filtering a set of completion items.
     748             :   /// When `falsy` the label is used.
     749             :   std::string filterText;
     750             : 
     751             :   /// A string that should be inserted to a document when selecting this
     752             :   /// completion. When `falsy` the label is used.
     753             :   std::string insertText;
     754             : 
     755             :   /// The format of the insert text. The format applies to both the `insertText`
     756             :   /// property and the `newText` property of a provided `textEdit`.
     757             :   InsertTextFormat insertTextFormat = InsertTextFormat::Missing;
     758             : 
     759             :   /// An edit which is applied to a document when selecting this completion.
     760             :   /// When an edit is provided `insertText` is ignored.
     761             :   ///
     762             :   /// Note: The range of the edit must be a single line range and it must
     763             :   /// contain the position at which completion has been requested.
     764             :   llvm::Optional<TextEdit> textEdit;
     765             : 
     766             :   /// An optional array of additional text edits that are applied when selecting
     767             :   /// this completion. Edits must not overlap with the main edit nor with
     768             :   /// themselves.
     769             :   std::vector<TextEdit> additionalTextEdits;
     770             : 
     771             :   /// Indicates if this item is deprecated.
     772             :   bool deprecated = false;
     773             : 
     774             :   // TODO(krasimir): The following optional fields defined by the language
     775             :   // server protocol are unsupported:
     776             :   //
     777             :   // data?: any - A data entry field that is preserved on a completion item
     778             :   //              between a completion and a completion resolve request.
     779             : };
     780             : llvm::json::Value toJSON(const CompletionItem &);
     781             : llvm::raw_ostream &operator<<(llvm::raw_ostream &, const CompletionItem &);
     782             : 
     783             : bool operator<(const CompletionItem &, const CompletionItem &);
     784             : 
     785             : /// Represents a collection of completion items to be presented in the editor.
     786             : struct CompletionList {
     787             :   /// The list is not complete. Further typing should result in recomputing the
     788             :   /// list.
     789             :   bool isIncomplete = false;
     790             : 
     791             :   /// The completion items.
     792             :   std::vector<CompletionItem> items;
     793             : };
     794             : llvm::json::Value toJSON(const CompletionList &);
     795             : 
     796             : /// A single parameter of a particular signature.
     797             : struct ParameterInformation {
     798             : 
     799             :   /// The label of this parameter. Mandatory.
     800             :   std::string label;
     801             : 
     802             :   /// The documentation of this parameter. Optional.
     803             :   std::string documentation;
     804             : };
     805             : llvm::json::Value toJSON(const ParameterInformation &);
     806             : 
     807             : /// Represents the signature of something callable.
     808             : struct SignatureInformation {
     809             : 
     810             :   /// The label of this signature. Mandatory.
     811             :   std::string label;
     812             : 
     813             :   /// The documentation of this signature. Optional.
     814             :   std::string documentation;
     815             : 
     816             :   /// The parameters of this signature.
     817             :   std::vector<ParameterInformation> parameters;
     818             : };
     819             : llvm::json::Value toJSON(const SignatureInformation &);
     820             : llvm::raw_ostream &operator<<(llvm::raw_ostream &,
     821             :                               const SignatureInformation &);
     822             : 
     823             : /// Represents the signature of a callable.
     824           0 : struct SignatureHelp {
     825             : 
     826             :   /// The resulting signatures.
     827             :   std::vector<SignatureInformation> signatures;
     828             : 
     829             :   /// The active signature.
     830             :   int activeSignature = 0;
     831             : 
     832             :   /// The active parameter of the active signature.
     833             :   int activeParameter = 0;
     834             : 
     835             :   /// Position of the start of the argument list, including opening paren. e.g.
     836             :   /// foo("first arg",   "second arg",
     837             :   ///    ^-argListStart   ^-cursor
     838             :   /// This is a clangd-specific extension, it is only available via C++ API and
     839             :   /// not currently serialized for the LSP.
     840             :   Position argListStart;
     841             : };
     842             : llvm::json::Value toJSON(const SignatureHelp &);
     843             : 
     844             : struct RenameParams {
     845             :   /// The document that was opened.
     846             :   TextDocumentIdentifier textDocument;
     847             : 
     848             :   /// The position at which this request was sent.
     849             :   Position position;
     850             : 
     851             :   /// The new name of the symbol.
     852             :   std::string newName;
     853             : };
     854             : bool fromJSON(const llvm::json::Value &, RenameParams &);
     855             : 
     856             : enum class DocumentHighlightKind { Text = 1, Read = 2, Write = 3 };
     857             : 
     858             : /// A document highlight is a range inside a text document which deserves
     859             : /// special attention. Usually a document highlight is visualized by changing
     860             : /// the background color of its range.
     861             : 
     862           0 : struct DocumentHighlight {
     863             :   /// The range this highlight applies to.
     864             :   Range range;
     865             : 
     866             :   /// The highlight kind, default is DocumentHighlightKind.Text.
     867             :   DocumentHighlightKind kind = DocumentHighlightKind::Text;
     868             : 
     869             :   friend bool operator<(const DocumentHighlight &LHS,
     870             :                         const DocumentHighlight &RHS) {
     871             :     int LHSKind = static_cast<int>(LHS.kind);
     872             :     int RHSKind = static_cast<int>(RHS.kind);
     873             :     return std::tie(LHS.range, LHSKind) < std::tie(RHS.range, RHSKind);
     874             :   }
     875             : 
     876             :   friend bool operator==(const DocumentHighlight &LHS,
     877             :                          const DocumentHighlight &RHS) {
     878           0 :     return LHS.kind == RHS.kind && LHS.range == RHS.range;
     879             :   }
     880             : };
     881             : llvm::json::Value toJSON(const DocumentHighlight &DH);
     882             : llvm::raw_ostream &operator<<(llvm::raw_ostream &, const DocumentHighlight &);
     883             : 
     884             : struct ReferenceParams : public TextDocumentPositionParams {
     885             :   // For now, no options like context.includeDeclaration are supported.
     886             : };
     887             : bool fromJSON(const llvm::json::Value &, ReferenceParams &);
     888             : 
     889             : } // namespace clangd
     890             : } // namespace clang
     891             : 
     892             : namespace llvm {
     893             : template <> struct format_provider<clang::clangd::Position> {
     894             :   static void format(const clang::clangd::Position &Pos, raw_ostream &OS,
     895             :                      StringRef Style) {
     896             :     assert(Style.empty() && "style modifiers for this type are not supported");
     897             :     OS << Pos;
     898             :   }
     899             : };
     900             : } // namespace llvm
     901             : 
     902             : #endif

Generated by: LCOV version 1.13