18 llvm::StringRef Contents, llvm::StringRef Version,
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;
76 return std::move(*Result);
82 std::optional<llvm::Expected<SignatureHelp>> Result;
84 return std::move(*Result);
87llvm::Expected<std::vector<LocatedSymbol>>
89 std::optional<llvm::Expected<std::vector<LocatedSymbol>>> Result;
91 return std::move(*Result);
94llvm::Expected<std::vector<DocumentHighlight>>
96 std::optional<llvm::Expected<std::vector<DocumentHighlight>>> Result;
98 return std::move(*Result);
102 Position Pos, llvm::StringRef NewName,
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;
115 return std::move(*Result);
118llvm::Expected<tooling::Replacements>
120 const std::vector<Range> &Rngs) {
121 std::optional<llvm::Expected<tooling::Replacements>> Result;
123 return std::move(*Result);
128 Req.
Query = std::string(Query);
136 return std::move(Builder).build();
144 return std::move(Slab).build();
147llvm::Expected<std::vector<SelectionRange>>
149 const std::vector<Position> &Pos) {
150 std::optional<llvm::Expected<std::vector<SelectionRange>>> Result;
152 return std::move(*Result);
155llvm::Expected<std::optional<clangd::Path>>
157 std::optional<llvm::Expected<std::optional<clangd::Path>>> Result;
159 return std::move(*Result);
164 llvm::Error Result = llvm::Error::success();
168 Result =
AST.takeError();
Manages a collection of source files and derived data (ASTs, indexes), and provides language-aware fe...
void prepareRename(PathRef File, Position Pos, std::optional< std::string > NewName, const RenameOptions &RenameOpts, Callback< RenameResult > CB)
Test the validity of a rename operation.
void addDocument(PathRef File, StringRef Contents, llvm::StringRef Version="null", WantDiagnostics WD=WantDiagnostics::Auto, bool ForceRebuild=false)
Add a File to the list of tracked C++ files or update the contents if File is already tracked.
void findDocumentHighlights(PathRef File, Position Pos, Callback< std::vector< DocumentHighlight > > CB)
Get document highlights for a given position.
void signatureHelp(PathRef File, Position Pos, MarkupKind DocumentationFormat, Callback< SignatureHelp > CB)
Provide signature help for File at Pos.
void switchSourceHeader(PathRef Path, Callback< std::optional< clangd::Path > > CB)
Switch to a corresponding source file when given a header file, and vice versa.
void semanticRanges(PathRef File, const std::vector< Position > &Pos, Callback< std::vector< SelectionRange > > CB)
Get semantic ranges around a specified position in a file.
void formatFile(PathRef File, const std::vector< Range > &Rngs, Callback< tooling::Replacements > CB)
Run formatting for the File with content Code.
void rename(PathRef File, Position Pos, llvm::StringRef NewName, const RenameOptions &Opts, Callback< RenameResult > CB)
Rename all occurrences of the symbol at the Pos in File to NewName.
void customAction(PathRef File, llvm::StringRef Name, Callback< InputsAndAST > Action)
Runs an arbitrary action that has access to the AST of the specified file.
void locateSymbolAt(PathRef File, Position Pos, Callback< std::vector< LocatedSymbol > > CB)
Find declaration/definition locations of symbol at a specified position.
bool blockUntilIdleForTest(std::optional< double > TimeoutSeconds=10)
void codeComplete(PathRef File, Position Pos, const clangd::CodeCompleteOptions &Opts, Callback< CodeCompleteResult > CB)
Run code completion for File at Pos.
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...
virtual bool fuzzyFind(const FuzzyFindRequest &Req, llvm::function_ref< void(const Symbol &)> Callback) const =0
Matches symbols in the index fuzzily and applies Callback on each matched symbol before returning.
virtual bool refs(const RefsRequest &Req, llvm::function_ref< void(const Ref &)> Callback) const =0
Finds all occurrences (e.g.
SymbolSlab::Builder is a mutable container that can 'freeze' to SymbolSlab.
void insert(const Symbol &S)
Adds a symbol, overwriting any existing one with the same ID.
An immutable symbol container that stores a set of symbols.
FIXME: Skip testing on windows temporarily due to the different escaping code mode.
llvm::Expected< std::optional< clangd::Path > > runSwitchHeaderSource(ClangdServer &Server, PathRef File)
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)
llvm::StringRef PathRef
A typedef to represent a ref to file path.
WantDiagnostics
Determines whether diagnostics should be generated for a file snapshot.
llvm::Expected< tooling::Replacements > runFormatFile(ClangdServer &Server, PathRef File, const std::vector< Range > &Rngs)
llvm::Error runCustomAction(ClangdServer &Server, PathRef File, llvm::function_ref< void(InputsAndAST)> Action)
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.