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;
42 fuzzyFind(
const FuzzyFindRequest &Req,
43 llvm::function_ref<
void(
const Symbol &)>
Callback)
const override;
46 void relations(
const RelationsRequest &Req,
47 llvm::function_ref<
void(
const SymbolID &,
const Symbol &)>
51 indexedFiles()
const override;
53 ProjectAwareIndex(
IndexFactory Gen,
bool Sync) : Gen(std::move(Gen)) {
55 Tasks = std::make_unique<AsyncTaskRunner>();
60 SymbolIndex *getIndex()
const;
63 mutable std::mutex Mu;
64 mutable llvm::DenseMap<Config::ExternalIndexSpec,
65 std::unique_ptr<SymbolIndex>>
67 mutable std::unique_ptr<AsyncTaskRunner> Tasks;
72size_t ProjectAwareIndex::estimateMemoryUsage()
const {
74 std::lock_guard<std::mutex> Lock(Mu);
75 for (
auto &
Entry : IndexForSpec)
80void ProjectAwareIndex::lookup(
81 const LookupRequest &Req,
82 llvm::function_ref<
void(
const Symbol &)>
Callback)
const {
83 trace::Span Tracer(
"ProjectAwareIndex::lookup");
84 if (
auto *Idx = getIndex())
88bool ProjectAwareIndex::refs(
89 const RefsRequest &Req,
90 llvm::function_ref<
void(
const Ref &)>
Callback)
const {
91 trace::Span Tracer(
"ProjectAwareIndex::refs");
92 if (
auto *Idx = getIndex())
97bool ProjectAwareIndex::fuzzyFind(
98 const FuzzyFindRequest &Req,
99 llvm::function_ref<
void(
const Symbol &)>
Callback)
const {
100 trace::Span Tracer(
"ProjectAwareIndex::fuzzyFind");
101 if (
auto *Idx = getIndex())
102 return Idx->fuzzyFind(Req,
Callback);
106void ProjectAwareIndex::relations(
107 const RelationsRequest &Req,
108 llvm::function_ref<
void(
const SymbolID &,
const Symbol &)>
Callback)
const {
109 trace::Span Tracer(
"ProjectAwareIndex::relations");
110 if (
auto *Idx = getIndex())
111 return Idx->relations(Req,
Callback);
115ProjectAwareIndex::indexedFiles()
const {
116 trace::Span Tracer(
"ProjectAwareIndex::indexedFiles");
117 if (
auto *Idx = getIndex())
118 return Idx->indexedFiles();
122SymbolIndex *ProjectAwareIndex::getIndex()
const {
126 const auto &External =
C.Index.External;
127 std::lock_guard<std::mutex> Lock(Mu);
128 auto Entry = IndexForSpec.try_emplace(External,
nullptr);
130 Entry.first->getSecond() = Gen(External, Tasks.get());
131 return Entry.first->second.get();
138 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.