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 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)
80 Total += Entry.second->estimateMemoryUsage();
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())
89 Idx->lookup(Req, Callback);
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())
97 return Idx->refs(Req, Callback);
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();
132 return [](llvm::StringRef) {
return IndexContents::None; };
135SymbolIndex *ProjectAwareIndex::getIndex()
const {
136 const auto &
C = Config::current();
137 if (
C.Index.External.Kind == Config::ExternalIndexSpec::None)
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);
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++ -*-===//