23 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROTOCOL_H 24 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROTOCOL_H 28 #include "clang/Index/IndexSymbol.h" 29 #include "llvm/ADT/Optional.h" 30 #include "llvm/Support/JSON.h" 31 #include "llvm/Support/raw_ostream.h" 55 class LSPError :
public llvm::ErrorInfo<LSPError> {
62 : Message(std::move(Message)), Code(Code) {}
64 void log(llvm::raw_ostream &OS)
const override {
65 OS << int(Code) <<
": " <<
Message;
68 return llvm::inconvertibleErrorCode();
87 llvm::StringRef TUPath);
89 static llvm::Expected<URIForFile> fromURI(
const URI &U,
90 llvm::StringRef HintPath);
95 explicit operator bool()
const {
return !
File.empty(); }
99 return LHS.File == RHS.File;
103 return !(LHS == RHS);
107 return LHS.File < RHS.File;
141 return !(LHS == RHS);
167 return !(LHS == RHS);
175 return start <= Rng.
start && Rng.
end <= end;
192 return !(LHS == RHS);
376 bool DiagnosticFixes =
false;
385 bool DiagnosticCategory =
false;
389 bool CompletionSnippets =
false;
394 bool CompletionFixes =
false;
398 bool HierarchicalDocumentSymbol =
false;
402 bool HasSignatureHelp =
false;
406 bool OffsetsInSignatureHelp =
false;
414 bool CodeActionStructure =
false;
418 bool SemanticHighlighting =
false;
429 bool RenamePrepareSupport =
false;
715 llvm::Optional<std::map<std::string, std::vector<TextEdit>>>
changes;
777 llvm::Optional<std::string>
kind;
786 llvm::Optional<WorkspaceEdit>
edit;
859 llvm::Optional<SymbolID>
ID;
996 bool deprecated =
false;
1013 bool isIncomplete =
false;
1050 llvm::raw_ostream &
operator<<(llvm::raw_ostream &,
1060 int activeSignature = 0;
1063 int activeParameter = 0;
1101 int LHSKind =
static_cast<int>(LHS.
kind);
1102 int RHSKind =
static_cast<int>(RHS.
kind);
1103 return std::tie(LHS.
range, LHSKind) < std::tie(RHS.
range, RHSKind);
1141 bool deprecated =
false;
1160 llvm::Optional<std::vector<TypeHierarchyItem>>
parents;
1165 llvm::Optional<std::vector<TypeHierarchyItem>>
children;
1216 bool IsInactive =
false;
1227 std::vector<SemanticHighlightingInformation>
Lines;
1281 return !(LHS == RHS);
1290 template <>
struct format_provider<
clang::clangd::Position> {
1293 assert(Style.empty() &&
"style modifiers for this type are not supported");
std::string insertText
A string that should be inserted to a document when selecting this completion.
std::string USR
Unified Symbol Resolution identifier This is an opaque string uniquely identifying a symbol...
const tooling::CompileCommand & Command
friend bool operator<(const Location &LHS, const Location &RHS)
llvm::Optional< std::vector< TypeHierarchyItem > > children
If this type hierarchy item is resolved, it contains the direct children of the current item...
URIForFile uri
The file's URI.
std::string code
The diagnostic's code. Can be omitted.
TextDocumentIdentifier textDocument
The document to provide document links for.
llvm::json::Value toJSON(const FuzzyFindRequest &Request)
friend bool operator==(const Location &LHS, const Location &RHS)
llvm::Optional< TextEdit > textEdit
An edit which is applied to a document when selecting this completion.
Exact commands are not specified in the protocol so we define the ones supported by Clangd here...
llvm::Optional< SymbolKindBitset > WorkspaceSymbolKinds
The supported set of SymbolKinds for workspace/symbol.
Some operations such as code completion produce a set of candidates.
llvm::Optional< URIForFile > rootUri
The rootUri of the workspace.
Position start
The range's start position.
friend bool operator==(const URIForFile &LHS, const URIForFile &RHS)
ConfigurationSettings settings
Represents a collection of completion items to be presented in the editor.
Range range
The range this highlight applies to.
llvm::Optional< bool > wantDiagnostics
Forces diagnostics to be generated, or to not be generated, for this version of the file...
friend bool operator<=(const Position &LHS, const Position &RHS)
std::vector< std::string > compilationCommand
Range range
The range for which the command was invoked.
CodeActionContext context
Context carrying additional information.
static const llvm::StringLiteral CLANGD_APPLY_FIX_COMMAND
Clangd extension: parameters configurable at initialize time.
std::vector< CompletionItem > items
The completion items.
bool operator==(const HoverInfo::Param &LHS, const HoverInfo::Param &RHS)
Documents are synced by always sending the full content of the document.
friend bool operator!=(const DocumentLink &LHS, const DocumentLink &RHS)
Documents are synced by sending the full content on open.
llvm::Optional< std::vector< CodeAction > > codeActions
Clangd extension: code actions related to this diagnostic.
clang::find_all_symbols::SymbolInfo::SymbolKind SymbolKind
llvm::Optional< std::map< std::string, std::vector< TextEdit > > > changes
Holds changes to existing resources.
llvm::Optional< std::string > kind
The kind of the code action.
bool operator()(const Diagnostic &LHS, const Diagnostic &RHS) const
std::string title
A short, human-readable, title for this code action.
llvm::Optional< Range > range
An optional range is a range inside a text document that is used to visualize a hover, e.g.
TextDocumentIdentifier textDocument
The document that was closed.
std::vector< Position > positions
The positions inside the text document.
SymbolKind indexSymbolKindToSymbolKind(index::SymbolKind Kind)
std::string tweakID
ID of the tweak that should be executed. Corresponds to Tweak::id().
std::string state
The human-readable string presents the current state of the file, can be shown in the UI (e...
An Event<T> allows events of type T to be broadcast to listeners.
llvm::Optional< std::string > data
An optional 'data' filed, which can be used to identify a type hierarchy item in a resolve request...
A code action represents a change that can be performed in code, e.g.
constexpr llvm::StringLiteral Message
friend bool operator!=(const URIForFile &LHS, const URIForFile &RHS)
URIForFile uri
The text document's URI.
std::string text
The new text of the range/document.
friend bool operator!=(const Position &LHS, const Position &RHS)
URIForFile target
The uri this link points to. If missing a resolve request is sent later.
llvm::Optional< WorkspaceEdit > edit
The workspace edit this code action performs.
Range selectionRange
The range that should be selected and revealed when this symbol is being picked, e.g the name of a function.
Values in a Context are indexed by typed keys.
constexpr auto SymbolKindMin
The show message notification is sent from a server to a client to ask the client to display a partic...
llvm::Optional< std::string > compilationDatabasePath
std::string sortText
A string that should be used when comparing this item with other items.
constexpr auto CompletionItemKindMin
std::string name
The human readable name of the hierarchy item.
friend bool operator!=(const Range &LHS, const Range &RHS)
std::bitset< CompletionItemKindMax+1 > CompletionItemKindBitset
Documents should not be synced at all.
Range selectionRange
The range that should be selected and revealed when this type hierarchy item is being picked...
std::string documentation
A human-readable string that represents a doc-comment.
InsertTextFormat
Defines whether the insert text in a completion item should be interpreted as plain text or a snippet...
Range range
The range enclosing this symbol not including leading/trailing whitespace but everything else like co...
URIForFile uri
The text document's URI.
std::vector< TextEdit > additionalTextEdits
An optional array of additional text edits that are applied when selecting this completion.
constexpr auto CompletionItemKindMax
Represents programming constructs like variables, classes, interfaces etc.
static const llvm::StringLiteral CLANGD_APPLY_TWEAK
llvm::Optional< int > processId
The process Id of the parent process that started the server.
Range range
The range enclosing this type hierarchy item not including leading/trailing whitespace but everything...
CompletionItemKind
The kind of a completion entry.
ConfigurationSettings ConfigSettings
TextDocumentIdentifier TextDocument
The textdocument these highlightings belong to.
TextDocumentSyncKind
Defines how the host (editor) should sync document changes to the language server.
TextDocumentIdentifier textDocument
The text document.
MarkupContent contents
The hover's content.
std::error_code convertToErrorCode() const override
A document highlight is a range inside a text document which deserves special attention.
URIForFile uri
The text document's URI.
std::string detail
A human-readable string with additional information about this item, like type or symbol information...
friend bool operator==(const DocumentLink &LHS, const DocumentLink &RHS)
llvm::Optional< SymbolID > ID
std::string source
A human-readable string describing the source of this diagnostic, e.g.
llvm::Optional< TweakArgs > tweakArgs
LSPError(std::string Message, ErrorCode Code)
static URI createFile(llvm::StringRef AbsolutePath)
This creates a file:// URI for AbsolutePath. The path must be absolute.
TextDocumentIdentifier textDocument
The document that was opened.
std::string newText
The string to be inserted.
Parameters for the semantic highlighting (server-side) push notification.
std::string newName
The new name of the symbol.
Clangd extension: parameters configurable at any time, via the workspace/didChangeConfiguration notif...
std::string command
The command identifier, e.g. CLANGD_APPLY_FIX_COMMAND.
InitializationOptions initializationOptions
User-provided initialization options.
TextDocumentIdentifier textDocument
std::string filterText
A string that should be used when filtering a set of completion items.
bool operator<(const Ref &L, const Ref &R)
friend bool operator<(const Position &LHS, const Position &RHS)
TextDocumentIdentifier textDocument
The document in which the command was invoked.
Range range
The range of the text document to be manipulated.
std::vector< std::string > fallbackFlags
friend bool operator<(const Range &LHS, const Range &RHS)
llvm::Optional< Range > range
The range of the document that changed.
llvm::Optional< std::string > category
The diagnostic's category.
Position position
The position inside the text document.
URIForFile file
A file provided by the client on a textDocument/codeAction request.
std::string containerName
std::vector< DocumentSymbol > children
Children of this symbol, e.g. properties of a class.
Position argListStart
Position of the start of the argument list, including opening paren.
static const llvm::StringLiteral REFACTOR_KIND
std::vector< SignatureInformation > signatures
The resulting signatures.
llvm::Optional< int > rangeLength
The length of the range that got replaced.
static llvm::SmallString< 128 > canonicalize(llvm::StringRef Path)
std::string name
The name of this symbol.
Completion was triggered by typing an identifier (24x7 code complete), manual invocation (e...
ClientCapabilities capabilities
The capabilities provided by the client (editor or tool)
TextDocumentItem textDocument
The document that was opened.
llvm::Optional< std::string > detail
Optional detail for the hierarchy item.
TextDocumentIdentifier textDocument
The document that did change.
std::map< std::string, ClangdCompileCommand > compilationDatabaseChanges
std::string detail
More detail for this symbol, e.g the signature of a function.
Completion was triggered by a trigger character specified by the triggerCharacters properties of the ...
std::vector< FileEvent > changes
The actual file events.
std::vector< SemanticHighlightingInformation > Lines
The lines of highlightings that should be sent.
llvm::Optional< CompletionItemKindBitset > CompletionItemKinds
The supported set of CompletionItemKinds for textDocument/completion.
std::string languageId
The text document's language identifier.
llvm::Optional< std::string > rootPath
The rootPath of the workspace.
bool fromJSON(const llvm::json::Value &Parameters, FuzzyFindRequest &Request)
A LSP-specific comparator used to find diagnostic in a container like std:map.
int line
Line position in a document (zero-based).
std::vector< TextDocumentContentChangeEvent > contentChanges
The actual content changes.
friend bool operator<(const DocumentHighlight &LHS, const DocumentHighlight &RHS)
int character
Character offset on a line in a document (zero-based).
TypeHierarchyDirection direction
The direction of the hierarchy levels to resolve.
CompletionContext context
bool contains(Position Pos) const
Represents the signature of a callable.
std::string query
A non-empty query string.
SymbolKind kind
The kind of this symbol.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::bitset< SymbolKindMax+1 > SymbolKindBitset
std::string message
The diagnostic's message.
std::string triggerCharacter
The trigger character (a single character) that has trigger code complete.
TextDocumentIdentifier textDocument
The text document.
static const llvm::StringLiteral INFO_KIND
std::string label
The label of this completion item.
friend bool operator==(const DocumentHighlight &LHS, const DocumentHighlight &RHS)
The type hierarchy params is an extension of the TextDocumentPositionsParams with optional properties...
Range range
The range of this selection range.
DocumentHighlightKind kind
The highlight kind, default is DocumentHighlightKind.Text.
SymbolKind adjustKindToCapability(SymbolKind Kind, SymbolKindBitset &SupportedSymbolKinds)
static const llvm::StringLiteral QUICKFIX_KIND
bool contains(Range Rng) const
A URI describes the location of a source file.
Range selection
A selection provided by the client on a textDocument/codeAction request.
std::vector< Diagnostic > diagnostics
An array of diagnostics.
bool deprecated
Indicates if this symbol is deprecated.
llvm::Optional< Command > command
A command this code action executes.
The parameters of a Workspace Symbol Request.
llvm::Optional< std::vector< TypeHierarchyItem > > parents
If this type hierarchy item is resolved, it contains the direct parents.
Parameters for the typeHierarchy/resolve request.
std::string workingDirectory
std::string text
The content of the opened text document.
Clangd extension: indicates the current state of the file in clangd, sent from server via the textDoc...
llvm::Optional< std::vector< Diagnostic > > diagnostics
The diagnostics that this code action resolves.
SymbolKind kind
The kind of the hierarchy item. For instance, class or interface.
Position position
The position at which this request was sent.
URIForFile uri
The text document's URI.
std::string message
The actual message.
Parameters for the document link request.
friend bool operator!=(const Location &LHS, const Location &RHS)
TypeHierarchyItem item
The item to resolve.
llvm::Optional< std::string > failureReason
Range range
The range at which the message applies.
friend bool operator<(const URIForFile &LHS, const URIForFile &RHS)
A range in a text document that links to an internal or external resource, like another text document...
std::unique_ptr< SelectionRange > parent
The parent selection range containing this range.
Position end
The range's end position.
llvm::Optional< WorkspaceEdit > workspaceEdit
int resolve
The hierarchy levels to resolve. 0 indicates no level.
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const CodeCompletion &C)
URIForFile uri
The URI of the text document where this type hierarchy item belongs to.
Completion was re-triggered as the current completion list is incomplete.
std::string toString() const
Returns a string URI with all components percent-encoded.
Clangd extension that's used in the 'compilationDatabaseChanges' in workspace/didChangeConfiguration ...
friend bool operator==(const Position &LHS, const Position &RHS)
Arguments for the 'applyTweak' command.
void log(llvm::raw_ostream &OS) const override
llvm::Optional< std::vector< DiagnosticRelatedInformation > > relatedInformation
An array of related diagnostic information, e.g.
friend bool operator==(const Range &LHS, const Range &RHS)
Represents information about identifier.
Range range
The range this link applies to.
constexpr auto SymbolKindMax
llvm::Optional< std::vector< OffsetEncoding > > offsetEncoding
Supported encodings for LSP character offsets. (clangd extension).
llvm::Optional< TraceLevel > trace
The initial trace setting. If omitted trace is disabled ('off').
llvm::StringRef file() const
Retrieves absolute path to the file.