14#include "llvm/ADT/StringRef.h"
28 const char *OwningFile =
29 S.Definition ? S.Definition.FileURI : S.CanonicalDeclaration.FileURI;
46 unsigned DynamicCount = 0;
47 unsigned StaticCount = 0;
48 unsigned MergedCount = 0;
50 unsigned StaticDropped = 0;
57 llvm::DenseSet<SymbolID> ReportedDynSymbols;
62 auto DynS = Dyn.
find(S.ID);
64 if (DynS != Dyn.
end()) {
66 ReportedDynSymbols.insert(S.ID);
67 return Callback(mergeSymbol(*DynS, S));
72 if (isIndexAuthoritative(DynamicContainsFile, S)) {
83 SPAN_ATTACH(Tracer,
"static_dropped", StaticDropped);
85 for (
const Symbol &S : Dyn)
86 if (!ReportedDynSymbols.count(S.ID))
97 Dynamic->
lookup(Req, [&](
const Symbol &S) { B.insert(S); });
99 auto RemainingIDs = Req.
IDs;
104 if (
const Symbol *Sym = B.find(S.ID)) {
105 RemainingIDs.erase(S.ID);
106 return Callback(mergeSymbol(*Sym, S));
111 if (isIndexAuthoritative(DynamicContainsFile, S))
116 RemainingIDs.erase(S.ID);
120 for (
const auto &
ID : RemainingIDs)
126 llvm::function_ref<
void(
const Ref &)>
Callback)
const {
129 uint32_t Remaining = Req.
Limit.value_or(std::numeric_limits<uint32_t>::max());
134 More |= Dynamic->
refs(Req, [&](
const Ref &O) {
136 assert(Remaining != 0);
139 if (Remaining == 0 && More)
144 bool StaticHadMore = Static->
refs(Req, [&](
const Ref &O) {
148 if (Remaining == 0) {
155 return More || StaticHadMore;
163 uint32_t Remaining = Req.
Limit.value_or(std::numeric_limits<uint32_t>::max());
170 assert(Remaining != 0);
173 if (Remaining == 0 && More)
178 bool StaticHadMore = Static->
containedRefs(Req, [&](
const auto &O) {
182 if (Remaining == 0) {
189 return More || StaticHadMore;
195 StaticContainsFile{Static->
indexedFiles()}](llvm::StringRef FileURI) {
196 return DynamicContainsFile(FileURI) | StaticContainsFile(FileURI);
203 uint32_t Remaining = Req.
Limit.value_or(std::numeric_limits<uint32_t>::max());
207 llvm::DenseSet<std::pair<SymbolID, SymbolID>> SeenRelations;
210 SeenRelations.insert(std::make_pair(Subject,
Object.ID));
217 !SeenRelations.count(std::make_pair(Subject,
Object.ID))) {
232 constexpr static const char *CodegenSuffixes[] = {
".proto"};
233 return llvm::any_of(CodegenSuffixes, [&](llvm::StringRef
Suffix) {
234 return llvm::StringRef(
Loc.FileURI).ends_with(
Suffix);
237 return HasCodeGenSuffix(L) && !HasCodeGenSuffix(R);
241 assert(L.ID == R.
ID);
251 Symbol S = PreferR ? R : L;
252 const Symbol &O = PreferR ? L : R;
260 if (S.Signature ==
"")
262 if (S.CompletionSnippetSuffix ==
"")
264 if (S.Documentation ==
"") {
269 bool IsClass = S.SymInfo.Kind == index::SymbolKind::Class ||
270 S.SymInfo.Kind == index::SymbolKind::Struct ||
271 S.SymInfo.Kind == index::SymbolKind::Union;
272 if (!IsClass || !S.Definition)
275 if (S.ReturnType ==
"")
281 for (
auto &SI : S.IncludeHeaders) {
282 if (SI.IncludeHeader == OI.IncludeHeader) {
284 SI.References += OI.References;
285 SI.SupportedDirectives |= OI.SupportedDirectives;
289 if (!Found && MergeIncludes)
290 S.IncludeHeaders.emplace_back(OI.IncludeHeader, OI.References,
291 OI.supportedDirectives());
#define SPAN_ATTACH(S, Name, Expr)
Attach a key-value pair to a Span event.
void relations(const RelationsRequest &, llvm::function_ref< void(const SymbolID &, const Symbol &)>) const override
bool containedRefs(const ContainedRefsRequest &, llvm::function_ref< void(const ContainedRefsResult &)>) const override
Find all symbols that are referenced by a symbol and apply Callback on each result.
bool refs(const RefsRequest &, llvm::function_ref< void(const Ref &)>) const override
Finds all occurrences (e.g.
void lookup(const LookupRequest &, llvm::function_ref< void(const Symbol &)>) const override
Looks up symbols with any of the given symbol IDs and applies Callback on each matched symbol.
bool fuzzyFind(const FuzzyFindRequest &, llvm::function_ref< void(const Symbol &)>) const override
Matches symbols in the index fuzzily and applies Callback on each matched symbol before returning.
llvm::unique_function< IndexContents(llvm::StringRef) const > indexedFiles() const override
virtual bool fuzzyFind(const FuzzyFindRequest &Req, llvm::function_ref< void(const Symbol &)> Callback) const =0
Matches symbols in the index fuzzily and applies Callback on each matched symbol before returning.
virtual bool containedRefs(const ContainedRefsRequest &Req, llvm::function_ref< void(const ContainedRefsResult &)> Callback) const =0
Find all symbols that are referenced by a symbol and apply Callback on each result.
virtual void relations(const RelationsRequest &Req, llvm::function_ref< void(const SymbolID &Subject, const Symbol &Object)> Callback) const =0
Finds all relations (S, P, O) stored in the index such that S is among Req.Subjects and P is Req....
virtual bool refs(const RefsRequest &Req, llvm::function_ref< void(const Ref &)> Callback) const =0
Finds all occurrences (e.g.
virtual void lookup(const LookupRequest &Req, llvm::function_ref< void(const Symbol &)> Callback) const =0
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
Returns function which checks if the specified file was used to build this index or not.
virtual IndexedFiles indexedFiles() const =0
SymbolSlab::Builder is a mutable container that can 'freeze' to SymbolSlab.
void insert(const Symbol &S)
Adds a symbol, overwriting any existing one with the same ID.
An immutable symbol container that stores a set of symbols.
const_iterator end() const
const_iterator find(const SymbolID &SymID) const
Records an event whose duration is the lifetime of the Span object.
IndexContents
Describes what data is covered by an index.
Symbol mergeSymbol(const Symbol &L, const Symbol &R)
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
static bool prefer(const SymbolLocation &L, const SymbolLocation &R)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::optional< uint32_t > Limit
If set, limit the number of refers returned from the index.
llvm::DenseSet< SymbolID > IDs
Represents a symbol occurrence in the source file.
SymbolLocation Location
The source location where the symbol is named.
std::optional< uint32_t > Limit
If set, limit the number of refers returned from the index.
std::optional< uint32_t > Limit
If set, limit the number of relations returned from the index.
The class presents a C++ symbol, e.g.
SymbolLocation Definition
The location of the symbol's definition, if one was found.
llvm::StringRef Type
Raw representation of the OpaqueType of the symbol, used for scoring purposes.
llvm::StringRef Documentation
Documentation including comment for the symbol declaration.
llvm::SmallVector< IncludeHeaderWithReferences, 1 > IncludeHeaders
One Symbol can potentially be included via different headers.
llvm::StringRef Signature
A brief description of the symbol that can be appended in the completion candidate list.
unsigned References
The number of translation units that reference this symbol from their main file.
llvm::StringRef ReturnType
Type when this symbol is used in an expression.
SymbolLocation CanonicalDeclaration
The location of the preferred declaration of the symbol.
llvm::StringRef CompletionSnippetSuffix
What to insert when completing this symbol, after the symbol name.
SymbolID ID
The ID of the symbol.
SymbolOrigin Origin
Where this symbol came from. Usually an index provides a constant value.