19 llvm_unreachable(
"not idle after addDocument");
27 template <
typename T>
struct CaptureProxy {
28 CaptureProxy(llvm::Optional<T> &Target) : Target(&Target) {
29 assert(!Target.hasValue());
32 CaptureProxy(
const CaptureProxy &) =
delete;
33 CaptureProxy &operator=(
const CaptureProxy &) =
delete;
35 CaptureProxy(CaptureProxy &&Other) : Target(Other.Target) {
36 Other.Target =
nullptr;
38 CaptureProxy &operator=(CaptureProxy &&) =
delete;
40 operator llvm::unique_function<void(T)>() && {
41 assert(!Future.valid() &&
"conversion to callback called multiple times");
42 Future = Promise.get_future();
43 return [Promise = std::move(Promise)](T
Value)
mutable {
44 Promise.set_value(std::make_shared<T>(std::move(
Value)));
51 assert(Future.valid() &&
"conversion to callback was not called");
52 assert(!Target->hasValue());
53 Target->emplace(std::move(*Future.get()));
57 llvm::Optional<T> *Target;
61 std::promise<std::shared_ptr<T>> Promise;
62 std::future<std::shared_ptr<T>> Future;
65 template <
typename T> CaptureProxy<T> capture(llvm::Optional<T> &Target) {
66 return CaptureProxy<T>(Target);
70 llvm::Expected<CodeCompleteResult>
73 llvm::Optional<llvm::Expected<CodeCompleteResult>> Result;
75 return std::move(*Result);
80 llvm::Optional<llvm::Expected<SignatureHelp>> Result;
82 return std::move(*Result);
85 llvm::Expected<std::vector<LocatedSymbol>>
87 llvm::Optional<llvm::Expected<std::vector<LocatedSymbol>>> Result;
89 return std::move(*Result);
92 llvm::Expected<std::vector<DocumentHighlight>>
94 llvm::Optional<llvm::Expected<std::vector<DocumentHighlight>>> Result;
96 return std::move(*Result);
101 llvm::Optional<llvm::Expected<FileEdits>> Result;
102 Server.
rename(File, Pos, NewName,
false, capture(Result));
103 return std::move(*Result);
107 llvm::Optional<std::string> Result;
108 Server.
dumpAST(File, capture(Result));
109 return std::move(*Result);
112 llvm::Expected<std::vector<SymbolInformation>>
114 llvm::Optional<llvm::Expected<std::vector<SymbolInformation>>> Result;
116 return std::move(*Result);
119 llvm::Expected<std::vector<DocumentSymbol>>
121 llvm::Optional<llvm::Expected<std::vector<DocumentSymbol>>> Result;
123 return std::move(*Result);
136 return std::move(Builder).build();
144 return std::move(Slab).build();
147 llvm::Expected<std::vector<Range>>
149 llvm::Optional<llvm::Expected<std::vector<Range>>> Result;
151 return std::move(*Result);
154 llvm::Expected<llvm::Optional<clangd::Path>>
156 llvm::Optional<llvm::Expected<llvm::Optional<clangd::Path>>> Result;
158 return std::move(*Result);
WantDiagnostics
Determines whether diagnostics should be generated for a file snapshot.
An immutable symbol container that stores a set of symbols.
llvm::DenseSet< SymbolID > IDs
void addDocument(PathRef File, StringRef Contents, WantDiagnostics WD=WantDiagnostics::Auto)
Add a File to the list of tracked C++ files or update the contents if File is already tracked...
bool AnyScope
If set to true, allow symbols from any scope.
llvm::Expected< std::vector< Range > > runSemanticRanges(ClangdServer &Server, PathRef File, Position Pos)
void codeComplete(PathRef File, Position Pos, const clangd::CodeCompleteOptions &Opts, Callback< CodeCompleteResult > CB)
Run code completion for File at Pos.
llvm::Expected< CodeCompleteResult > runCodeComplete(ClangdServer &Server, PathRef File, Position Pos, clangd::CodeCompleteOptions Opts)
std::string runDumpAST(ClangdServer &Server, PathRef File)
An efficient structure of storing large set of symbol references in memory.
llvm::Expected< SignatureHelp > runSignatureHelp(ClangdServer &Server, PathRef File, Position Pos)
llvm::Expected< std::vector< DocumentSymbol > > runDocumentSymbols(ClangdServer &Server, PathRef File)
llvm::Expected< std::vector< LocatedSymbol > > runLocateSymbolAt(ClangdServer &Server, PathRef File, Position Pos)
Interface for symbol indexes that can be used for searching or matching symbols among a set of symbol...
Represents a symbol occurrence in the source file.
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...
llvm::StringRef PathRef
A typedef to represent a ref to file path.
void insert(const Symbol &S)
Adds a symbol, overwriting any existing one with the same ID.
LLVM_NODISCARD bool blockUntilIdleForTest(llvm::Optional< double > TimeoutSeconds=10)
void findDocumentHighlights(PathRef File, Position Pos, Callback< std::vector< DocumentHighlight >> CB)
Get document highlights for a given position.
llvm::Expected< llvm::Optional< clangd::Path > > runSwitchHeaderSource(ClangdServer &Server, PathRef File)
SymbolSlab::Builder is a mutable container that can 'freeze' to SymbolSlab.
SymbolSlab runFuzzyFind(const SymbolIndex &Index, llvm::StringRef Query)
std::string Query
A query string for the fuzzy find.
virtual bool refs(const RefsRequest &Req, llvm::function_ref< void(const Ref &)> Callback) const =0
Finds all occurrences (e.g.
void switchSourceHeader(PathRef Path, Callback< llvm::Optional< clangd::Path >> CB)
Switch to a corresponding source file when given a header file, and vice versa.
void dumpAST(PathRef File, llvm::unique_function< void(std::string)> Callback)
Only for testing purposes.
void documentSymbols(StringRef File, Callback< std::vector< DocumentSymbol >> CB)
Retrieve the symbols within the specified file.
RefSlab::Builder is a mutable container that can 'freeze' to RefSlab.
CodeCompletionBuilder Builder
The class presents a C++ symbol, e.g.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::Expected< std::vector< SymbolInformation > > runWorkspaceSymbols(ClangdServer &Server, llvm::StringRef Query, int Limit)
llvm::Expected< std::vector< DocumentHighlight > > runFindDocumentHighlights(ClangdServer &Server, PathRef File, Position Pos)
llvm::Expected< FileEdits > runRename(ClangdServer &Server, PathRef File, Position Pos, llvm::StringRef NewName)
void insert(const SymbolID &ID, const Ref &S)
Adds a ref to the slab. Deep copy: Strings will be owned by the slab.
void locateSymbolAt(PathRef File, Position Pos, Callback< std::vector< LocatedSymbol >> CB)
Find declaration/definition locations of symbol at a specified position.
Manages a collection of source files and derived data (ASTs, indexes), and provides language-aware fe...
void semanticRanges(PathRef File, Position Pos, Callback< std::vector< Range >> CB)
Get semantic ranges around a specified position in a file.
void rename(PathRef File, Position Pos, llvm::StringRef NewName, bool WantFormat, Callback< FileEdits > CB)
Rename all occurrences of the symbol at the Pos in File to NewName.
void workspaceSymbols(StringRef Query, int Limit, Callback< std::vector< SymbolInformation >> CB)
Retrieve the top symbols from the workspace matching a query.
void signatureHelp(PathRef File, Position Pos, Callback< SignatureHelp > CB)
Provide signature help for File at Pos.
RefSlab getRefs(const SymbolIndex &Index, SymbolID ID)
void runAddDocument(ClangdServer &Server, PathRef File, llvm::StringRef Contents, WantDiagnostics WantDiags)
const SymbolIndex * Index