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 17 0.0 %
Date: 2018-06-17 00:07:59 Functions: 0 11 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 JSONExpr.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 "JSONExpr.h"
      28             : #include "URI.h"
      29             : #include "llvm/ADT/Optional.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             : json::Expr toJSON(const URIForFile &U);
      80             : bool fromJSON(const json::Expr &, URIForFile &);
      81             : 
      82             : struct TextDocumentIdentifier {
      83             :   /// The text document's URI.
      84             :   URIForFile uri;
      85             : };
      86             : json::Expr toJSON(const TextDocumentIdentifier &);
      87             : bool fromJSON(const json::Expr &, 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 json::Expr &, Position &);
     115             : json::Expr 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 json::Expr &, Range &);
     138             : json::Expr 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             : json::Expr 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 json::Expr &, 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             : bool fromJSON(const json::Expr &, TextEdit &);
     176             : json::Expr toJSON(const TextEdit &);
     177             : llvm::raw_ostream &operator<<(llvm::raw_ostream &, const TextEdit &);
     178             : 
     179             : struct TextDocumentItem {
     180             :   /// The text document's URI.
     181             :   URIForFile 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 json::Expr &, TextDocumentItem &);
     193             : 
     194             : enum class TraceLevel {
     195             :   Off = 0,
     196             :   Messages = 1,
     197             :   Verbose = 2,
     198             : };
     199             : bool fromJSON(const json::Expr &E, TraceLevel &Out);
     200             : 
     201             : struct NoParams {};
     202             : inline bool fromJSON(const json::Expr &, NoParams &) { return true; }
     203             : using ShutdownParams = NoParams;
     204             : using ExitParams = NoParams;
     205             : 
     206             : /// Defines how the host (editor) should sync document changes to the language
     207             : /// server.
     208             : enum class TextDocumentSyncKind {
     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             : 
     220             : struct CompletionItemClientCapabilities {
     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 json::Expr &, CompletionItemClientCapabilities &);
     231             : 
     232             : struct CompletionClientCapabilities {
     233             :   /// Whether completion supports dynamic registration.
     234             :   bool dynamicRegistration = false;
     235             :   /// The client supports the following `CompletionItem` specific capabilities.
     236             :   CompletionItemClientCapabilities completionItem;
     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 json::Expr &, 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 json::Expr &, SymbolKind &);
     281             : 
     282             : struct SymbolKindCapabilities {
     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 json::Expr &, std::vector<SymbolKind> &);
     289             : bool fromJSON(const json::Expr &, SymbolKindCapabilities &);
     290             : SymbolKind adjustKindToCapability(SymbolKind Kind,
     291             :                                   SymbolKindBitset &supportedSymbolKinds);
     292             : 
     293             : struct WorkspaceSymbolCapabilities {
     294             :   /// Capabilities SymbolKind.
     295             :   llvm::Optional<SymbolKindCapabilities> symbolKind;
     296             : };
     297             : bool fromJSON(const json::Expr &, WorkspaceSymbolCapabilities &);
     298             : 
     299             : // FIXME: most of the capabilities are missing from this struct. Only the ones
     300             : // used by clangd are currently there.
     301             : struct WorkspaceClientCapabilities {
     302             :   /// Capabilities specific to `workspace/symbol`.
     303             :   llvm::Optional<WorkspaceSymbolCapabilities> symbol;
     304             : };
     305             : bool fromJSON(const json::Expr &, WorkspaceClientCapabilities &);
     306             : 
     307             : // FIXME: most of the capabilities are missing from this struct. Only the ones
     308             : // used by clangd are currently there.
     309             : struct TextDocumentClientCapabilities {
     310             :   /// Capabilities specific to the `textDocument/completion`
     311             :   CompletionClientCapabilities completion;
     312             : };
     313             : bool fromJSON(const json::Expr &, TextDocumentClientCapabilities &);
     314             : 
     315             : struct ClientCapabilities {
     316             :   // Workspace specific client capabilities.
     317             :   llvm::Optional<WorkspaceClientCapabilities> workspace;
     318             : 
     319             :   // Text document specific client capabilities.
     320             :   TextDocumentClientCapabilities textDocument;
     321             : };
     322             : 
     323             : bool fromJSON(const json::Expr &, ClientCapabilities &);
     324             : 
     325             : struct InitializeParams {
     326             :   /// The process Id of the parent process that started
     327             :   /// the server. Is null if the process has not been started by another
     328             :   /// process. If the parent process is not alive then the server should exit
     329             :   /// (see exit notification) its process.
     330             :   llvm::Optional<int> processId;
     331             : 
     332             :   /// The rootPath of the workspace. Is null
     333             :   /// if no folder is open.
     334             :   ///
     335             :   /// @deprecated in favour of rootUri.
     336             :   llvm::Optional<std::string> rootPath;
     337             : 
     338             :   /// The rootUri of the workspace. Is null if no
     339             :   /// folder is open. If both `rootPath` and `rootUri` are set
     340             :   /// `rootUri` wins.
     341             :   llvm::Optional<URIForFile> rootUri;
     342             : 
     343             :   // User provided initialization options.
     344             :   // initializationOptions?: any;
     345             : 
     346             :   /// The capabilities provided by the client (editor or tool)
     347             :   ClientCapabilities capabilities;
     348             : 
     349             :   /// The initial trace setting. If omitted trace is disabled ('off').
     350             :   llvm::Optional<TraceLevel> trace;
     351             : };
     352             : bool fromJSON(const json::Expr &, InitializeParams &);
     353             : 
     354             : struct DidOpenTextDocumentParams {
     355             :   /// The document that was opened.
     356             :   TextDocumentItem textDocument;
     357             : 
     358             :   /// Extension storing per-file metadata, such as compilation flags.
     359             :   llvm::Optional<Metadata> metadata;
     360             : };
     361             : bool fromJSON(const json::Expr &, DidOpenTextDocumentParams &);
     362             : 
     363             : struct DidCloseTextDocumentParams {
     364             :   /// The document that was closed.
     365             :   TextDocumentIdentifier textDocument;
     366             : };
     367             : bool fromJSON(const json::Expr &, DidCloseTextDocumentParams &);
     368             : 
     369           0 : struct TextDocumentContentChangeEvent {
     370             :   /// The range of the document that changed.
     371             :   llvm::Optional<Range> range;
     372             : 
     373             :   /// The length of the range that got replaced.
     374             :   llvm::Optional<int> rangeLength;
     375             : 
     376             :   /// The new text of the range/document.
     377             :   std::string text;
     378             : };
     379             : bool fromJSON(const json::Expr &, TextDocumentContentChangeEvent &);
     380             : 
     381             : struct DidChangeTextDocumentParams {
     382             :   /// The document that did change. The version number points
     383             :   /// to the version after all provided content changes have
     384             :   /// been applied.
     385             :   TextDocumentIdentifier textDocument;
     386             : 
     387             :   /// The actual content changes.
     388             :   std::vector<TextDocumentContentChangeEvent> contentChanges;
     389             : 
     390             :   /// Forces diagnostics to be generated, or to not be generated, for this
     391             :   /// version of the file. If not set, diagnostics are eventually consistent:
     392             :   /// either they will be provided for this version or some subsequent one.
     393             :   /// This is a clangd extension.
     394             :   llvm::Optional<bool> wantDiagnostics;
     395             : };
     396             : bool fromJSON(const json::Expr &, DidChangeTextDocumentParams &);
     397             : 
     398             : enum class FileChangeType {
     399             :   /// The file got created.
     400             :   Created = 1,
     401             :   /// The file got changed.
     402             :   Changed = 2,
     403             :   /// The file got deleted.
     404             :   Deleted = 3
     405             : };
     406             : bool fromJSON(const json::Expr &E, FileChangeType &Out);
     407             : 
     408             : struct FileEvent {
     409             :   /// The file's URI.
     410             :   URIForFile uri;
     411             :   /// The change type.
     412             :   FileChangeType type = FileChangeType::Created;
     413             : };
     414             : bool fromJSON(const json::Expr &, FileEvent &);
     415             : 
     416             : struct DidChangeWatchedFilesParams {
     417             :   /// The actual file events.
     418             :   std::vector<FileEvent> changes;
     419             : };
     420             : bool fromJSON(const json::Expr &, DidChangeWatchedFilesParams &);
     421             : 
     422             : /// Clangd extension to manage a workspace/didChangeConfiguration notification
     423             : /// since the data received is described as 'any' type in LSP.
     424             : struct ClangdConfigurationParamsChange {
     425             :   llvm::Optional<std::string> compilationDatabasePath;
     426             : };
     427             : bool fromJSON(const json::Expr &, ClangdConfigurationParamsChange &);
     428             : 
     429             : struct DidChangeConfigurationParams {
     430             :   // We use this predefined struct because it is easier to use
     431             :   // than the protocol specified type of 'any'.
     432             :   ClangdConfigurationParamsChange settings;
     433             : };
     434             : bool fromJSON(const json::Expr &, DidChangeConfigurationParams &);
     435             : 
     436             : struct FormattingOptions {
     437             :   /// Size of a tab in spaces.
     438             :   int tabSize = 0;
     439             : 
     440             :   /// Prefer spaces over tabs.
     441             :   bool insertSpaces = false;
     442             : };
     443             : bool fromJSON(const json::Expr &, FormattingOptions &);
     444             : json::Expr toJSON(const FormattingOptions &);
     445             : 
     446             : struct DocumentRangeFormattingParams {
     447             :   /// The document to format.
     448             :   TextDocumentIdentifier textDocument;
     449             : 
     450             :   /// The range to format
     451             :   Range range;
     452             : 
     453             :   /// The format options
     454             :   FormattingOptions options;
     455             : };
     456             : bool fromJSON(const json::Expr &, DocumentRangeFormattingParams &);
     457             : 
     458             : struct DocumentOnTypeFormattingParams {
     459             :   /// The document to format.
     460             :   TextDocumentIdentifier textDocument;
     461             : 
     462             :   /// The position at which this request was sent.
     463             :   Position position;
     464             : 
     465             :   /// The character that has been typed.
     466             :   std::string ch;
     467             : 
     468             :   /// The format options.
     469             :   FormattingOptions options;
     470             : };
     471             : bool fromJSON(const json::Expr &, DocumentOnTypeFormattingParams &);
     472             : 
     473             : struct DocumentFormattingParams {
     474             :   /// The document to format.
     475             :   TextDocumentIdentifier textDocument;
     476             : 
     477             :   /// The format options
     478             :   FormattingOptions options;
     479             : };
     480             : bool fromJSON(const json::Expr &, DocumentFormattingParams &);
     481             : 
     482           0 : struct Diagnostic {
     483             :   /// The range at which the message applies.
     484             :   Range range;
     485             : 
     486             :   /// The diagnostic's severity. Can be omitted. If omitted it is up to the
     487             :   /// client to interpret diagnostics as error, warning, info or hint.
     488             :   int severity = 0;
     489             : 
     490             :   /// The diagnostic's code. Can be omitted.
     491             :   /// Note: Not currently used by clangd
     492             :   // std::string code;
     493             : 
     494             :   /// A human-readable string describing the source of this
     495             :   /// diagnostic, e.g. 'typescript' or 'super lint'.
     496             :   /// Note: Not currently used by clangd
     497             :   // std::string source;
     498             : 
     499             :   /// The diagnostic's message.
     500             :   std::string message;
     501             : };
     502             : 
     503             : /// A LSP-specific comparator used to find diagnostic in a container like
     504             : /// std:map.
     505             : /// We only use the required fields of Diagnostic to do the comparsion to avoid
     506             : /// any regression issues from LSP clients (e.g. VScode), see
     507             : /// https://git.io/vbr29
     508             : struct LSPDiagnosticCompare {
     509             :   bool operator()(const Diagnostic &LHS, const Diagnostic &RHS) const {
     510             :     return std::tie(LHS.range, LHS.message) < std::tie(RHS.range, RHS.message);
     511             :   }
     512             : };
     513             : bool fromJSON(const json::Expr &, Diagnostic &);
     514             : llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Diagnostic &);
     515             : 
     516             : struct CodeActionContext {
     517             :   /// An array of diagnostics.
     518             :   std::vector<Diagnostic> diagnostics;
     519             : };
     520             : bool fromJSON(const json::Expr &, CodeActionContext &);
     521             : 
     522             : struct CodeActionParams {
     523             :   /// The document in which the command was invoked.
     524             :   TextDocumentIdentifier textDocument;
     525             : 
     526             :   /// The range for which the command was invoked.
     527             :   Range range;
     528             : 
     529             :   /// Context carrying additional information.
     530             :   CodeActionContext context;
     531             : };
     532             : bool fromJSON(const json::Expr &, CodeActionParams &);
     533             : 
     534             : struct WorkspaceEdit {
     535             :   /// Holds changes to existing resources.
     536             :   llvm::Optional<std::map<std::string, std::vector<TextEdit>>> changes;
     537             : 
     538             :   /// Note: "documentChanges" is not currently used because currently there is
     539             :   /// no support for versioned edits.
     540             : };
     541             : bool fromJSON(const json::Expr &, WorkspaceEdit &);
     542             : json::Expr toJSON(const WorkspaceEdit &WE);
     543             : 
     544             : /// Exact commands are not specified in the protocol so we define the
     545             : /// ones supported by Clangd here. The protocol specifies the command arguments
     546             : /// to be "any[]" but to make this safer and more manageable, each command we
     547             : /// handle maps to a certain llvm::Optional of some struct to contain its
     548             : /// arguments. Different commands could reuse the same llvm::Optional as
     549             : /// arguments but a command that needs different arguments would simply add a
     550             : /// new llvm::Optional and not use any other ones. In practice this means only
     551             : /// one argument type will be parsed and set.
     552             : struct ExecuteCommandParams {
     553             :   // Command to apply fix-its. Uses WorkspaceEdit as argument.
     554             :   const static llvm::StringLiteral CLANGD_APPLY_FIX_COMMAND;
     555             : 
     556             :   /// The command identifier, e.g. CLANGD_APPLY_FIX_COMMAND
     557             :   std::string command;
     558             : 
     559             :   // Arguments
     560             :   llvm::Optional<WorkspaceEdit> workspaceEdit;
     561             : };
     562             : bool fromJSON(const json::Expr &, ExecuteCommandParams &);
     563             : 
     564             : struct Command : public ExecuteCommandParams {
     565             :   std::string title;
     566             : };
     567             : 
     568             : json::Expr toJSON(const Command &C);
     569             : 
     570             : /// Represents information about programming constructs like variables, classes,
     571             : /// interfaces etc.
     572           0 : struct SymbolInformation {
     573             :   /// The name of this symbol.
     574             :   std::string name;
     575             : 
     576             :   /// The kind of this symbol.
     577             :   SymbolKind kind;
     578             : 
     579             :   /// The location of this symbol.
     580             :   Location location;
     581             : 
     582             :   /// The name of the symbol containing this symbol.
     583             :   std::string containerName;
     584             : };
     585             : json::Expr toJSON(const SymbolInformation &);
     586             : llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SymbolInformation &);
     587             : 
     588             : /// The parameters of a Workspace Symbol Request.
     589             : struct WorkspaceSymbolParams {
     590             :   /// A non-empty query string
     591             :   std::string query;
     592             : };
     593             : bool fromJSON(const json::Expr &, WorkspaceSymbolParams &);
     594             : 
     595             : struct ApplyWorkspaceEditParams {
     596             :   WorkspaceEdit edit;
     597             : };
     598             : json::Expr toJSON(const ApplyWorkspaceEditParams &);
     599             : 
     600             : struct TextDocumentPositionParams {
     601             :   /// The text document.
     602             :   TextDocumentIdentifier textDocument;
     603             : 
     604             :   /// The position inside the text document.
     605             :   Position position;
     606             : };
     607             : bool fromJSON(const json::Expr &, TextDocumentPositionParams &);
     608             : 
     609             : enum class MarkupKind {
     610             :   PlainText,
     611             :   Markdown,
     612             : };
     613             : 
     614             : struct MarkupContent {
     615             :   MarkupKind kind = MarkupKind::PlainText;
     616             :   std::string value;
     617             : };
     618             : json::Expr toJSON(const MarkupContent &MC);
     619             : 
     620             : struct Hover {
     621             :   /// The hover's content
     622             :   MarkupContent contents;
     623             : 
     624             :   /// An optional range is a range inside a text document
     625             :   /// that is used to visualize a hover, e.g. by changing the background color.
     626             :   llvm::Optional<Range> range;
     627             : };
     628             : json::Expr toJSON(const Hover &H);
     629             : 
     630             : /// The kind of a completion entry.
     631             : enum class CompletionItemKind {
     632             :   Missing = 0,
     633             :   Text = 1,
     634             :   Method = 2,
     635             :   Function = 3,
     636             :   Constructor = 4,
     637             :   Field = 5,
     638             :   Variable = 6,
     639             :   Class = 7,
     640             :   Interface = 8,
     641             :   Module = 9,
     642             :   Property = 10,
     643             :   Unit = 11,
     644             :   Value = 12,
     645             :   Enum = 13,
     646             :   Keyword = 14,
     647             :   Snippet = 15,
     648             :   Color = 16,
     649             :   File = 17,
     650             :   Reference = 18,
     651             : };
     652             : 
     653             : /// Defines whether the insert text in a completion item should be interpreted
     654             : /// as plain text or a snippet.
     655             : enum class InsertTextFormat {
     656             :   Missing = 0,
     657             :   /// The primary text to be inserted is treated as a plain string.
     658             :   PlainText = 1,
     659             :   /// The primary text to be inserted is treated as a snippet.
     660             :   ///
     661             :   /// A snippet can define tab stops and placeholders with `$1`, `$2`
     662             :   /// and `${3:foo}`. `$0` defines the final tab stop, it defaults to the end
     663             :   /// of the snippet. Placeholders with equal identifiers are linked, that is
     664             :   /// typing in one will update others too.
     665             :   ///
     666             :   /// See also:
     667             :   /// https//github.com/Microsoft/vscode/blob/master/src/vs/editor/contrib/snippet/common/snippet.md
     668             :   Snippet = 2,
     669             : };
     670             : 
     671             : /// Provides details for how a completion item was scored.
     672             : /// This can be used for client-side filtering of completion items as the
     673             : /// user keeps typing.
     674             : /// This is a clangd extension.
     675             : struct CompletionItemScores {
     676             :   /// The score that items are ranked by.
     677             :   /// This is filterScore * symbolScore.
     678             :   float finalScore = 0.f;
     679             :   /// How the partial identifier matched filterText. [0-1]
     680             :   float filterScore = 0.f;
     681             :   /// How the symbol fits, ignoring the partial identifier.
     682             :   float symbolScore = 0.f;
     683             : };
     684             : 
     685           0 : struct CompletionItem {
     686             :   /// The label of this completion item. By default also the text that is
     687             :   /// inserted when selecting this completion.
     688             :   std::string label;
     689             : 
     690             :   /// The kind of this completion item. Based of the kind an icon is chosen by
     691             :   /// the editor.
     692             :   CompletionItemKind kind = CompletionItemKind::Missing;
     693             : 
     694             :   /// A human-readable string with additional information about this item, like
     695             :   /// type or symbol information.
     696             :   std::string detail;
     697             : 
     698             :   /// A human-readable string that represents a doc-comment.
     699             :   std::string documentation;
     700             : 
     701             :   /// A string that should be used when comparing this item with other items.
     702             :   /// When `falsy` the label is used.
     703             :   std::string sortText;
     704             : 
     705             :   /// Details about the quality of this completion item. (clangd extension)
     706             :   llvm::Optional<CompletionItemScores> scoreInfo;
     707             : 
     708             :   /// A string that should be used when filtering a set of completion items.
     709             :   /// When `falsy` the label is used.
     710             :   std::string filterText;
     711             : 
     712             :   /// A string that should be inserted to a document when selecting this
     713             :   /// completion. When `falsy` the label is used.
     714             :   std::string insertText;
     715             : 
     716             :   /// The format of the insert text. The format applies to both the `insertText`
     717             :   /// property and the `newText` property of a provided `textEdit`.
     718             :   InsertTextFormat insertTextFormat = InsertTextFormat::Missing;
     719             : 
     720             :   /// An edit which is applied to a document when selecting this completion.
     721             :   /// When an edit is provided `insertText` is ignored.
     722             :   ///
     723             :   /// Note: The range of the edit must be a single line range and it must
     724             :   /// contain the position at which completion has been requested.
     725             :   llvm::Optional<TextEdit> textEdit;
     726             : 
     727             :   /// An optional array of additional text edits that are applied when selecting
     728             :   /// this completion. Edits must not overlap with the main edit nor with
     729             :   /// themselves.
     730             :   std::vector<TextEdit> additionalTextEdits;
     731             : 
     732             :   // TODO(krasimir): The following optional fields defined by the language
     733             :   // server protocol are unsupported:
     734             :   //
     735             :   // data?: any - A data entry field that is preserved on a completion item
     736             :   //              between a completion and a completion resolve request.
     737             : };
     738             : json::Expr toJSON(const CompletionItem &);
     739             : llvm::raw_ostream &operator<<(llvm::raw_ostream &, const CompletionItem &);
     740             : 
     741             : bool operator<(const CompletionItem &, const CompletionItem &);
     742             : 
     743             : /// Represents a collection of completion items to be presented in the editor.
     744           0 : struct CompletionList {
     745             :   /// The list is not complete. Further typing should result in recomputing the
     746             :   /// list.
     747             :   bool isIncomplete = false;
     748             : 
     749             :   /// The completion items.
     750             :   std::vector<CompletionItem> items;
     751             : };
     752             : json::Expr toJSON(const CompletionList &);
     753             : 
     754             : /// A single parameter of a particular signature.
     755           0 : struct ParameterInformation {
     756             : 
     757             :   /// The label of this parameter. Mandatory.
     758             :   std::string label;
     759             : 
     760             :   /// The documentation of this parameter. Optional.
     761             :   std::string documentation;
     762             : };
     763             : json::Expr toJSON(const ParameterInformation &);
     764             : 
     765             : /// Represents the signature of something callable.
     766           0 : struct SignatureInformation {
     767             : 
     768             :   /// The label of this signature. Mandatory.
     769             :   std::string label;
     770             : 
     771             :   /// The documentation of this signature. Optional.
     772             :   std::string documentation;
     773             : 
     774             :   /// The parameters of this signature.
     775             :   std::vector<ParameterInformation> parameters;
     776             : };
     777             : json::Expr toJSON(const SignatureInformation &);
     778             : llvm::raw_ostream &operator<<(llvm::raw_ostream &,
     779             :                               const SignatureInformation &);
     780             : 
     781             : /// Represents the signature of a callable.
     782           0 : struct SignatureHelp {
     783             : 
     784             :   /// The resulting signatures.
     785             :   std::vector<SignatureInformation> signatures;
     786             : 
     787             :   /// The active signature.
     788             :   int activeSignature = 0;
     789             : 
     790             :   /// The active parameter of the active signature.
     791             :   int activeParameter = 0;
     792             : };
     793             : json::Expr toJSON(const SignatureHelp &);
     794             : 
     795             : struct RenameParams {
     796             :   /// The document that was opened.
     797             :   TextDocumentIdentifier textDocument;
     798             : 
     799             :   /// The position at which this request was sent.
     800             :   Position position;
     801             : 
     802             :   /// The new name of the symbol.
     803             :   std::string newName;
     804             : };
     805             : bool fromJSON(const json::Expr &, RenameParams &);
     806             : 
     807             : enum class DocumentHighlightKind { Text = 1, Read = 2, Write = 3 };
     808             : 
     809             : /// A document highlight is a range inside a text document which deserves
     810             : /// special attention. Usually a document highlight is visualized by changing
     811             : /// the background color of its range.
     812             : 
     813           0 : struct DocumentHighlight {
     814             :   /// The range this highlight applies to.
     815             :   Range range;
     816             : 
     817             :   /// The highlight kind, default is DocumentHighlightKind.Text.
     818             :   DocumentHighlightKind kind = DocumentHighlightKind::Text;
     819             : 
     820             :   friend bool operator<(const DocumentHighlight &LHS,
     821             :                         const DocumentHighlight &RHS) {
     822             :     int LHSKind = static_cast<int>(LHS.kind);
     823             :     int RHSKind = static_cast<int>(RHS.kind);
     824             :     return std::tie(LHS.range, LHSKind) < std::tie(RHS.range, RHSKind);
     825             :   }
     826             : 
     827             :   friend bool operator==(const DocumentHighlight &LHS,
     828             :                          const DocumentHighlight &RHS) {
     829           0 :     return LHS.kind == RHS.kind && LHS.range == RHS.range;
     830             :   }
     831             : };
     832             : json::Expr toJSON(const DocumentHighlight &DH);
     833             : llvm::raw_ostream &operator<<(llvm::raw_ostream &, const DocumentHighlight &);
     834             : 
     835             : } // namespace clangd
     836             : } // namespace clang
     837             : 
     838             : namespace llvm {
     839             : template <> struct format_provider<clang::clangd::Position> {
     840             :   static void format(const clang::clangd::Position &Pos, raw_ostream &OS,
     841             :                      StringRef Style) {
     842             :     assert(Style.empty() && "style modifiers for this type are not supported");
     843             :     OS << Pos;
     844             :   }
     845             : };
     846             : } // namespace llvm
     847             : 
     848             : #endif

Generated by: LCOV version 1.13