20 const auto BackingDataSize = Slab.
bytes() + Refs.bytes();
21 auto Data = std::make_pair(std::move(Slab), std::move(Refs));
22 return std::make_unique<MemIndex>(Data.first, Data.second, Relations,
23 std::move(Data), BackingDataSize);
29 assert(!StringRef(Req.
Query).contains(
"::") &&
30 "There must be no :: in query.");
34 Req.
Limit ? *Req.
Limit : std::numeric_limits<size_t>::max());
37 for (
const auto &Pair : Index) {
38 const Symbol *Sym = Pair.second;
48 if (Top.
push({*Score * quality(*Sym), Sym}))
51 auto Results = std::move(Top).items();
53 for (
const auto &Item :
Results)
61 for (
const auto &
ID : Req.
IDs) {
62 auto I = Index.find(
ID);
69 llvm::function_ref<
void(
const Ref &)>
Callback)
const {
71 uint32_t Remaining = Req.
Limit.value_or(std::numeric_limits<uint32_t>::max());
72 for (
const auto &ReqID : Req.
IDs) {
73 auto SymRefs = Refs.find(ReqID);
74 if (SymRefs == Refs.end())
76 for (
const auto &O : SymRefs->second) {
77 if (!
static_cast<int>(Req.
Filter & O.Kind))
91 uint32_t Remaining = Req.
Limit.value_or(std::numeric_limits<uint32_t>::max());
94 auto It = Relations.find(
95 std::make_pair(Subject,
static_cast<uint8_t
>(Req.
Predicate)));
96 if (It != Relations.end()) {
97 for (
const auto &
Obj : It->second) {
100 LookupReq.
IDs.insert(
Obj);
110 return [
this](llvm::StringRef FileURI) {
116 return Index.getMemorySize() + Refs.getMemorySize() +
117 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 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::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).