18 llvm::StringRef Contents, llvm::StringRef Version,
20 Server.addDocument(
File, Contents, Version,
WantDiags, ForceRebuild);
21 if (!Server.blockUntilIdleForTest())
22 llvm_unreachable(
"not idle after addDocument");
30template <
typename T>
struct CaptureProxy {
31 CaptureProxy(std::optional<T> &Target) : Target(&Target) { assert(!Target); }
33 CaptureProxy(
const CaptureProxy &) =
delete;
34 CaptureProxy &operator=(
const CaptureProxy &) =
delete;
36 CaptureProxy(CaptureProxy &&Other) : Target(Other.Target) {
37 Other.Target =
nullptr;
39 CaptureProxy &operator=(CaptureProxy &&) =
delete;
41 operator llvm::unique_function<void(T)>() && {
42 assert(!Future.valid() &&
"conversion to callback called multiple times");
43 Future = Promise.get_future();
44 return [Promise = std::move(Promise)](
T Value)
mutable {
45 Promise.set_value(std::make_shared<T>(std::move(
Value)));
52 assert(Future.valid() &&
"conversion to callback was not called");
53 assert(!Target->has_value());
54 Target->emplace(std::move(*Future.get()));
58 std::optional<T> *Target;
62 std::promise<std::shared_ptr<T>> Promise;
63 std::future<std::shared_ptr<T>> Future;
66template <
typename T> CaptureProxy<T> capture(std::optional<T> &Target) {
67 return CaptureProxy<T>(Target);
71llvm::Expected<CodeCompleteResult>
74 std::optional<llvm::Expected<CodeCompleteResult>> Result;
75 Server.codeComplete(
File,
Pos, Opts, capture(Result));
76 return std::move(*Result);
82 std::optional<llvm::Expected<SignatureHelp>> Result;
83 Server.signatureHelp(
File,
Pos, DocumentationFormat, capture(Result));
84 return std::move(*Result);
87llvm::Expected<std::vector<LocatedSymbol>>
89 std::optional<llvm::Expected<std::vector<LocatedSymbol>>> Result;
90 Server.locateSymbolAt(
File,
Pos, capture(Result));
91 return std::move(*Result);
94llvm::Expected<std::vector<DocumentHighlight>>
96 std::optional<llvm::Expected<std::vector<DocumentHighlight>>> Result;
97 Server.findDocumentHighlights(
File,
Pos, capture(Result));
98 return std::move(*Result);
104 std::optional<llvm::Expected<RenameResult>> Result;
105 Server.rename(
File,
Pos, NewName, RenameOpts, capture(Result));
106 return std::move(*Result);
109llvm::Expected<RenameResult>
111 std::optional<std::string> NewName,
113 std::optional<llvm::Expected<RenameResult>> Result;
114 Server.prepareRename(
File,
Pos, NewName, RenameOpts, capture(Result));
115 return std::move(*Result);
118llvm::Expected<tooling::Replacements>
120 std::optional<llvm::Expected<tooling::Replacements>> Result;
121 Server.formatFile(
File, Rng, capture(Result));
122 return std::move(*Result);
127 Req.
Query = std::string(Query);
134 Index.fuzzyFind(Req, [&](
const Symbol &Sym) {
Builder.insert(Sym); });
135 return std::move(
Builder).build();
142 Index.refs(Req, [&](
const Ref &S) { Slab.
insert(
ID, S); });
143 return std::move(Slab).build();
146llvm::Expected<std::vector<SelectionRange>>
148 const std::vector<Position> &
Pos) {
149 std::optional<llvm::Expected<std::vector<SelectionRange>>> Result;
150 Server.semanticRanges(
File,
Pos, capture(Result));
151 return std::move(*Result);
154llvm::Expected<std::optional<clangd::Path>>
156 std::optional<llvm::Expected<std::optional<clangd::Path>>> Result;
157 Server.switchSourceHeader(
File, capture(Result));
158 return std::move(*Result);
163 llvm::Error Result = llvm::Error::success();
165 Server.customAction(
File,
"Custom", [&](llvm::Expected<InputsAndAST>
AST) {
167 Result =
AST.takeError();
CodeCompletionBuilder Builder
WantDiagnostics WantDiags
Manages a collection of source files and derived data (ASTs, indexes), and provides language-aware fe...
A threadsafe flag that is initially clear.
RefSlab::Builder is a mutable container that can 'freeze' to RefSlab.
void insert(const SymbolID &ID, const Ref &S)
Adds a ref to the slab. Deep copy: Strings will be owned by the slab.
An efficient structure of storing large set of symbol references in memory.
Interface for symbol indexes that can be used for searching or matching symbols among a set of symbol...
SymbolSlab::Builder is a mutable container that can 'freeze' to SymbolSlab.
An immutable symbol container that stores a set of symbols.
llvm::Expected< std::optional< clangd::Path > > runSwitchHeaderSource(ClangdServer &Server, PathRef File)
llvm::Expected< tooling::Replacements > runFormatFile(ClangdServer &Server, PathRef File, std::optional< Range > Rng)
llvm::Expected< RenameResult > runRename(ClangdServer &Server, PathRef File, Position Pos, llvm::StringRef NewName, const RenameOptions &RenameOpts)
llvm::Expected< std::vector< SelectionRange > > runSemanticRanges(ClangdServer &Server, PathRef File, const std::vector< Position > &Pos)
llvm::Expected< CodeCompleteResult > runCodeComplete(ClangdServer &Server, PathRef File, Position Pos, clangd::CodeCompleteOptions Opts)
llvm::Expected< SignatureHelp > runSignatureHelp(ClangdServer &Server, PathRef File, Position Pos, MarkupKind DocumentationFormat)
RefSlab getRefs(const SymbolIndex &Index, SymbolID ID)
void runAddDocument(ClangdServer &Server, PathRef File, llvm::StringRef Contents, llvm::StringRef Version, WantDiagnostics WantDiags, bool ForceRebuild)
llvm::Expected< std::vector< LocatedSymbol > > runLocateSymbolAt(ClangdServer &Server, PathRef File, Position Pos)
WantDiagnostics
Determines whether diagnostics should be generated for a file snapshot.
llvm::Error runCustomAction(ClangdServer &Server, PathRef File, llvm::function_ref< void(InputsAndAST)> Action)
llvm::StringRef PathRef
A typedef to represent a ref to file path.
llvm::Expected< std::vector< DocumentHighlight > > runFindDocumentHighlights(ClangdServer &Server, PathRef File, Position Pos)
SymbolSlab runFuzzyFind(const SymbolIndex &Index, llvm::StringRef Query)
llvm::Expected< RenameResult > runPrepareRename(ClangdServer &Server, PathRef File, Position Pos, std::optional< std::string > NewName, const RenameOptions &RenameOpts)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::string Query
A query string for the fuzzy find.
bool AnyScope
If set to true, allow symbols from any scope.
Represents a symbol occurrence in the source file.
llvm::DenseSet< SymbolID > IDs
The class presents a C++ symbol, e.g.