21 const auto BackingDataSize = Slab.
bytes() + Refs.bytes();
22 auto Data = std::make_pair(std::move(Slab), std::move(Refs));
23 return std::make_unique<MemIndex>(Data.first, Data.second, Relations,
24 std::move(Data), BackingDataSize);
30 assert(!StringRef(Req.
Query).contains(
"::") &&
31 "There must be no :: in query.");
35 Req.
Limit.value_or(std::numeric_limits<size_t>::max()));
38 for (
const auto &
Pair : Index) {
49 if (Top.
push({*Score * quality(*Sym), Sym}))
52 auto Results = std::move(Top).items();
54 for (
const auto &Item :
Results)
62 for (
const auto &
ID : Req.
IDs) {
63 auto I = Index.find(
ID);
70 llvm::function_ref<
void(
const Ref &)>
Callback)
const {
72 uint32_t Remaining = Req.
Limit.value_or(std::numeric_limits<uint32_t>::max());
73 for (
const auto &ReqID : Req.
IDs) {
74 auto SymRefs = Refs.find(ReqID);
75 if (SymRefs == Refs.end())
77 for (
const auto &O : SymRefs->second) {
78 if (!
static_cast<int>(Req.
Filter & O.Kind))
93 uint32_t Remaining = Req.
Limit.value_or(std::numeric_limits<uint32_t>::max());
94 for (
const auto &
Pair : Refs) {
95 for (
const auto &R :
Pair.second) {
97 Req.
ID != R.Container)
111 uint32_t Remaining = Req.
Limit.value_or(std::numeric_limits<uint32_t>::max());
114 auto It = Relations.find(
115 std::make_pair(Subject,
static_cast<uint8_t
>(Req.
Predicate)));
116 if (It != Relations.end()) {
117 for (
const auto &
Obj : It->second) {
120 LookupReq.
IDs.insert(
Obj);
130 return [
this](llvm::StringRef FileURI) {
136 return Index.getMemorySize() + Refs.getMemorySize() +
137 Relations.getMemorySize() + BackingDataSize;
std::vector< CodeCompletionResult > Results
std::optional< float > Score
#define SPAN_ATTACH(S, Name, Expr)
Attach a key-value pair to a Span event.
size_t estimateMemoryUsage() const override
Returns estimated size of index (in bytes).
void lookup(const LookupRequest &Req, llvm::function_ref< void(const Symbol &)> Callback) const override
Looks up symbols with any of the given symbol IDs and applies Callback on each matched symbol.
bool fuzzyFind(const FuzzyFindRequest &Req, llvm::function_ref< void(const Symbol &)> Callback) const override
Matches symbols in the index fuzzily and applies Callback on each matched symbol before returning.
void relations(const RelationsRequest &Req, llvm::function_ref< void(const SymbolID &, const Symbol &)> Callback) const override
llvm::unique_function< IndexContents(llvm::StringRef) const > indexedFiles() const override
static std::unique_ptr< SymbolIndex > build(SymbolSlab Symbols, RefSlab Refs, RelationSlab Relations)
Builds an index from slabs. The index takes ownership of the data.
bool containedRefs(const ContainedRefsRequest &Req, llvm::function_ref< void(const ContainedRefsResult &)> Callback) const override
Find all symbols that are referenced by a symbol and apply Callback on each result.
bool refs(const RefsRequest &Req, llvm::function_ref< void(const Ref &)> Callback) const override
Finds all occurrences (e.g.
An efficient structure of storing large set of symbol references in memory.
An immutable symbol container that stores a set of symbols.
TopN<T> is a lossy container that preserves only the "best" N elements.
bool push(value_type &&V)
Records an event whose duration is the lifetime of the Span object.
IndexContents
Describes what data is covered by an index.
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::optional< uint32_t > Limit
If set, limit the number of refers returned from the index.
static const RefKind SupportedRefKinds
Note that RefKind::Call just restricts the matched SymbolKind to functions, not the form of the refer...
std::vector< std::string > Scopes
If this is non-empty, symbols must be in at least one of the scopes (e.g.
bool RestrictForCodeCompletion
If set to true, only symbols for completion support will be considered.
std::string Query
A query string for the fuzzy find.
bool AnyScope
If set to true, allow symbols from any scope.
std::optional< uint32_t > Limit
The number of top candidates to return.
llvm::DenseSet< SymbolID > IDs
Represents a symbol occurrence in the source file.
llvm::DenseSet< SymbolID > IDs
std::optional< uint32_t > Limit
If set, limit the number of refers returned from the index.
std::optional< uint32_t > Limit
If set, limit the number of relations returned from the index.
llvm::DenseSet< SymbolID > Subjects
The class presents a C++ symbol, e.g.
@ IndexedForCodeCompletion
Whether or not this symbol is meant to be used for the code completion.
llvm::StringRef Name
The unqualified name of the symbol, e.g. "bar" (for ns::bar).
llvm::StringRef Scope
The containing namespace. e.g. "" (global), "ns::" (top-level namespace).