17#include "llvm/ADT/DenseMap.h"
18#include "llvm/ADT/StringRef.h"
27class ProjectAwareIndex :
public SymbolIndex {
29 size_t estimateMemoryUsage()
const override;
32 void lookup(
const LookupRequest &Req,
33 llvm::function_ref<
void(
const Symbol &)>
Callback)
const override;
36 bool refs(
const RefsRequest &Req,
37 llvm::function_ref<
void(
const Ref &)>
Callback)
const override;
39 bool containedRefs(
const ContainedRefsRequest &Req,
40 llvm::function_ref<
void(
const ContainedRefsResult &)>
46 fuzzyFind(
const FuzzyFindRequest &Req,
47 llvm::function_ref<
void(
const Symbol &)>
Callback)
const override;
50 void relations(
const RelationsRequest &Req,
51 llvm::function_ref<
void(
const SymbolID &,
const Symbol &)>
55 indexedFiles()
const override;
57 ProjectAwareIndex(
IndexFactory Gen,
bool Sync) : Gen(std::move(Gen)) {
59 Tasks = std::make_unique<AsyncTaskRunner>();
64 SymbolIndex *getIndex()
const;
67 mutable std::mutex Mu;
68 mutable llvm::DenseMap<Config::ExternalIndexSpec,
69 std::unique_ptr<SymbolIndex>>
71 mutable std::unique_ptr<AsyncTaskRunner> Tasks;
76size_t ProjectAwareIndex::estimateMemoryUsage()
const {
78 std::lock_guard<std::mutex> Lock(Mu);
79 for (
auto &
Entry : IndexForSpec)
84void ProjectAwareIndex::lookup(
85 const LookupRequest &Req,
86 llvm::function_ref<
void(
const Symbol &)>
Callback)
const {
87 trace::Span Tracer(
"ProjectAwareIndex::lookup");
88 if (
auto *Idx = getIndex())
92bool ProjectAwareIndex::refs(
93 const RefsRequest &Req,
94 llvm::function_ref<
void(
const Ref &)>
Callback)
const {
95 trace::Span Tracer(
"ProjectAwareIndex::refs");
96 if (
auto *Idx = getIndex())
101bool ProjectAwareIndex::containedRefs(
102 const ContainedRefsRequest &Req,
103 llvm::function_ref<
void(
const ContainedRefsResult &)>
Callback)
const {
104 trace::Span Tracer(
"ProjectAwareIndex::refersTo");
105 if (
auto *Idx = getIndex())
106 return Idx->containedRefs(Req,
Callback);
110bool ProjectAwareIndex::fuzzyFind(
111 const FuzzyFindRequest &Req,
112 llvm::function_ref<
void(
const Symbol &)>
Callback)
const {
113 trace::Span Tracer(
"ProjectAwareIndex::fuzzyFind");
114 if (
auto *Idx = getIndex())
115 return Idx->fuzzyFind(Req,
Callback);
119void ProjectAwareIndex::relations(
120 const RelationsRequest &Req,
121 llvm::function_ref<
void(
const SymbolID &,
const Symbol &)>
Callback)
const {
122 trace::Span Tracer(
"ProjectAwareIndex::relations");
123 if (
auto *Idx = getIndex())
124 return Idx->relations(Req,
Callback);
128ProjectAwareIndex::indexedFiles()
const {
129 trace::Span Tracer(
"ProjectAwareIndex::indexedFiles");
130 if (
auto *Idx = getIndex())
131 return Idx->indexedFiles();
135SymbolIndex *ProjectAwareIndex::getIndex()
const {
139 const auto &External =
C.Index.External;
140 std::lock_guard<std::mutex> Lock(Mu);
141 auto Entry = IndexForSpec.try_emplace(External,
nullptr);
143 Entry.first->getSecond() = Gen(External, Tasks.get());
144 return Entry.first->second.get();
151 return std::make_unique<ProjectAwareIndex>(std::move(Gen), Sync);
IndexContents
Describes what data is covered by an index.
std::function< std::unique_ptr< SymbolIndex >(const Config::ExternalIndexSpec &, AsyncTaskRunner *)> IndexFactory
A functor to create an index for an external index specification.
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
std::unique_ptr< SymbolIndex > createProjectAwareIndex(IndexFactory Gen, bool Sync)
Returns an index that answers queries using external indices.
std::vector< std::string > lookup(const SymbolIndex &I, llvm::ArrayRef< SymbolID > IDs)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
static const Config & current()
Returns the Config of the current Context, or an empty configuration.