clang-tools  15.0.0git
Dex.cpp
Go to the documentation of this file.
1 //===--- Dex.cpp - Dex Symbol Index Implementation --------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "Dex.h"
10 #include "FileDistance.h"
11 #include "FuzzyMatch.h"
12 #include "Quality.h"
13 #include "URI.h"
14 #include "index/Index.h"
15 #include "index/dex/Iterator.h"
16 #include "index/dex/Token.h"
17 #include "index/dex/Trigram.h"
18 #include "support/Logger.h"
19 #include "support/Trace.h"
20 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/ADT/StringMap.h"
22 #include "llvm/ADT/StringSet.h"
23 #include "llvm/Support/Path.h"
24 #include "llvm/Support/ScopedPrinter.h"
25 #include <algorithm>
26 #include <queue>
27 #include <utility>
28 #include <vector>
29 
30 namespace clang {
31 namespace clangd {
32 namespace dex {
33 
34 std::unique_ptr<SymbolIndex> Dex::build(SymbolSlab Symbols, RefSlab Refs,
35  RelationSlab Rels) {
36  auto Size = Symbols.bytes() + Refs.bytes();
37  // There is no need to include "Rels" in Data because the relations are self-
38  // contained, without references into a backing store.
39  auto Data = std::make_pair(std::move(Symbols), std::move(Refs));
40  return std::make_unique<Dex>(Data.first, Data.second, Rels, std::move(Data),
41  Size);
42 }
43 
44 namespace {
45 
46 // Mark symbols which are can be used for code completion.
47 const Token RestrictedForCodeCompletion =
48  Token(Token::Kind::Sentinel, "Restricted For Code Completion");
49 
50 // Helper to efficiently assemble the inverse index (token -> matching docs).
51 // The output is a nice uniform structure keyed on Token, but constructing
52 // the Token object every time we want to insert into the map is wasteful.
53 // Instead we have various maps keyed on things that are cheap to compute,
54 // and produce the Token keys once at the end.
55 class IndexBuilder {
56  llvm::DenseMap<Trigram, std::vector<DocID>> TrigramDocs;
57  std::vector<DocID> RestrictedCCDocs;
58  llvm::StringMap<std::vector<DocID>> TypeDocs;
59  llvm::StringMap<std::vector<DocID>> ScopeDocs;
60  llvm::StringMap<std::vector<DocID>> ProximityDocs;
61  std::vector<Trigram> TrigramScratch;
62 
63 public:
64  // Add the tokens which are given symbol's characteristics.
65  // This includes fuzzy matching trigrams, symbol's scope, etc.
66  // FIXME(kbobyrev): Support more token types:
67  // * Namespace proximity
68  void add(const Symbol &Sym, DocID D) {
69  generateIdentifierTrigrams(Sym.Name, TrigramScratch);
70  for (Trigram T : TrigramScratch)
71  TrigramDocs[T].push_back(D);
72  ScopeDocs[Sym.Scope].push_back(D);
73  if (!llvm::StringRef(Sym.CanonicalDeclaration.FileURI).empty())
74  for (const auto &ProximityURI :
76  ProximityDocs[ProximityURI].push_back(D);
78  RestrictedCCDocs.push_back(D);
79  if (!Sym.Type.empty())
80  TypeDocs[Sym.Type].push_back(D);
81  }
82 
83  // Assemble the final compressed posting lists for the added symbols.
84  llvm::DenseMap<Token, PostingList> build() && {
85  llvm::DenseMap<Token, PostingList> Result(/*InitialReserve=*/
86  TrigramDocs.size() +
87  RestrictedCCDocs.size() +
88  TypeDocs.size() +
89  ScopeDocs.size() +
90  ProximityDocs.size());
91  // Tear down intermediate structs as we go to reduce memory usage.
92  // Since we're trying to get rid of underlying allocations, clearing the
93  // containers is not enough.
94  auto CreatePostingList =
95  [&Result](Token::Kind TK, llvm::StringMap<std::vector<DocID>> &Docs) {
96  for (auto &E : Docs) {
97  Result.try_emplace(Token(TK, E.first()), E.second);
98  E.second = {};
99  }
100  Docs = {};
101  };
102  CreatePostingList(Token::Kind::Type, TypeDocs);
103  CreatePostingList(Token::Kind::Scope, ScopeDocs);
104  CreatePostingList(Token::Kind::ProximityURI, ProximityDocs);
105 
106  // TrigramDocs are stored in a DenseMap and RestrictedCCDocs is not even a
107  // map, treat them specially.
108  for (auto &E : TrigramDocs) {
109  Result.try_emplace(Token(Token::Kind::Trigram, E.first.str()), E.second);
110  E.second = {};
111  }
112  TrigramDocs = llvm::DenseMap<Trigram, std::vector<DocID>>{};
113  if (!RestrictedCCDocs.empty())
114  Result.try_emplace(RestrictedForCodeCompletion,
115  std::move(RestrictedCCDocs));
116  return Result;
117  }
118 };
119 
120 } // namespace
121 
122 void Dex::buildIndex() {
123  this->Corpus = dex::Corpus(Symbols.size());
124  std::vector<std::pair<float, const Symbol *>> ScoredSymbols(Symbols.size());
125 
126  for (size_t I = 0; I < Symbols.size(); ++I) {
127  const Symbol *Sym = Symbols[I];
128  LookupTable[Sym->ID] = Sym;
129  ScoredSymbols[I] = {quality(*Sym), Sym};
130  }
131 
132  // Symbols are sorted by symbol qualities so that items in the posting lists
133  // are stored in the descending order of symbol quality.
134  llvm::sort(ScoredSymbols, std::greater<std::pair<float, const Symbol *>>());
135 
136  // SymbolQuality was empty up until now.
137  SymbolQuality.resize(Symbols.size());
138  // Populate internal storage using Symbol + Score pairs.
139  for (size_t I = 0; I < ScoredSymbols.size(); ++I) {
140  SymbolQuality[I] = ScoredSymbols[I].first;
141  Symbols[I] = ScoredSymbols[I].second;
142  }
143 
144  // Build posting lists for symbols.
145  IndexBuilder Builder;
146  for (DocID SymbolRank = 0; SymbolRank < Symbols.size(); ++SymbolRank)
147  Builder.add(*Symbols[SymbolRank], SymbolRank);
148  InvertedIndex = std::move(Builder).build();
149 }
150 
151 std::unique_ptr<Iterator> Dex::iterator(const Token &Tok) const {
152  auto It = InvertedIndex.find(Tok);
153  return It == InvertedIndex.end() ? Corpus.none()
154  : It->second.iterator(&It->first);
155 }
156 
157 // Constructs BOOST iterators for Path Proximities.
158 std::unique_ptr<Iterator> Dex::createFileProximityIterator(
159  llvm::ArrayRef<std::string> ProximityPaths) const {
160  std::vector<std::unique_ptr<Iterator>> BoostingIterators;
161  // Deduplicate parent URIs extracted from the ProximityPaths.
162  llvm::StringSet<> ParentURIs;
163  llvm::StringMap<SourceParams> Sources;
164  for (const auto &Path : ProximityPaths) {
165  Sources[Path] = SourceParams();
166  auto PathURI = URI::create(Path);
167  const auto PathProximityURIs = generateProximityURIs(PathURI.toString());
168  for (const auto &ProximityURI : PathProximityURIs)
169  ParentURIs.insert(ProximityURI);
170  }
171  // Use SymbolRelevanceSignals for symbol relevance evaluation: use defaults
172  // for all parameters except for Proximity Path distance signal.
173  SymbolRelevanceSignals PathProximitySignals;
174  // DistanceCalculator will find the shortest distance from ProximityPaths to
175  // any URI extracted from the ProximityPaths.
176  URIDistance DistanceCalculator(Sources);
177  PathProximitySignals.FileProximityMatch = &DistanceCalculator;
178  // Try to build BOOST iterator for each Proximity Path provided by
179  // ProximityPaths. Boosting factor should depend on the distance to the
180  // Proximity Path: the closer processed path is, the higher boosting factor.
181  for (const auto &ParentURI : ParentURIs.keys()) {
182  // FIXME(kbobyrev): Append LIMIT on top of every BOOST iterator.
183  auto It = iterator(Token(Token::Kind::ProximityURI, ParentURI));
184  if (It->kind() != Iterator::Kind::False) {
185  PathProximitySignals.SymbolURI = ParentURI;
186  BoostingIterators.push_back(Corpus.boost(
187  std::move(It), PathProximitySignals.evaluateHeuristics()));
188  }
189  }
190  BoostingIterators.push_back(Corpus.all());
191  return Corpus.unionOf(std::move(BoostingIterators));
192 }
193 
194 // Constructs BOOST iterators for preferred types.
195 std::unique_ptr<Iterator>
196 Dex::createTypeBoostingIterator(llvm::ArrayRef<std::string> Types) const {
197  std::vector<std::unique_ptr<Iterator>> BoostingIterators;
198  SymbolRelevanceSignals PreferredTypeSignals;
199  PreferredTypeSignals.TypeMatchesPreferred = true;
200  auto Boost = PreferredTypeSignals.evaluateHeuristics();
201  for (const auto &T : Types)
202  BoostingIterators.push_back(
203  Corpus.boost(iterator(Token(Token::Kind::Type, T)), Boost));
204  BoostingIterators.push_back(Corpus.all());
205  return Corpus.unionOf(std::move(BoostingIterators));
206 }
207 
208 /// Constructs iterators over tokens extracted from the query and exhausts it
209 /// while applying Callback to each symbol in the order of decreasing quality
210 /// of the matched symbols.
212  llvm::function_ref<void(const Symbol &)> Callback) const {
213  assert(!StringRef(Req.Query).contains("::") &&
214  "There must be no :: in query.");
215  trace::Span Tracer("Dex fuzzyFind");
216  FuzzyMatcher Filter(Req.Query);
217  // For short queries we use specialized trigrams that don't yield all results.
218  // Prevent clients from postfiltering them for longer queries.
219  bool More = !Req.Query.empty() && Req.Query.size() < 3;
220 
221  std::vector<std::unique_ptr<Iterator>> Criteria;
222  const auto TrigramTokens = generateQueryTrigrams(Req.Query);
223 
224  // Generate query trigrams and construct AND iterator over all query
225  // trigrams.
226  std::vector<std::unique_ptr<Iterator>> TrigramIterators;
227  for (const auto &Trigram : TrigramTokens)
228  TrigramIterators.push_back(iterator(Trigram));
229  Criteria.push_back(Corpus.intersect(std::move(TrigramIterators)));
230 
231  // Generate scope tokens for search query.
232  std::vector<std::unique_ptr<Iterator>> ScopeIterators;
233  for (const auto &Scope : Req.Scopes)
234  ScopeIterators.push_back(iterator(Token(Token::Kind::Scope, Scope)));
235  if (Req.AnyScope)
236  ScopeIterators.push_back(
237  Corpus.boost(Corpus.all(), ScopeIterators.empty() ? 1.0 : 0.2));
238  Criteria.push_back(Corpus.unionOf(std::move(ScopeIterators)));
239 
240  // Add proximity paths boosting (all symbols, some boosted).
241  Criteria.push_back(createFileProximityIterator(Req.ProximityPaths));
242  // Add boosting for preferred types.
243  Criteria.push_back(createTypeBoostingIterator(Req.PreferredTypes));
244 
246  Criteria.push_back(iterator(RestrictedForCodeCompletion));
247 
248  // Use TRUE iterator if both trigrams and scopes from the query are not
249  // present in the symbol index.
250  auto Root = Corpus.intersect(std::move(Criteria));
251  // Retrieve more items than it was requested: some of the items with high
252  // final score might not be retrieved otherwise.
253  // FIXME(kbobyrev): Tune this ratio.
254  if (Req.Limit)
255  Root = Corpus.limit(std::move(Root), *Req.Limit * 100);
256  SPAN_ATTACH(Tracer, "query", llvm::to_string(*Root));
257  vlog("Dex query tree: {0}", *Root);
258 
259  using IDAndScore = std::pair<DocID, float>;
260  std::vector<IDAndScore> IDAndScores = consume(*Root);
261 
262  auto Compare = [](const IDAndScore &LHS, const IDAndScore &RHS) {
263  return LHS.second > RHS.second;
264  };
265  TopN<IDAndScore, decltype(Compare)> Top(
266  Req.Limit ? *Req.Limit : std::numeric_limits<size_t>::max(), Compare);
267  for (const auto &IDAndScore : IDAndScores) {
268  const DocID SymbolDocID = IDAndScore.first;
269  const auto *Sym = Symbols[SymbolDocID];
270  const llvm::Optional<float> Score = Filter.match(Sym->Name);
271  if (!Score)
272  continue;
273  // Combine Fuzzy Matching score, precomputed symbol quality and boosting
274  // score for a cumulative final symbol score.
275  const float FinalScore =
276  (*Score) * SymbolQuality[SymbolDocID] * IDAndScore.second;
277  // If Top.push(...) returns true, it means that it had to pop an item. In
278  // this case, it is possible to retrieve more symbols.
279  if (Top.push({SymbolDocID, FinalScore}))
280  More = true;
281  }
282 
283  // Apply callback to the top Req.Limit items in the descending
284  // order of cumulative score.
285  for (const auto &Item : std::move(Top).items())
286  Callback(*Symbols[Item.first]);
287  return More;
288 }
289 
290 void Dex::lookup(const LookupRequest &Req,
291  llvm::function_ref<void(const Symbol &)> Callback) const {
292  trace::Span Tracer("Dex lookup");
293  for (const auto &ID : Req.IDs) {
294  auto I = LookupTable.find(ID);
295  if (I != LookupTable.end())
296  Callback(*I->second);
297  }
298 }
299 
300 bool Dex::refs(const RefsRequest &Req,
301  llvm::function_ref<void(const Ref &)> Callback) const {
302  trace::Span Tracer("Dex refs");
303  uint32_t Remaining = Req.Limit.value_or(std::numeric_limits<uint32_t>::max());
304  for (const auto &ID : Req.IDs)
305  for (const auto &Ref : Refs.lookup(ID)) {
306  if (!static_cast<int>(Req.Filter & Ref.Kind))
307  continue;
308  if (Remaining == 0)
309  return true; // More refs were available.
310  --Remaining;
311  Callback(Ref);
312  }
313  return false; // We reported all refs.
314 }
315 
317  const RelationsRequest &Req,
318  llvm::function_ref<void(const SymbolID &, const Symbol &)> Callback) const {
319  trace::Span Tracer("Dex relations");
320  uint32_t Remaining = Req.Limit.value_or(std::numeric_limits<uint32_t>::max());
321  for (const SymbolID &Subject : Req.Subjects) {
322  LookupRequest LookupReq;
323  auto It = Relations.find(
324  std::make_pair(Subject, static_cast<uint8_t>(Req.Predicate)));
325  if (It != Relations.end()) {
326  for (const auto &Object : It->second) {
327  if (Remaining > 0) {
328  --Remaining;
329  LookupReq.IDs.insert(Object);
330  }
331  }
332  }
333  lookup(LookupReq, [&](const Symbol &Object) { Callback(Subject, Object); });
334  }
335 }
336 
337 llvm::unique_function<IndexContents(llvm::StringRef) const>
339  return [this](llvm::StringRef FileURI) {
340  return Files.contains(FileURI) ? IdxContents : IndexContents::None;
341  };
342 }
343 
344 size_t Dex::estimateMemoryUsage() const {
345  size_t Bytes = Symbols.size() * sizeof(const Symbol *);
346  Bytes += SymbolQuality.size() * sizeof(float);
347  Bytes += LookupTable.getMemorySize();
348  Bytes += InvertedIndex.getMemorySize();
349  for (const auto &TokenToPostingList : InvertedIndex)
350  Bytes += TokenToPostingList.second.bytes();
351  Bytes += Refs.getMemorySize();
352  Bytes += Relations.getMemorySize();
353  return Bytes + BackingDataSize;
354 }
355 
356 std::vector<std::string> generateProximityURIs(llvm::StringRef URIPath) {
357  std::vector<std::string> Result;
358  auto ParsedURI = URI::parse(URIPath);
359  assert(ParsedURI &&
360  "Non-empty argument of generateProximityURIs() should be a valid "
361  "URI.");
362  llvm::StringRef Body = ParsedURI->body();
363  // FIXME(kbobyrev): Currently, this is a heuristic which defines the maximum
364  // size of resulting vector. Some projects might want to have higher limit if
365  // the file hierarchy is deeper. For the generic case, it would be useful to
366  // calculate Limit in the index build stage by calculating the maximum depth
367  // of the project source tree at runtime.
368  size_t Limit = 5;
369  // Insert original URI before the loop: this would save a redundant iteration
370  // with a URI parse.
371  Result.emplace_back(ParsedURI->toString());
372  while (!Body.empty() && --Limit > 0) {
373  // FIXME(kbobyrev): Parsing and encoding path to URIs is not necessary and
374  // could be optimized.
375  Body = llvm::sys::path::parent_path(Body, llvm::sys::path::Style::posix);
376  if (!Body.empty())
377  Result.emplace_back(
378  URI(ParsedURI->scheme(), ParsedURI->authority(), Body).toString());
379  }
380  return Result;
381 }
382 
383 } // namespace dex
384 } // namespace clangd
385 } // namespace clang
clang::clangd::Ref::Kind
RefKind Kind
Definition: Ref.h:88
clang::clangd::Symbol::IndexedForCodeCompletion
@ IndexedForCodeCompletion
Whether or not this symbol is meant to be used for the code completion.
Definition: Symbol.h:119
Dex.h
clang::clangd::dex::Corpus::boost
std::unique_ptr< Iterator > boost(std::unique_ptr< Iterator > Child, float Factor) const
Returns BOOST iterator which multiplies the score of each item by given factor.
Definition: Iterator.cpp:432
clang::clangd::dex::Dex::lookup
void lookup(const LookupRequest &Req, llvm::function_ref< void(const Symbol &)> Callback) const override
Looks up symbols with any of the given symbol IDs and applies Callback on each matched symbol.
Definition: Dex.cpp:290
E
const Expr * E
Definition: AvoidBindCheck.cpp:88
clang::clangd::dex::Dex::relations
void relations(const RelationsRequest &Req, llvm::function_ref< void(const SymbolID &, const Symbol &)> Callback) const override
Definition: Dex.cpp:316
Trigram.h
Refs
RefSlab Refs
Definition: SymbolCollectorTests.cpp:312
clang::clangd::Path
std::string Path
A typedef to represent a file path.
Definition: Path.h:26
clang::clangd::FuzzyFindRequest::PreferredTypes
std::vector< std::string > PreferredTypes
Preferred types of symbols. These are raw representation of OpaqueType.
Definition: Index.h:49
Tracer
std::unique_ptr< trace::EventTracer > Tracer
Definition: TraceTests.cpp:161
clang::clangd::RelationsRequest::Limit
llvm::Optional< uint32_t > Limit
If set, limit the number of relations returned from the index.
Definition: Index.h:84
clang::clangd::SymbolKind::Object
@ Object
clang::clangd::dex::consume
std::vector< std::pair< DocID, float > > consume(Iterator &It)
Advances the iterator until it is exhausted.
Definition: Iterator.cpp:357
clang::clangd::dex::Trigram
Definition: Trigram.h:38
Index.h
Root
ASTNode Root
Definition: DumpAST.cpp:332
clang::clangd::URI::create
static llvm::Expected< URI > create(llvm::StringRef AbsolutePath, llvm::StringRef Scheme)
Creates a URI for a file in the given scheme.
Definition: URI.cpp:209
clang::clangd::dex::Corpus::all
std::unique_ptr< Iterator > all() const
Returns TRUE Iterator which iterates over "virtual" PostingList containing all items in range [0,...
Definition: Iterator.cpp:424
clang::clangd::FuzzyFindRequest::Scopes
std::vector< std::string > Scopes
If this is non-empty, symbols must be in at least one of the scopes (e.g.
Definition: Index.h:36
Trace.h
clang::clangd::dex::Dex::build
static std::unique_ptr< SymbolIndex > build(SymbolSlab, RefSlab, RelationSlab)
Builds an index from slabs. The index takes ownership of the slab.
Definition: Dex.cpp:34
clang::clangd::dex::Corpus::intersect
std::unique_ptr< Iterator > intersect(std::vector< std::unique_ptr< Iterator >> Children) const
Returns AND Iterator which performs the intersection of the PostingLists of its children.
Definition: Iterator.cpp:365
clang::clangd::RelationsRequest::Predicate
RelationKind Predicate
Definition: Index.h:82
clang::clangd::RefSlab
An efficient structure of storing large set of symbol references in memory.
Definition: Ref.h:108
clang::clangd::FuzzyFindRequest
Definition: Index.h:26
clang::clangd::dex::Corpus::none
std::unique_ptr< Iterator > none() const
Returns FALSE Iterator which iterates over no documents.
Definition: Iterator.cpp:428
clang::clangd::URI::parse
static llvm::Expected< URI > parse(llvm::StringRef Uri)
Parse a URI string "<scheme>:[//<authority>/]<path>".
Definition: URI.cpp:177
clang::clangd::dex::generateQueryTrigrams
std::vector< Token > generateQueryTrigrams(llvm::StringRef Query)
Returns list of unique fuzzy-search trigrams given a query.
Definition: Trigram.cpp:123
clang::clangd::FuzzyFindRequest::Query
std::string Query
A query string for the fuzzy find.
Definition: Index.h:29
clang::clangd::dex::Dex::estimateMemoryUsage
size_t estimateMemoryUsage() const override
Returns estimated size of index (in bytes).
Definition: Dex.cpp:344
clang::clangd::dex::Corpus
Definition: Iterator.h:133
clang::clangd::TopN::push
bool push(value_type &&V)
Definition: Quality.h:196
FileDistance.h
ns1::ns2::D
@ D
Definition: CategoricalFeature.h:3
FuzzyMatch.h
clang::clangd::TopN
TopN<T> is a lossy container that preserves only the "best" N elements.
Definition: Quality.h:188
clang::clangd::RelationsRequest::Subjects
llvm::DenseSet< SymbolID > Subjects
Definition: Index.h:81
clang::clangd::dex::Token::Kind::Scope
@ Scope
Scope primitives, e.g.
clang::clangd::RelationSlab
Definition: Relation.h:50
clang::clangd::dex::Token::Kind::ProximityURI
@ ProximityURI
Path Proximity URI to symbol declaration.
clang::clangd::dex::Token::Kind::Type
@ Type
Type of symbol (see Symbol::Type).
Builder
CodeCompletionBuilder Builder
Definition: CodeCompletionStringsTests.cpp:36
clang::clangd::dex::generateProximityURIs
std::vector< std::string > generateProximityURIs(llvm::StringRef URIPath)
Returns Search Token for a number of parent directories of given Path.
Definition: Dex.cpp:356
Logger.h
clang::clangd::Symbol
The class presents a C++ symbol, e.g.
Definition: Symbol.h:36
clang::clangd::dex::generateIdentifierTrigrams
void generateIdentifierTrigrams(llvm::StringRef Identifier, std::vector< Trigram > &Result)
Produces list of unique fuzzy-search trigrams from unqualified symbol.
Definition: Trigram.cpp:100
clang::clangd::Symbol::Flags
SymbolFlag Flags
Definition: Symbol.h:128
clang::clangd::IndexContents
IndexContents
Describes what data is covered by an index.
Definition: Index.h:93
clang::clangd::SymbolLocation::FileURI
const char * FileURI
Definition: SymbolLocation.h:64
SPAN_ATTACH
#define SPAN_ATTACH(S, Name, Expr)
Attach a key-value pair to a Span event.
Definition: Trace.h:164
clang::clangd::vlog
void vlog(const char *Fmt, Ts &&... Vals)
Definition: Logger.h:72
clang::clangd::Symbol::Name
llvm::StringRef Name
The unqualified name of the symbol, e.g. "bar" (for ns::bar).
Definition: Symbol.h:42
clang::clangd::RefsRequest::IDs
llvm::DenseSet< SymbolID > IDs
Definition: Index.h:69
clang::clangd::dex::Dex::indexedFiles
llvm::unique_function< IndexContents(llvm::StringRef) const > indexedFiles() const override
Definition: Dex.cpp:338
clang::clangd::dex::Token
A Token represents an attribute of a symbol, such as a particular trigram present in the name (used f...
Definition: Token.h:38
clang::clangd::FuzzyFindRequest::Limit
llvm::Optional< uint32_t > Limit
The number of top candidates to return.
Definition: Index.h:42
clang::clangd::Symbol::CanonicalDeclaration
SymbolLocation CanonicalDeclaration
The location of the preferred declaration of the symbol.
Definition: Symbol.h:56
clang::clangd::LookupRequest::IDs
llvm::DenseSet< SymbolID > IDs
Definition: Index.h:65
Iterator.h
clang::clangd::dex::Dex::refs
bool refs(const RefsRequest &Req, llvm::function_ref< void(const Ref &)> Callback) const override
Finds all occurrences (e.g.
Definition: Dex.cpp:300
clang::clangd::RefsRequest::Filter
RefKind Filter
Definition: Index.h:70
clang::clangd::LookupRequest
Definition: Index.h:64
clang::clangd::URI::toString
std::string toString() const
Returns a string URI with all components percent-encoded.
Definition: URI.cpp:160
clang::clangd::IndexContents::None
@ None
ID
static char ID
Definition: Logger.cpp:74
Score
llvm::Optional< float > Score
Definition: FuzzyMatchTests.cpp:47
clang::clangd::Ref
Represents a symbol occurrence in the source file.
Definition: Ref.h:85
clang::clangd::FuzzyMatcher
Definition: FuzzyMatch.h:71
clang::clangd::Symbol::Scope
llvm::StringRef Scope
The containing namespace. e.g. "" (global), "ns::" (top-level namespace).
Definition: Symbol.h:44
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::clangd::dex::Dex::fuzzyFind
bool fuzzyFind(const FuzzyFindRequest &Req, llvm::function_ref< void(const Symbol &)> Callback) const override
Constructs iterators over tokens extracted from the query and exhausts it while applying Callback to ...
Definition: Dex.cpp:211
clang::clangd::dex::Token::Kind::Sentinel
@ Sentinel
Internal Token type for invalid/special tokens, e.g.
clang::clangd::dex::DocID
uint32_t DocID
Symbol position in the list of all index symbols sorted by a pre-computed symbol quality.
Definition: Iterator.h:45
clang::clangd::dex::Token::Kind
Kind
Kind specifies Token type which defines semantics for the internal representation.
Definition: Token.h:47
clang::clangd::RefsRequest::Limit
llvm::Optional< uint32_t > Limit
If set, limit the number of refers returned from the index.
Definition: Index.h:74
clang::clangd::FuzzyFindRequest::AnyScope
bool AnyScope
If set to true, allow symbols from any scope.
Definition: Index.h:39
clang::clangd::dex::Corpus::limit
std::unique_ptr< Iterator > limit(std::unique_ptr< Iterator > Child, size_t Limit) const
Returns LIMIT iterator, which yields up to N elements of its child iterator.
Definition: Iterator.cpp:441
clang::clangd::Callback
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
Definition: Function.h:28
clang::clangd::RelationsRequest
Definition: Index.h:80
URI.h
Quality.h
clang::clangd::FuzzyFindRequest::RestrictForCodeCompletion
bool RestrictForCodeCompletion
If set to true, only symbols for completion support will be considered.
Definition: Index.h:44
clang::clangd::SymbolSlab
An immutable symbol container that stores a set of symbols.
Definition: Symbol.h:177
clang::clangd::SymbolID
Definition: SymbolID.h:32
clang::clangd::Symbol::Type
llvm::StringRef Type
Raw representation of the OpaqueType of the symbol, used for scoring purposes.
Definition: Symbol.h:85
Token.h
clang::clangd::RefsRequest
Definition: Index.h:68
clang::clangd::FuzzyFindRequest::ProximityPaths
std::vector< std::string > ProximityPaths
Contextually relevant files (e.g.
Definition: Index.h:47
clang::clangd::dex::Corpus::unionOf
std::unique_ptr< Iterator > unionOf(std::vector< std::unique_ptr< Iterator >> Children) const
Returns OR Iterator which performs the union of the PostingLists of its children.
Definition: Iterator.cpp:395
clang::clangd::URI
A URI describes the location of a source file.
Definition: URI.h:28
clang::clangd::quality
float quality(const Symbol &S)
Computes query-independent quality score for a Symbol.
Definition: Symbol.cpp:29
clang::clangd::dex::Iterator::Kind::False
@ False
clang::clangd::dex::Token::Kind::Trigram
@ Trigram
Represents trigram used for fuzzy search of unqualified symbol names.
clang::clangd::trace::Span
Records an event whose duration is the lifetime of the Span object.
Definition: Trace.h:143