17 #include "clang/Basic/LLVM.h" 18 #include "llvm/ADT/SmallString.h" 19 #include "llvm/Support/Format.h" 20 #include "llvm/Support/FormatVariadic.h" 21 #include "llvm/Support/Path.h" 22 #include "llvm/Support/raw_ostream.h" 29 assert(llvm::sys::path::is_absolute(AbsPath) &&
"the path is relative");
30 File = std::move(AbsPath);
34 if (
auto S = E.getAsString()) {
37 elog(
"Failed to parse URI {0}: {1}", *S, U.takeError());
40 if (U->scheme() !=
"file" && U->scheme() !=
"test") {
41 elog(
"Clangd only supports 'file' URI scheme for workspace files: {0}",
67 json::ObjectMapper O(Params);
68 return O && O.map(
"uri", R.
uri);
72 json::ObjectMapper O(Params);
73 return O && O.map(
"line", R.
line) && O.map(
"character", R.
character);
88 json::ObjectMapper O(Params);
89 return O && O.map(
"start", R.
start) && O.map(
"end", R.
end);
100 return OS << R.
start <<
'-' << R.
end;
111 return OS << L.
range <<
'@' << L.
uri;
115 json::ObjectMapper O(Params);
116 return O && O.map(
"uri", R.
uri) && O.map(
"languageId", R.
languageId) &&
117 O.map(
"version", R.
version) && O.map(
"text", R.
text);
121 json::ObjectMapper O(Params);
129 json::ObjectMapper O(Params);
130 return O && O.map(
"range", R.
range) && O.map(
"newText", R.
newText);
141 OS << TE.
range <<
" => \"";
142 printEscapedString(TE.
newText, OS);
147 if (
auto S = E.getAsString()) {
151 }
else if (*S ==
"messages") {
154 }
else if (*S ==
"verbose") {
163 json::ObjectMapper O(Params);
172 json::ObjectMapper O(Params);
182 if (
auto T = E.getAsInteger()) {
193 if (
auto *A = E.getAsArray()) {
195 for (
size_t I = 0; I < A->size(); ++I) {
198 Out.push_back(KindOut);
206 json::ObjectMapper O(Params);
207 return O && O.map(
"valueSet", R.
valueSet);
212 auto KindVal =
static_cast<size_t>(
Kind);
213 if (KindVal >=
SymbolKindMin && KindVal <= SupportedSymbolKinds.size() &&
214 SupportedSymbolKinds[KindVal])
229 json::ObjectMapper O(Params);
230 return O && O.map(
"symbolKind", R.
symbolKind);
234 json::ObjectMapper O(Params);
235 return O && O.map(
"symbol", R.
symbol);
239 json::ObjectMapper O(Params);
247 json::ObjectMapper O(Params);
256 json::ObjectMapper O(Params);
265 O.map(
"trace", R.
trace);
271 json::ObjectMapper O(Params);
277 json::ObjectMapper O(Params);
282 json::ObjectMapper O(Params);
289 if (
auto T = E.getAsInteger()) {
300 json::ObjectMapper O(Params);
301 return O && O.map(
"uri", R.
uri) && O.map(
"type", R.
type);
305 json::ObjectMapper O(Params);
306 return O && O.map(
"changes", R.
changes);
310 json::ObjectMapper O(Params);
311 return O && O.map(
"range", R.
range) && O.map(
"rangeLength", R.
rangeLength) &&
312 O.map(
"text", R.
text);
316 json::ObjectMapper O(Params);
317 return O && O.map(
"tabSize", R.
tabSize) &&
329 json::ObjectMapper O(Params);
335 json::ObjectMapper O(Params);
337 O.map(
"position", R.
position) && O.map(
"ch", R.
ch) &&
342 json::ObjectMapper O(Params);
348 json::ObjectMapper O(Params);
353 json::ObjectMapper O(Params);
354 if (!O || !O.map(
"range", R.
range) || !O.map(
"message", R.
message))
361 json::ObjectMapper O(Params);
366 OS << D.
range <<
" [";
388 json::ObjectMapper O(Params);
394 json::ObjectMapper O(Params);
395 return O && O.map(
"changes", R.
changes);
401 json::ObjectMapper O(Params);
402 if (!O || !O.map(
"command", R.
command))
405 auto Args = Params.getAsObject()->getArray(
"arguments");
406 if (R.
command == ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND) {
407 return Args && Args->size() == 1 &&
416 {
"kind",
static_cast<int>(P.
kind)},
429 json::ObjectMapper O(Params);
430 return O && O.map(
"query", R.
query);
437 return std::move(Cmd);
444 for (
auto &Change : *WE.
changes)
445 FileChanges[Change.first] =
json::Array(Change.second);
446 return json::Object{{
"changes", std::move(FileChanges)}};
454 json::ObjectMapper O(Params);
466 llvm_unreachable(
"Invalid MarkupKind");
470 if (MC.
value.empty())
482 if (H.
range.hasValue())
485 return std::move(Result);
489 assert(!CI.
label.empty() &&
"completion item label is required");
492 Result[
"kind"] =
static_cast<int>(CI.
kind);
494 Result[
"detail"] = CI.
detail;
509 return std::move(Result);
530 assert(!PI.
label.empty() &&
"parameter information label is required");
534 return std::move(Result);
538 assert(!SI.
label.empty() &&
"signature information label is required");
545 return std::move(Result);
556 "Unexpected negative value for number of active signatures.");
558 "Unexpected negative value for active parameter index");
567 json::ObjectMapper O(Params);
575 {
"kind",
static_cast<int>(DH.
kind)},
590 json::ObjectMapper O(Params);
591 return O && O.map(
"settings", CCP.
settings);
596 json::ObjectMapper O(Params);
std::string insertText
A string that should be inserted to a document when selecting this completion.
URIForFile uri
The file's URI.
CompletionClientCapabilities completion
Capabilities specific to the textDocument/completion
static StringRef toTextKind(MarkupKind Kind)
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...
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.
llvm::Optional< SymbolKindCapabilities > symbolKind
Capabilities SymbolKind.
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...
Range range
The range for which the command was invoked.
CodeActionContext context
Context carrying additional information.
static const llvm::StringLiteral CLANGD_APPLY_FIX_COMMAND
CompletionItemKind kind
The kind of this completion item.
Clangd extension to set clangd-specific "initializationOptions" in the "initialize" request and for t...
llvm::Optional< WorkspaceSymbolCapabilities > symbol
Capabilities specific to workspace/symbol.
std::vector< CompletionItem > items
The completion items.
bool snippetSupport
Client supports snippets as insert text.
llvm::Optional< std::map< std::string, std::vector< TextEdit > > > changes
Holds changes to existing resources.
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.
llvm::Optional< ClangdInitializationOptions > initializationOptions
URIForFile uri
The text document's URI.
std::string text
The new text of the range/document.
llvm::Optional< WorkspaceClientCapabilities > workspace
constexpr auto SymbolKindMin
std::string sortText
A string that should be used when comparing this item with other items.
bool isIncomplete
The list is not complete.
llvm::Optional< Metadata > metadata
Extension storing per-file metadata, such as compilation flags.
std::string documentation
A human-readable string that represents a doc-comment.
std::vector< TextEdit > additionalTextEdits
An optional array of additional text edits that are applied when selecting this completion.
void elog(const char *Fmt, Ts &&... Vals)
llvm::Optional< int > processId
The process Id of the parent process that started the server.
bool contextSupport
The client supports to send additional context information for a textDocument/completion request...
MarkupContent contents
The hover's content.
A document highlight is a range inside a text document which deserves special attention.
TextDocumentClientCapabilities textDocument
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...
TextDocumentIdentifier textDocument
The document that was opened.
std::string newText
The string to be inserted.
std::string newName
The new name of the symbol.
std::string command
The command identifier, e.g. CLANGD_APPLY_FIX_COMMAND.
TextDocumentIdentifier textDocument
std::string filterText
A string that should be used when filtering a set of completion items.
TextDocumentIdentifier textDocument
The document in which the command was invoked.
Range range
The range of the text document to be manipulated.
CompletionItemClientCapabilities completionItem
The client supports the following CompletionItem specific capabilities.
int activeSignature
The active signature.
void log(const char *Fmt, Ts &&... Vals)
int activeParameter
The active parameter of the active signature.
llvm::Optional< Range > range
The range of the document that changed.
std::string Path
A typedef to represent a file path.
Position position
The position inside the text document.
std::vector< SignatureInformation > signatures
The resulting signatures.
llvm::Optional< int > rangeLength
The length of the range that got replaced.
ClientCapabilities capabilities
The capabilities provided by the client (editor or tool)
TextDocumentItem textDocument
The document that was opened.
TextDocumentIdentifier textDocument
The document that did change.
std::vector< FileEvent > changes
The actual file events.
bool commitCharacterSupport
Client supports commit characters on a completion item.
std::string languageId
The text document's language identifier.
llvm::Optional< std::string > rootPath
The rootPath of the workspace.
int line
Line position in a document (zero-based).
std::vector< TextDocumentContentChangeEvent > contentChanges
The actual content changes.
int character
Character offset on a line in a document (zero-based).
llvm::Optional< std::vector< SymbolKind > > valueSet
The SymbolKinds that the client supports.
Represents the signature of a callable.
std::string query
A non-empty query string.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::bitset< SymbolKindMax+1 > SymbolKindBitset
std::string message
The diagnostic's code.
TextDocumentIdentifier textDocument
The text document.
json::Value toJSON(const URIForFile &U)
Serialize/deserialize URIForFile to/from a string URI.
std::string label
The label of this completion item.
bool dynamicRegistration
Whether completion supports dynamic registration.
DocumentHighlightKind kind
The highlight kind, default is DocumentHighlightKind.Text.
SymbolKind adjustKindToCapability(SymbolKind Kind, SymbolKindBitset &SupportedSymbolKinds)
std::vector< Diagnostic > diagnostics
An array of diagnostics.
int severity
The diagnostic's severity.
The parameters of a Workspace Symbol Request.
FileChangeType type
The change type.
std::string text
The content of the opened text document.
static llvm::Expected< std::string > resolve(const URI &U, llvm::StringRef HintPath="")
Resolves the absolute path of U.
Position position
The position at which this request was sent.
URIForFile uri
The text document's URI.
static llvm::Expected< URI > parse(llvm::StringRef Uri)
Parse a URI string "<scheme>:[//<authority>/]<path>".
Range range
The range at which the message applies.
int version
The version number of this document (it will strictly increase after each.
Position end
The range's end position.
llvm::Optional< WorkspaceEdit > workspaceEdit
InsertTextFormat insertTextFormat
The format of the insert text.
ClangdConfigurationParamsChange settings
bool operator<(const CompletionItem &L, const CompletionItem &R)
bool fromJSON(const json::Value &E, URIForFile &R)
llvm::Optional< std::string > compilationDatabasePath
raw_ostream & operator<<(raw_ostream &OS, const CodeCompletion &C)
llvm::Optional< TraceLevel > trace
The initial trace setting. If omitted trace is disabled ('off').