20#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_DEX_DEX_H
21#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_DEX_DEX_H
28#include "llvm/ADT/StringSet.h"
38 template <
typename SymbolRange,
typename RefsRange,
typename RelationsRange>
40 bool SupportContainedRefs)
42 for (
auto &&Sym : Symbols)
43 this->Symbols.push_back(&Sym);
44 for (
auto &&
Ref : Refs)
45 this->Refs.try_emplace(
Ref.first,
Ref.second);
46 for (
auto &&Rel : Relations)
47 this->Relations[std::make_pair(Rel.Subject,
48 static_cast<uint8_t
>(Rel.Predicate))]
49 .push_back(Rel.Object);
50 buildIndex(SupportContainedRefs);
53 template <
typename SymbolRange,
typename RefsRange,
typename RelationsRange,
56 Payload &&BackingData,
size_t BackingDataSize,
bool SupportContainedRefs)
57 :
Dex(std::forward<
SymbolRange>(Symbols), std::forward<RefsRange>(Refs),
58 std::forward<RelationsRange>(Relations), SupportContainedRefs) {
59 KeepAlive = std::shared_ptr<void>(
60 std::make_shared<Payload>(std::move(BackingData)),
nullptr);
61 this->BackingDataSize = BackingDataSize;
64 template <
typename SymbolRange,
typename RefsRange,
typename RelationsRange,
65 typename FileRange,
typename Payload>
68 size_t BackingDataSize,
bool SupportContainedRefs)
69 :
Dex(std::forward<
SymbolRange>(Symbols), std::forward<RefsRange>(Refs),
70 std::forward<RelationsRange>(Relations),
71 std::forward<
Payload>(BackingData), BackingDataSize,
72 SupportContainedRefs) {
73 this->Files = std::forward<FileRange>(Files);
74 this->IdxContents = IdxContents;
79 bool SupportContainedRefs);
89 llvm::function_ref<
void(
const Ref &)>
Callback)
const override;
106 const Ref *Reference;
111 : Reference(&Reference), Target(Target) {}
112 const Ref &ref()
const {
return *Reference; }
113 ContainedRefsResult containedRefsResult()
const {
114 return {ref().Location, ref().Kind, Target};
118 void buildIndex(
bool EnableOutgoingCalls);
119 llvm::iterator_range<std::vector<RevRef>::const_iterator>
120 lookupRevRefs(
const SymbolID &
Container)
const;
121 std::unique_ptr<Iterator> iterator(
const Token &Tok)
const;
122 std::unique_ptr<Iterator>
123 createFileProximityIterator(llvm::ArrayRef<std::string> ProximityPaths)
const;
124 std::unique_ptr<Iterator>
125 createTypeBoostingIterator(llvm::ArrayRef<std::string> Types)
const;
128 std::vector<const Symbol *> Symbols;
130 std::vector<float> SymbolQuality;
131 llvm::DenseMap<SymbolID, const Symbol *> LookupTable;
138 llvm::DenseMap<Token, PostingList> InvertedIndex;
140 llvm::DenseMap<SymbolID, llvm::ArrayRef<Ref>> Refs;
141 std::vector<RevRef> RevRefs;
143 "RelationKind should be of same size as a uint8_t");
144 llvm::DenseMap<std::pair<SymbolID, uint8_t>, std::vector<SymbolID>> Relations;
145 std::shared_ptr<void> KeepAlive;
147 llvm::StringSet<> Files;
153 size_t BackingDataSize = 0;
Symbol index queries consist of specific requirements for the requested symbol, such as high fuzzy ma...
This defines posting list interface: a storage for identifiers of symbols which can be characterized ...
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...
An immutable symbol container that stores a set of symbols.
In-memory Dex trigram-based index implementation.
size_t estimateMemoryUsage() const override
Returns estimated size of index (in bytes).
bool refs(const RefsRequest &Req, llvm::function_ref< void(const Ref &)> Callback) const override
Finds all occurrences (e.g.
void relations(const RelationsRequest &Req, llvm::function_ref< void(const SymbolID &, const Symbol &)> Callback) const override
Dex(SymbolRange &&Symbols, RefsRange &&Refs, RelationsRange &&Relations, bool SupportContainedRefs)
static std::unique_ptr< SymbolIndex > build(SymbolSlab, RefSlab, RelationSlab, bool SupportContainedRefs)
Builds an index from slabs. The index takes ownership of the slab.
Dex(SymbolRange &&Symbols, RefsRange &&Refs, RelationsRange &&Relations, FileRange &&Files, IndexContents IdxContents, Payload &&BackingData, size_t BackingDataSize, bool SupportContainedRefs)
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.
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.
llvm::unique_function< IndexContents(llvm::StringRef) const > indexedFiles() const override
Dex(SymbolRange &&Symbols, RefsRange &&Refs, RelationsRange &&Relations, Payload &&BackingData, size_t BackingDataSize, bool SupportContainedRefs)
bool fuzzyFind(const FuzzyFindRequest &Req, llvm::function_ref< void(const Symbol &)> Callback) const override
Constructs iterators over tokens extracted from the query and exhausts it while applying Callback to ...
Token objects represent a characteristic of a symbol, which can be used to perform efficient search.
llvm::SmallVector< llvm::StringRef, ProximityURILimit > generateProximityURIs(llvm::StringRef URI)
Returns Search Token for a number of parent directories of given Path.
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++ -*-===//
Represents a symbol occurrence in the source file.
Represents a symbol range where the symbol can potentially have multiple tokens.
The class presents a C++ symbol, e.g.