Go to the documentation of this file.
23 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROTOCOL_H
24 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROTOCOL_H
29 #include "clang/Index/IndexSymbol.h"
30 #include "llvm/ADT/SmallVector.h"
31 #include "llvm/Support/JSON.h"
32 #include "llvm/Support/raw_ostream.h"
63 class LSPError :
public llvm::ErrorInfo<LSPError> {
72 void log(llvm::raw_ostream &
OS)
const override {
76 return llvm::inconvertibleErrorCode();
98 llvm::StringRef TUPath);
100 static llvm::Expected<URIForFile>
fromURI(
const URI &U,
101 llvm::StringRef HintPath);
104 llvm::StringRef
file()
const {
return File; }
106 explicit operator bool()
const {
return !File.empty(); }
110 return LHS.File == RHS.File;
114 return !(LHS == RHS);
118 return LHS.File < RHS.File;
122 explicit URIForFile(std::string &&File) : File(std::move(File)) {}
170 return !(LHS == RHS);
183 llvm::raw_ostream &
operator<<(llvm::raw_ostream &,
const Position &);
196 return !(LHS == RHS);
221 return !(LHS == RHS);
251 return std::tie(L.newText, L.range) == std::tie(R.
newText, R.
range);
255 llvm::raw_ostream &
operator<<(llvm::raw_ostream &,
const TextEdit &);
611 return llvm::json::Object{{
"token", P.
token}, {
"value", P.
value}};
891 llvm::SmallVector<DiagnosticTag, 1>
tags;
971 std::map<std::string, std::vector<TextEdit>>
changes;
1334 llvm::raw_ostream &
operator<<(llvm::raw_ostream &,
1385 int LHSKind =
static_cast<int>(LHS.
kind);
1386 int RHSKind =
static_cast<int>(RHS.
kind);
1387 return std::tie(LHS.
range, LHSKind) < std::tie(RHS.
range, RHSKind);
1396 llvm::raw_ostream &
operator<<(llvm::raw_ostream &,
const DocumentHighlight &);
1442 std::optional<std::vector<ResolveParams>>
parents;
1455 std::optional<std::vector<TypeHierarchyItem>>
parents;
1461 std::optional<std::vector<TypeHierarchyItem>>
children;
1733 std::optional<std::vector<SemanticTokensEdit>>
edits;
1735 std::optional<std::vector<SemanticToken>>
tokens;
1791 return !(LHS == RHS);
1883 template <>
struct format_provider<
clang::clangd::Position> {
1886 assert(Style.empty() &&
"style modifiers for this type are not supported");
bool includeDeclaration
Include the declaration of the current symbol.
Range selectionRange
The range that should be selected and revealed when this symbol is being picked, e....
A document highlight is a range inside a text document which deserves special attention.
CharSourceRange Range
SourceRange for the file name.
std::optional< std::vector< OffsetEncoding > > offsetEncoding
Supported encodings for LSP character offsets. (clangd extension).
Range selectionRange
The range that should be selected and revealed when this symbol is being picked, e....
bool paddingLeft
Render padding before the hint.
bool isIncomplete
The list is not complete.
@ Warning
A warning message.
Range range
The range enclosing this symbol not including leading/trailing whitespace but everything else like co...
@ Designator
A hint before an element of an aggregate braced initializer list, indicating what it is initializing.
TypeHierarchyDirection direction
The direction of the hierarchy levels to resolve.
constexpr auto SymbolKindMax
TextDocumentItem textDocument
The document that was opened.
std::string source
A human-readable string describing the source of this diagnostic, e.g.
Some operations such as code completion produce a set of candidates.
std::error_code convertToErrorCode() const override
std::string label
The label of this hint.
constexpr auto SymbolKindMin
URIForFile uri
The text document's URI.
Clangd extension that's used in the 'compilationDatabaseChanges' in workspace/didChangeConfiguration ...
std::string workingDirectory
bool DiagnosticFixes
Whether the client accepts diagnostics with codeActions attached inline.
LSPError(std::string Message, ErrorCode Code)
std::string previousResultId
The previous result id.
unsigned tokenModifiers
each set bit will be looked up in SemanticTokensLegend.tokenModifiers
Body of textDocument/semanticTokens/full request.
URIForFile uri
The text document's URI.
std::optional< SymbolKindBitset > WorkspaceSymbolKinds
The supported set of SymbolKinds for workspace/symbol.
std::vector< Diagnostic > diagnostics
An array of diagnostic information items.
URIForFile uri
The file's URI.
std::optional< int > processId
The process Id of the parent process that started the server.
std::optional< Range > range
An optional range is a range inside a text document that is used to visualize a hover,...
bool DiagnosticCategory
Whether the client accepts diagnostics with category attached to it using the "category" extension.
InlayHintKind kind
The kind of this hint.
@ TriggerTriggerForIncompleteCompletions
Completion was re-triggered as the current completion list is incomplete.
URIForFile uri
The resource identifier of this item.
MessageType type
The message type.
int resolve
The hierarchy levels to resolve. 0 indicates no level.
TextDocumentIdentifier textDocument
The text document.
std::string detail
More detaill for this item, e.g. the signature of a function.
A code action represents a change that can be performed in code, e.g.
Body of textDocument/semanticTokens/full/delta request.
std::optional< std::vector< TypeHierarchyItem > > parents
This is a clangd exntesion.
friend bool operator==(const DocumentHighlight &LHS, const DocumentHighlight &RHS)
bool deprecated
Indicates if this item is deprecated.
T value
The progress data.
std::string detail
Brief additional information, such as "||" for the particular operator.
Represents a collection of completion items to be presented in the editor.
bool CompletionFixes
Client supports completions with additionalTextEdit near the cursor.
@ PlainText
The primary text to be inserted is treated as a plain string.
std::vector< std::string > only
Requested kind of actions to return.
Describes a replacement of a contiguous range of semanticTokens.
This models LSP SemanticTokensDelta | SemanticTokens, which is the result of textDocument/semanticTok...
std::vector< Position > positions
The positions inside the text document.
friend bool operator<(const Location &LHS, const Location &RHS)
bool isPreferred
Marks this as a preferred action.
CallHierarchyItem to
The item that is called.
ConfigurationSettings settings
std::string label
The label of this completion item.
std::optional< std::vector< Diagnostic > > diagnostics
The diagnostics that this code action resolves.
bool paddingRight
Render padding after the hint.
bool HierarchicalDocumentSymbol
Client supports hierarchical document symbols.
friend bool operator<(const Range &LHS, const Range &RHS)
Position start
The range's start position.
std::optional< std::string > rootPath
The rootPath of the workspace.
std::optional< int64_t > version
The version number of this document (it will strictly increase after each change, including undo/redo...
std::optional< bool > wantDiagnostics
Forces diagnostics to be generated, or to not be generated, for this version of the file.
bool forceRebuild
Force a complete rebuild of the file, ignoring all cached state.
std::optional< Command > command
A command this code action executes.
MarkupKind CompletionDocumentationFormat
The documentation format that should be used for textDocument/completion.
@ Created
The file got created.
TextDocumentSyncKind
Defines how the host (editor) should sync document changes to the language server.
std::vector< SymbolTag > tags
Tags for this item.
SymbolKind kind
The kind of this item.
A range in a text document that links to an internal or external resource, like another text document...
bool CompletionSnippets
Client supports snippets as insert text.
float score
The score that clangd calculates to rank the returned completions.
std::optional< std::string > detail
More detail for this item, e.g. the signature of a function.
@ None
Documents should not be synced at all.
unsigned deltaLine
token line number, relative to the previous token
Extends Locations returned by textDocument/references with extra info.
Range range
The range this highlight applies to.
static llvm::Expected< URIForFile > fromURI(const URI &U, llvm::StringRef HintPath)
const static llvm::StringLiteral COMMENT_KIND
Position argListStart
Position of the start of the argument list, including opening paren.
std::string tweakID
ID of the tweak that should be executed. Corresponds to Tweak::id().
std::optional< std::string > message
Optional, a final message indicating to for example indicate the outcome of the operation.
friend bool operator<=(const Position &LHS, const Position &RHS)
TextDocumentIdentifier textDocument
The document in which the command was invoked.
CodeActionContext context
Context carrying additional information.
bool contains(Range Rng) const
friend bool operator<(const URIForFile &LHS, const URIForFile &RHS)
std::string kind
The specific kind of node this is, such as "BinaryOperator".
Represents an incoming call, e.g. a caller of a method or constructor.
std::string filterText
A string that should be used when filtering a set of completion items.
friend bool operator==(const Position &LHS, const Position &RHS)
llvm::json::Object rawCapabilities
The same data as capabilities, but not parsed (to expose to modules).
std::vector< DocumentSymbol > children
Children of this symbol, e.g. properties of a class.
std::bitset< SymbolKindMax+1 > SymbolKindBitset
std::optional< std::vector< CodeAction > > codeActions
Clangd extension: code actions related to this diagnostic.
void log(llvm::raw_ostream &OS) const override
std::string containerName
Range range
The range enclosing this symbol not including leading/trailing whitespace but everything else,...
bool cancellable
Controls if a cancel button should show to allow the user to cancel the long-running operation.
The parameter of a textDocument/prepareCallHierarchy request.
Position position
The position at which this request was sent.
Range range
The range at which the message applies.
std::optional< std::vector< ResolveParams > > parents
None means parents aren't resolved and empty is no parents.
std::bitset< CompletionItemKindMax+1 > CompletionItemKindBitset
int line
Line position in a document (zero-based).
To start progress reporting a $/progress notification with the following payload must be sent.
std::string title
A short, human-readable, title for this code action.
DocumentHighlightKind kind
The highlight kind, default is DocumentHighlightKind.Text.
std::optional< bool > cancellable
Controls enablement state of a cancel button.
std::optional< std::vector< SemanticTokensEdit > > edits
Set if we computed edits relative to a previous set of tokens.
std::map< std::string, std::vector< TextEdit > > changes
Holds changes to existing resources.
URIForFile uri
The text document's URI.
Signals the end of progress reporting.
bool OffsetsInSignatureHelp
Client supports processing label offsets instead of a simple label string.
std::string triggerCharacter
The trigger character (a single character) that has trigger code complete.
const static llvm::StringLiteral REGION_KIND
ClientCapabilities capabilities
The capabilities provided by the client (editor or tool)
std::string title
Mandatory title of the progress operation.
DiagnosticCallback Diagnostic
std::vector< SemanticToken > tokens
The actual tokens.
ConfigurationSettings ConfigSettings
llvm::json::Value argument
std::optional< std::vector< TypeHierarchyItem > > children
If this type hierarchy item is resolved, it contains the direct children of the current item.
llvm::SmallVector< DiagnosticTag, 1 > tags
Additional metadata about the diagnostic.
std::vector< Range > fromRanges
The range at which the calls appear.
std::string state
The human-readable string presents the current state of the file, can be shown in the UI (e....
bool RenamePrepareSupport
The client supports testing for validity of rename operations before execution.
MarkupKind HoverContentFormat
The content format that should be used for Hover requests.
Arguments for the 'applyTweak' command.
MarkupKind SignatureHelpDocumentationFormat
The documentation format that should be used for textDocument/signatureHelp.
std::optional< Range > range
The range of the original source file covered by this node.
Specifies a single semantic token in the document.
A tree that can be used to represent memory usage of nested components while preserving the hierarchy...
friend bool operator==(const Range &LHS, const Range &RHS)
bool LineFoldingOnly
Client signals that it only supports folding complete lines.
std::optional< WorkspaceEdit > edit
The workspace edit this code action performs.
std::string insertText
A string that should be inserted to a document when selecting this completion.
std::vector< SignatureInformation > signatures
The resulting signatures.
TextDocumentIdentifier textDocument
std::optional< int64_t > version
The version number of the document the diagnostics are published for.
std::string role
The general kind of node, such as "expression" Corresponds to the base AST node type such as Expr.
URIForFile uri
The URI for which diagnostic information is reported.
llvm::json::Value toJSON(const FuzzyFindRequest &Request)
std::vector< CompletionItem > items
The completion items.
friend bool operator!=(const Location &LHS, const Location &RHS)
unsigned deltaStart
token start character, relative to the previous token (relative to 0 or the previous token's start if...
CompletionItemKind kind
The kind of this completion item.
std::string name
The name of this item.
unsigned tokenType
will be looked up in SemanticTokensLegend.tokenTypes
@ Deleted
The file got deleted.
Represents an outgoing call, e.g.
bool fromJSON(const llvm::json::Value &Parameters, FuzzyFindRequest &Request, llvm::json::Path P)
std::string detail
More detail for this symbol, e.g the signature of a function.
llvm::json::Value token
The token to be used to report progress.
URIForFile file
A file provided by the client on a textDocument/codeAction request.
friend bool operator==(const Location &LHS, const Location &RHS)
URIForFile uri
The text document's URI.
std::string data
An optional 'data' field, which can be used to identify a call hierarchy item in an incomingCalls or ...
std::optional< std::vector< SemanticToken > > tokens
Set if we computed a fresh set of tokens.
std::string command
The identifier of the actual command handler.
TextDocumentIdentifier textDocument
SymbolKind indexSymbolKindToSymbolKind(index::SymbolKind Kind)
llvm::json::Object data
A data entry field that is preserved between a textDocument/publishDiagnostics notification and textD...
Range selectionRange
The range that should be selected and revealed when this symbol is being picked, e....
SymbolKind
The SymbolInfo Type.
Structure to capture a description for an error code.
std::string languageId
The text document's language identifier.
std::string sortText
A string that should be used when comparing this item with other items.
int character
Character offset on a line in a document (zero-based).
CompletionTriggerKind triggerKind
How the completion was triggered.
@ Invoked
Completion was triggered by typing an identifier (24x7 code complete), manual invocation (e....
Position position
The position inside the text document.
Position end
The range's end position.
std::vector< std::string > fallbackFlags
Values in a Context are indexed by typed keys.
std::array< uint8_t, 20 > SymbolID
constexpr auto CompletionItemKindMax
Represents programming constructs like variables, classes, interfaces etc.
unsigned length
the length of the token. A token cannot be multiline
std::vector< FileEvent > changes
The actual file events.
std::optional< std::string > compilationDatabasePath
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const CodeCompletion &C)
CompletionItemKind
The kind of a completion entry.
friend bool operator==(const URIForFile &LHS, const URIForFile &RHS)
URIForFile uri
The resource identifier of this item.
std::optional< unsigned > percentage
Optional progress percentage to display (value 100 is considered 100%).
Represents information about identifier.
Clangd extension: parameters configurable at any time, via the workspace/didChangeConfiguration notif...
Parameters for the document link request.
std::string USR
Unified Symbol Resolution identifier This is an opaque string uniquely identifying a symbol.
@ Incremental
Documents are synced by sending the full content on open.
@ Full
Documents are synced by always sending the full content of the document.
clang::find_all_symbols::SymbolInfo::SymbolKind SymbolKind
std::optional< std::string > message
Optional, more detailed associated progress message.
int activeSignature
The active signature.
std::string text
The content of the opened text document.
InitializationOptions initializationOptions
User-provided initialization options.
bool operator()(const Diagnostic &LHS, const Diagnostic &RHS) const
@ Deprecated
Deprecated or obsolete code.
std::optional< std::string > kind
The kind of the code action.
The parameter of a callHierarchy/incomingCalls request.
std::vector< Diagnostic > diagnostics
An array of diagnostics known on the client side overlapping the range provided to the textDocument/c...
TextDocumentIdentifier textDocument
The text document.
std::optional< TextEdit > textEdit
An edit which is applied to a document when selecting this completion.
bool ReferenceContainer
Client supports displaying a container string for results of textDocument/reference (clangd extension...
Reporting progress is done using the following payload.
std::optional< Location > definitionRange
InsertTextFormat insertTextFormat
The format of the insert text.
bool WorkDoneProgress
The client supports progress notifications.
std::vector< TextEdit > additionalTextEdits
An optional array of additional text edits that are applied when selecting this completion.
std::optional< int > rangeLength
The length of the range that got replaced.
std::optional< Range > range
The visible document range for which inlay hints should be computed.
friend bool operator<(const DocumentHighlight &LHS, const DocumentHighlight &RHS)
MarkupContent contents
The hover's content.
std::string toString() const
Returns a string URI with all components percent-encoded.
@ Type
An inlay hint that for a type annotation.
std::map< std::string, ClangdCompileCommand > compilationDatabaseChanges
std::optional< std::string > failureReason
bool deprecated
true if the hierarchy item is deprecated.
bool SemanticTokenRefreshSupport
Whether the client implementation supports a refresh request sent from the server to the client.
bool CodeActionStructure
Client supports CodeAction return value for textDocument/codeAction.
Payload for textDocument/ast request.
SymbolKind kind
The kind of this symbol.
Range range
The range of this selection range.
bool percentage
Optional progress percentage to display (value 100 is considered 100%).
std::vector< TextDocumentContentChangeEvent > contentChanges
The actual content changes.
VersionedTextDocumentIdentifier textDocument
The document that did change.
The type hierarchy params is an extension of the TextDocumentPositionsParams with optional properties...
TextDocumentIdentifier textDocument
The text document.
friend bool operator<(const Position &LHS, const Position &RHS)
TextDocumentIdentifier textDocument
The document that was saved.
The parameters of a Workspace Symbol Request.
std::vector< SemanticToken > tokens
const static llvm::StringLiteral IMPORT_KIND
std::vector< std::string > compilationCommand
std::string detail
A human-readable string with additional information about this item, like type or symbol information.
FileChangeType type
The change type.
Represents the signature of a callable.
A versioned set of tokens.
friend bool operator!=(const URIForFile &LHS, const URIForFile &RHS)
std::string message
The actual message.
std::string message
The diagnostic's message.
friend bool operator!=(const Range &LHS, const Range &RHS)
std::unique_ptr< SelectionRange > parent
The parent selection range containing this range.
static URIForFile canonicalize(llvm::StringRef AbsPath, llvm::StringRef TUPath)
Canonicalizes AbsPath via URI.
@ Info
An information message.
Used to resolve a client provided item back.
int severity
The diagnostic's severity.
llvm::json::Value token
The progress token provided by the client or server.
std::optional< int > limit
Max results to return, overriding global default.
std::optional< std::string > category
The diagnostic's category.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::raw_string_ostream OS
Stores information about a region of code that can be folded.
std::optional< Range > range
The range of the document that changed.
const static llvm::StringLiteral REFACTOR_KIND
friend bool operator==(const DocumentLink &LHS, const DocumentLink &RHS)
Range range
The range enclosing this symbol not including leading / trailing whitespace but everything else,...
std::optional< std::int64_t > version
The version number of this document.
Range range
The range this link applies to.
Clangd extension: indicates the current state of the file in clangd, sent from server via the textDoc...
std::string query
A query string to filter symbols by.
bool deprecated
Indicates if this symbol is deprecated.
bool TheiaSemanticHighlighting
Client supports Theia semantic highlighting extension.
bool operator<(const Ref &L, const Ref &R)
Clangd extension: parameters configurable at initialize time.
TextDocumentIdentifier textDocument
The document that was closed.
Represents programming constructs like functions or constructors in the context of call hierarchy.
std::string code
The diagnostic's code. Can be omitted.
TextDocumentIdentifier textDocument
The document that was opened.
CallHierarchyItem from
The item that makes the call.
int activeParameter
The active parameter of the active signature.
std::optional< TraceLevel > trace
The initial trace setting. If omitted trace is disabled ('off').
bool contains(Position Pos) const
llvm::StringRef file() const
Retrieves absolute path to the file.
bool operator==(const Inclusion &LHS, const Inclusion &RHS)
bool ImplicitProgressCreation
The client supports implicit $/progress work-done progress streams, without a preceding window/workDo...
std::string name
The name of this symbol.
Range selection
A selection provided by the client on a textDocument/codeAction request.
std::optional< CodeDescription > codeDescription
An optional property to describe the error code.
CompletionContext context
InsertTextFormat
Defines whether the insert text in a completion item should be interpreted as plain text or a snippet...
std::optional< MarkupContent > documentation
A human-readable string that represents a doc-comment.
std::optional< CompletionItemKindBitset > CompletionItemKinds
The supported set of CompletionItemKinds for textDocument/completion.
InlayHintKind
Inlay hint kinds.
std::string arcana
A one-line dump of detailed information about the node.
@ TriggerCharacter
Completion was triggered by a trigger character specified by the triggerCharacters properties of the ...
TextDocumentIdentifier textDocument
The document to provide document links for.
TextDocumentIdentifier textDocument
The text document.
std::string newText
The string to be inserted.
A LSP-specific comparator used to find diagnostic in a container like std:map.
@ Unnecessary
Unused or unnecessary code.
static URI createFile(llvm::StringRef AbsolutePath)
This creates a file:// URI for AbsolutePath. The path must be absolute.
CompiledFragmentImpl & Out
bool CancelsStaleRequests
Whether the client claims to cancel stale requests.
TextDocumentIdentifier textDocument
The text document.
std::vector< ASTNode > children
Nodes nested within this one, such as the operands of a BinaryOperator.
ResolveParams data
A data entry field that is preserved between a type hierarchy prepare and supertypes or subtypes requ...
TypeHierarchyDirection direction
The direction of the hierarchy levels to resolve.
URIForFile target
The uri this link points to. If missing a resolve request is sent later.
std::string text
The new text of the range/document.
TextDocumentIdentifier textDocument
The text document.
int resolve
The hierarchy levels to resolve.
The parameter of a callHierarchy/outgoingCalls request.
std::optional< URIForFile > rootUri
The rootUri of the workspace.
Simplified description of a clang AST node.
constexpr auto CompletionItemKindMin
TypeHierarchyItem item
The item to resolve.
std::vector< Range > fromRanges
The range at which this item is called.
std::optional< Location > declarationRange
std::optional< Range > range
The position of the node to be dumped.
std::optional< std::vector< DiagnosticRelatedInformation > > relatedInformation
An array of related diagnostic information, e.g.
Range range
The range of the text document to be manipulated.
The show message notification is sent from a server to a client to ask the client to display a partic...
const static llvm::StringLiteral INFO_KIND
A URI describes the location of a source file.
std::optional< int > limit
Max results to return, overriding global default.
bool HasSignatureHelp
Client supports signature help.
std::string title
Mandatory title of the progress operation.
Range range
The range for which the command was invoked.
@ Changed
The file got changed.
@ Snippet
The primary text to be inserted is treated as a snippet.
Position position
The position of this hint.
Range range
The range of source code to which the hint applies.
friend bool operator!=(const DocumentLink &LHS, const DocumentLink &RHS)
static constexpr bool Value
friend bool operator!=(const Position &LHS, const Position &RHS)
std::string name
The name of this item.
std::string href
An URI to open with more information about the diagnostic error.
std::string newName
The new name of the symbol.
std::vector< HeaderHandle > Path
A parameter literal used in inlay hint requests.
SymbolKind adjustKindToCapability(SymbolKind Kind, SymbolKindBitset &SupportedSymbolKinds)
SymbolKind kind
The kind of this item.
const static llvm::StringLiteral QUICKFIX_KIND
Parameters for the typeHierarchy/resolve request.
An Event<T> allows events of type T to be broadcast to listeners.
std::optional< std::string > containerName
clangd extension: contains the name of the function or class in which the reference occurs
@ Parameter
An inlay hint that is for a parameter.