17#include "llvm/ADT/DenseMap.h"
18#include "llvm/ADT/StringRef.h"
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 reverseRelations(
const RelationsRequest &,
56 llvm::function_ref<
void(
const SymbolID &,
const Symbol &)>)
60 indexedFiles()
const override;
62 ProjectAwareIndex(
IndexFactory Gen,
bool Sync) : Gen(std::move(Gen)) {
64 Tasks = std::make_unique<AsyncTaskRunner>();
69 SymbolIndex *getIndex()
const;
72 mutable std::mutex Mu;
73 mutable llvm::DenseMap<Config::ExternalIndexSpec,
74 std::unique_ptr<SymbolIndex>>
76 mutable std::unique_ptr<AsyncTaskRunner> Tasks;
81size_t ProjectAwareIndex::estimateMemoryUsage()
const {
83 std::lock_guard<std::mutex> Lock(Mu);
84 for (
auto &Entry : IndexForSpec)
85 Total += Entry.second->estimateMemoryUsage();
89void ProjectAwareIndex::lookup(
90 const LookupRequest &Req,
91 llvm::function_ref<
void(
const Symbol &)>
Callback)
const {
92 trace::Span Tracer(
"ProjectAwareIndex::lookup");
93 if (
auto *Idx = getIndex())
94 Idx->lookup(Req, Callback);
97bool ProjectAwareIndex::refs(
98 const RefsRequest &Req,
99 llvm::function_ref<
void(
const Ref &)>
Callback)
const {
100 trace::Span Tracer(
"ProjectAwareIndex::refs");
101 if (
auto *Idx = getIndex())
102 return Idx->refs(Req, Callback);
106bool ProjectAwareIndex::containedRefs(
107 const ContainedRefsRequest &Req,
108 llvm::function_ref<
void(
const ContainedRefsResult &)>
Callback)
const {
109 trace::Span Tracer(
"ProjectAwareIndex::refersTo");
110 if (
auto *Idx = getIndex())
111 return Idx->containedRefs(Req, Callback);
115bool ProjectAwareIndex::fuzzyFind(
116 const FuzzyFindRequest &Req,
117 llvm::function_ref<
void(
const Symbol &)>
Callback)
const {
118 trace::Span Tracer(
"ProjectAwareIndex::fuzzyFind");
119 if (
auto *Idx = getIndex())
120 return Idx->fuzzyFind(Req, Callback);
124void ProjectAwareIndex::relations(
125 const RelationsRequest &Req,
126 llvm::function_ref<
void(
const SymbolID &,
const Symbol &)>
Callback)
const {
127 trace::Span Tracer(
"ProjectAwareIndex::relations");
128 if (
auto *Idx = getIndex())
129 return Idx->relations(Req, Callback);
132void ProjectAwareIndex::reverseRelations(
133 const RelationsRequest &Req,
134 llvm::function_ref<
void(
const SymbolID &,
const Symbol &)>
Callback)
const {
135 trace::Span Tracer(
"ProjectAwareIndex::relations");
136 if (
auto *Idx = getIndex())
137 return Idx->reverseRelations(Req, Callback);
141ProjectAwareIndex::indexedFiles()
const {
142 trace::Span Tracer(
"ProjectAwareIndex::indexedFiles");
143 if (
auto *Idx = getIndex())
144 return Idx->indexedFiles();
145 return [](llvm::StringRef) {
return IndexContents::None; };
148SymbolIndex *ProjectAwareIndex::getIndex()
const {
149 const auto &
C = Config::current();
150 if (
C.Index.External.Kind == Config::ExternalIndexSpec::None)
152 const auto &External =
C.Index.External;
153 std::lock_guard<std::mutex> Lock(Mu);
154 auto Entry = IndexForSpec.try_emplace(External,
nullptr);
156 Entry.first->getSecond() = Gen(External, Tasks.get());
157 return Entry.first->second.get();
164 return std::make_unique<ProjectAwareIndex>(std::move(Gen), Sync);
Interface for symbol indexes that can be used for searching or matching symbols among a set of symbol...
FIXME: Skip testing on windows temporarily due to the different escaping code mode.
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>.
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)
std::function< std::unique_ptr< SymbolIndex >( const Config::ExternalIndexSpec &, AsyncTaskRunner *)> IndexFactory
A functor to create an index for an external index specification.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//