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;
161 StaticContainsFile{Static->
indexedFiles()}](llvm::StringRef FileURI) {
162 return DynamicContainsFile(FileURI) | StaticContainsFile(FileURI);
169 uint32_t Remaining = Req.
Limit.value_or(std::numeric_limits<uint32_t>::max());
173 llvm::DenseSet<std::pair<SymbolID, SymbolID>> SeenRelations;
176 SeenRelations.insert(std::make_pair(Subject,
Object.ID));
183 !SeenRelations.count(std::make_pair(Subject,
Object.ID))) {
198 constexpr static const char *CodegenSuffixes[] = {
".proto"};
199 return llvm::any_of(CodegenSuffixes, [&](llvm::StringRef
Suffix) {
200 return llvm::StringRef(
Loc.FileURI).ends_with(
Suffix);
203 return HasCodeGenSuffix(L) && !HasCodeGenSuffix(R);
207 assert(L.ID == R.
ID);
217 Symbol S = PreferR ? R : L;
218 const Symbol &O = PreferR ? L : R;
226 if (S.Signature ==
"")
228 if (S.CompletionSnippetSuffix ==
"")
230 if (S.Documentation ==
"") {
235 bool IsClass = S.SymInfo.Kind == index::SymbolKind::Class ||
236 S.SymInfo.Kind == index::SymbolKind::Struct ||
237 S.SymInfo.Kind == index::SymbolKind::Union;
238 if (!IsClass || !S.Definition)
241 if (S.ReturnType ==
"")
247 for (
auto &SI : S.IncludeHeaders) {
248 if (SI.IncludeHeader == OI.IncludeHeader) {
250 SI.References += OI.References;
251 SI.SupportedDirectives |= OI.SupportedDirectives;
255 if (!Found && MergeIncludes)
256 S.IncludeHeaders.emplace_back(OI.IncludeHeader, OI.References,
257 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 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 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++ -*-===//
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.