clang-tools 8.0.0

Index.h
Go to the documentation of this file.
1 //===--- Index.h -------------------------------------------------*- C++-*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_H
12
13 #include "ExpectedTypes.h"
14 #include "SymbolID.h"
15 #include "clang/Index/IndexSymbol.h"
16 #include "clang/Lex/Lexer.h"
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/DenseSet.h"
19 #include "llvm/ADT/Optional.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/StringExtras.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/Support/JSON.h"
24 #include "llvm/Support/StringSaver.h"
25 #include <array>
26 #include <limits>
27 #include <mutex>
28 #include <string>
29 #include <tuple>
30
31 namespace clang {
32 namespace clangd {
33
34 struct SymbolLocation {
35 // Specify a position (Line, Column) of symbol. Using Line/Column allows us to
36 // build LSP responses without reading the file content.
37 //
38 // Position is encoded into 32 bits to save space.
39 // If Line/Column overflow, the value will be their maximum value.
40 struct Position {
41 Position() : Line(0), Column(0) {}
42 void setLine(uint32_t Line);
43 uint32_t line() const { return Line; }
44 void setColumn(uint32_t Column);
45 uint32_t column() const { return Column; }
46
47 bool hasOverflow() const {
48 return Line >= MaxLine || Column >= MaxColumn;
49 }
50
51 static constexpr uint32_t MaxLine = (1 << 20) - 1;
52 static constexpr uint32_t MaxColumn = (1 << 12) - 1;
53
54 private:
55 uint32_t Line : 20; // 0-based
56 // Using UTF-16 code units.
57 uint32_t Column : 12; // 0-based
58 };
59
60 /// The symbol range, using half-open range [Start, End).
61 Position Start;
62 Position End;
63
64 explicit operator bool() const { return !StringRef(FileURI).empty(); }
65
66 // The URI of the source file where a symbol occurs.
67 // The string must be null-terminated.
68 //
69 // We avoid using llvm::StringRef here to save memory.
70 // WARNING: unless you know what you are doing, it is recommended to use it
71 // via llvm::StringRef.
72 const char *FileURI = "";
73 };
74 inline bool operator==(const SymbolLocation::Position &L,
75 const SymbolLocation::Position &R) {
76 return std::make_tuple(L.line(), L.column()) ==
77 std::make_tuple(R.line(), R.column());
78 }
79 inline bool operator<(const SymbolLocation::Position &L,
80 const SymbolLocation::Position &R) {
81 return std::make_tuple(L.line(), L.column()) <
82 std::make_tuple(R.line(), R.column());
83 }
84 inline bool operator==(const SymbolLocation &L, const SymbolLocation &R) {
85 assert(L.FileURI && R.FileURI);
86 return !std::strcmp(L.FileURI, R.FileURI) &&
87 std::tie(L.Start, L.End) == std::tie(R.Start, R.End);
88 }
89 inline bool operator<(const SymbolLocation &L, const SymbolLocation &R) {
90 assert(L.FileURI && R.FileURI);
91 int Cmp = std::strcmp(L.FileURI, R.FileURI);
92 if (Cmp != 0)
93 return Cmp < 0;
94 return std::tie(L.Start, L.End) < std::tie(R.Start, R.End);
95 }
96 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SymbolLocation &);
97
98 } // namespace clangd
99 } // namespace clang
100 namespace llvm {
101 // Support SymbolIDs as DenseMap keys.
102 template <> struct DenseMapInfo<clang::clangd::SymbolID> {
103 static inline clang::clangd::SymbolID getEmptyKey() {
104 static clang::clangd::SymbolID EmptyKey("EMPTYKEY");
105 return EmptyKey;
106 }
107 static inline clang::clangd::SymbolID getTombstoneKey() {
108 static clang::clangd::SymbolID TombstoneKey("TOMBSTONEKEY");
109 return TombstoneKey;
110 }
111 static unsigned getHashValue(const clang::clangd::SymbolID &Sym) {
112 return hash_value(Sym);
113 }
114 static bool isEqual(const clang::clangd::SymbolID &LHS,
115 const clang::clangd::SymbolID &RHS) {
116 return LHS == RHS;
117 }
118 };
119 } // namespace llvm
120 namespace clang {
121 namespace clangd {
122
123 // Describes the source of information about a symbol.
124 // Mainly useful for debugging, e.g. understanding code completion reuslts.
125 // This is a bitfield as information can be combined from several sources.
126 enum class SymbolOrigin : uint8_t {
127 Unknown = 0,
128 AST = 1 << 0, // Directly from the AST (indexes should not set this).
129 Dynamic = 1 << 1, // From the dynamic index of opened files.
130 Static = 1 << 2, // From the static, externally-built index.
131 Merge = 1 << 3, // A non-trivial index merge was performed.
132 // Remaining bits reserved for index implementations.
133 };
134 inline SymbolOrigin operator|(SymbolOrigin A, SymbolOrigin B) {
135 return static_cast<SymbolOrigin>(static_cast<uint8_t>(A) |
136 static_cast<uint8_t>(B));
137 }
138 inline SymbolOrigin &operator|=(SymbolOrigin &A, SymbolOrigin B) {
139 return A = A | B;
140 }
141 inline SymbolOrigin operator&(SymbolOrigin A, SymbolOrigin B) {
142 return static_cast<SymbolOrigin>(static_cast<uint8_t>(A) &
143 static_cast<uint8_t>(B));
144 }
145 raw_ostream &operator<<(raw_ostream &, SymbolOrigin);
146
147 // The class presents a C++ symbol, e.g. class, function.
148 //
149 // WARNING: Symbols do not own much of their underlying data - typically strings
150 // are owned by a SymbolSlab. They should be treated as non-owning references.
151 // Copies are shallow.
152 // When adding new unowned data fields to Symbol, remember to update:
153 // - SymbolSlab::Builder in Index.cpp, to copy them to the slab's storage.
154 // - mergeSymbol in Merge.cpp, to properly combine two Symbols.
155 //
156 // A fully documented symbol can be split as:
157 // size_type std::map<k, t>::count(const K& key) const
158 // | Return | Scope |Name| Signature |
159 // We split up these components to allow display flexibility later.
160 struct Symbol {
161 // The ID of the symbol.
162 SymbolID ID;
163 // The symbol information, like symbol kind.
164 index::SymbolInfo SymInfo;
165 // The unqualified name of the symbol, e.g. "bar" (for ns::bar).
166 llvm::StringRef Name;
167 // The containing namespace. e.g. "" (global), "ns::" (top-level namespace).
168 llvm::StringRef Scope;
169 // The location of the symbol's definition, if one was found.
170 // This just covers the symbol name (e.g. without class/function body).
171 SymbolLocation Definition;
172 // The location of the preferred declaration of the symbol.
173 // This just covers the symbol name.
174 // This may be the same as Definition.
175 //
176 // A C++ symbol may have multiple declarations, and we pick one to prefer.
177 // * For classes, the canonical declaration should be the definition.
178 // * For non-inline functions, the canonical declaration typically appears
179 // in the ".h" file corresponding to the definition.
180 SymbolLocation CanonicalDeclaration;
181 // The number of translation units that reference this symbol from their main
182 // file. This number is only meaningful if aggregated in an index.
183 unsigned References = 0;
184 /// Where this symbol came from. Usually an index provides a constant value.
185 SymbolOrigin Origin = SymbolOrigin::Unknown;
186 /// A brief description of the symbol that can be appended in the completion
187 /// candidate list. For example, "(X x, Y y) const" is a function signature.
188 /// Only set when the symbol is indexed for completion.
189 llvm::StringRef Signature;
190 /// What to insert when completing this symbol, after the symbol name.
191 /// This is in LSP snippet syntax (e.g. "({$0})" for a no-args function).
192 /// (When snippets are disabled, the symbol name alone is used).
193 /// Only set when the symbol is indexed for completion.
194 llvm::StringRef CompletionSnippetSuffix;
195 /// Documentation including comment for the symbol declaration.
196 llvm::StringRef Documentation;
197 /// Type when this symbol is used in an expression. (Short display form).
198 /// e.g. return type of a function, or type of a variable.
199 /// Only set when the symbol is indexed for completion.
200 llvm::StringRef ReturnType;
201
202 /// Raw representation of the OpaqueType of the symbol, used for scoring
203 /// purposes.
204 /// Only set when the symbol is indexed for completion.
205 llvm::StringRef Type;
206
207 struct IncludeHeaderWithReferences {
208 IncludeHeaderWithReferences() = default;
209
210 IncludeHeaderWithReferences(llvm::StringRef IncludeHeader,
211 unsigned References)
212 : IncludeHeader(IncludeHeader), References(References) {}
213
214 /// This can be either a URI of the header to be #include'd
215 /// for this symbol, or a literal header quoted with <> or "" that is
216 /// suitable to be included directly. When it is a URI, the exact #include
217 /// path needs to be calculated according to the URI scheme.
218 ///
219 /// Note that the include header is a canonical include for the symbol and
220 /// can be different from FileURI in the CanonicalDeclaration.
221 llvm::StringRef IncludeHeader = "";
222 /// The number of translation units that reference this symbol and include
223 /// this header. This number is only meaningful if aggregated in an index.
224 unsigned References = 0;
225 };
226 /// One Symbol can potentially be incuded via different headers.
227 /// - If we haven't seen a definition, this covers all declarations.
228 /// - If we have seen a definition, this covers declarations visible from
229 /// any definition.
230 /// Only set when the symbol is indexed for completion.
231 llvm::SmallVector<IncludeHeaderWithReferences, 1> IncludeHeaders;
232
233 enum SymbolFlag : uint8_t {
234 None = 0,
235 /// Whether or not this symbol is meant to be used for the code completion.
236 /// See also isIndexedForCodeCompletion().
237 /// Note that we don't store completion information (signature, snippet,
238 /// type, inclues) if the symbol is not indexed for code completion.
239 IndexedForCodeCompletion = 1 << 0,
240 /// Indicates if the symbol is deprecated.
241 Deprecated = 1 << 1,
242 // Symbol is an implementation detail.
243 ImplementationDetail = 1 << 2,
244 // Symbol is visible to other files (not e.g. a static helper function).
245 VisibleOutsideFile = 1 << 3,
246 };
247
248 SymbolFlag Flags = SymbolFlag::None;
249 /// FIXME: also add deprecation message and fixit?
250 };
251 inline Symbol::SymbolFlag operator|(Symbol::SymbolFlag A, Symbol::SymbolFlag B) {
252 return static_cast<Symbol::SymbolFlag>(static_cast<uint8_t>(A) |
253 static_cast<uint8_t>(B));
254 }
255 inline Symbol::SymbolFlag &operator|=(Symbol::SymbolFlag &A, Symbol::SymbolFlag B) {
256 return A = A | B;
257 }
258 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Symbol &S);
259 raw_ostream &operator<<(raw_ostream &, Symbol::SymbolFlag);
260
261 // Invokes Callback with each StringRef& contained in the Symbol.
262 // Useful for deduplicating backing strings.
263 template <typename Callback> void visitStrings(Symbol &S, const Callback &CB) {
264 CB(S.Name);
265 CB(S.Scope);
266 CB(S.Signature);
267 CB(S.CompletionSnippetSuffix);
268 CB(S.Documentation);
269 CB(S.ReturnType);
270 CB(S.Type);
271 auto RawCharPointerCB = [&CB](const char *&P) {
272 llvm::StringRef S(P);
273 CB(S);
274 assert(!S.data()[S.size()] && "Visited StringRef must be null-terminated");
275 P = S.data();
276 };
277 RawCharPointerCB(S.CanonicalDeclaration.FileURI);
278 RawCharPointerCB(S.Definition.FileURI);
279
280 for (auto &Include : S.IncludeHeaders)
281 CB(Include.IncludeHeader);
282 }
283
284 // Computes query-independent quality score for a Symbol.
285 // This currently falls in the range [1, ln(#indexed documents)].
286 // FIXME: this should probably be split into symbol -> signals
287 // and signals -> score, so it can be reused for Sema completions.
288 float quality(const Symbol &S);
289
290 // An immutable symbol container that stores a set of symbols.
291 // The container will maintain the lifetime of the symbols.
292 class SymbolSlab {
293 public:
294 using const_iterator = std::vector<Symbol>::const_iterator;
295 using iterator = const_iterator;
296 using value_type = Symbol;
297
298 SymbolSlab() = default;
299
300 const_iterator begin() const { return Symbols.begin(); }
301 const_iterator end() const { return Symbols.end(); }
302 const_iterator find(const SymbolID &SymID) const;
303
304 size_t size() const { return Symbols.size(); }
305 bool empty() const { return Symbols.empty(); }
306 // Estimates the total memory usage.
307 size_t bytes() const {
308 return sizeof(*this) + Arena.getTotalMemory() +
309 Symbols.capacity() * sizeof(Symbol);
310 }
311
312 // SymbolSlab::Builder is a mutable container that can 'freeze' to SymbolSlab.
313 // The frozen SymbolSlab will use less memory.
314 class Builder {
315 public:
316 Builder() : UniqueStrings(Arena) {}
317
318 // Adds a symbol, overwriting any existing one with the same ID.
319 // This is a deep copy: underlying strings will be owned by the slab.
320 void insert(const Symbol &S);
321
322 // Returns the symbol with an ID, if it exists. Valid until next insert().
323 const Symbol *find(const SymbolID &ID) {
324 auto I = SymbolIndex.find(ID);
325 return I == SymbolIndex.end() ? nullptr : &Symbols[I->second];
326 }
327
328 // Consumes the builder to finalize the slab.
329 SymbolSlab build() &&;
330
331 private:
332 llvm::BumpPtrAllocator Arena;
333 // Intern table for strings. Contents are on the arena.
334 llvm::UniqueStringSaver UniqueStrings;
335 std::vector<Symbol> Symbols;
336 // Values are indices into Symbols vector.
337 llvm::DenseMap<SymbolID, size_t> SymbolIndex;
338 };
339
340 private:
341 SymbolSlab(llvm::BumpPtrAllocator Arena, std::vector<Symbol> Symbols)
342 : Arena(std::move(Arena)), Symbols(std::move(Symbols)) {}
343
344 llvm::BumpPtrAllocator Arena; // Owns Symbol data that the Symbols do not.
345 std::vector<Symbol> Symbols; // Sorted by SymbolID to allow lookup.
346 };
347
348 // Describes the kind of a cross-reference.
349 //
350 // This is a bitfield which can be combined from different kinds.
351 enum class RefKind : uint8_t {
352 Unknown = 0,
353 Declaration = static_cast<uint8_t>(index::SymbolRole::Declaration),
354 Definition = static_cast<uint8_t>(index::SymbolRole::Definition),
355 Reference = static_cast<uint8_t>(index::SymbolRole::Reference),
356 All = Declaration | Definition | Reference,
357 };
358 inline RefKind operator|(RefKind L, RefKind R) {
359 return static_cast<RefKind>(static_cast<uint8_t>(L) |
360 static_cast<uint8_t>(R));
361 }
362 inline RefKind &operator|=(RefKind &L, RefKind R) { return L = L | R; }
363 inline RefKind operator&(RefKind A, RefKind B) {
364 return static_cast<RefKind>(static_cast<uint8_t>(A) &
365 static_cast<uint8_t>(B));
366 }
367 llvm::raw_ostream &operator<<(llvm::raw_ostream &, RefKind);
368
369 // Represents a symbol occurrence in the source file.
370 // Despite the name, it could be a declaration/definition/reference.
371 //
372 // WARNING: Location does not own the underlying data - Copies are shallow.
373 struct Ref {
374 // The source location where the symbol is named.
375 SymbolLocation Location;
376 RefKind Kind = RefKind::Unknown;
377 };
378 inline bool operator<(const Ref &L, const Ref &R) {
379 return std::tie(L.Location, L.Kind) < std::tie(R.Location, R.Kind);
380 }
381 inline bool operator==(const Ref &L, const Ref &R) {
382 return std::tie(L.Location, L.Kind) == std::tie(R.Location, R.Kind);
383 }
384 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Ref &);
385
386 // An efficient structure of storing large set of symbol references in memory.
387 // Filenames are deduplicated.
388 class RefSlab {
389 public:
390 using value_type = std::pair<SymbolID, llvm::ArrayRef<Ref>>;
391 using const_iterator = std::vector<value_type>::const_iterator;
392 using iterator = const_iterator;
393
394 RefSlab() = default;
395 RefSlab(RefSlab &&Slab) = default;
396 RefSlab &operator=(RefSlab &&RHS) = default;
397
398 const_iterator begin() const { return Refs.begin(); }
399 const_iterator end() const { return Refs.end(); }
400 /// Gets the number of symbols.
401 size_t size() const { return Refs.size(); }
402 size_t numRefs() const { return NumRefs; }
403 bool empty() const { return Refs.empty(); }
404
405 size_t bytes() const {
406 return sizeof(*this) + Arena.getTotalMemory() +
407 sizeof(value_type) * Refs.size();
408 }
409
410 // RefSlab::Builder is a mutable container that can 'freeze' to RefSlab.
411 class Builder {
412 public:
413 Builder() : UniqueStrings(Arena) {}
414 // Adds a ref to the slab. Deep copy: Strings will be owned by the slab.
415 void insert(const SymbolID &ID, const Ref &S);
416 // Consumes the builder to finalize the slab.
417 RefSlab build() &&;
418
419 private:
420 llvm::BumpPtrAllocator Arena;
421 llvm::UniqueStringSaver UniqueStrings; // Contents on the arena.
422 llvm::DenseMap<SymbolID, std::vector<Ref>> Refs;
423 };
424
425 private:
426 RefSlab(std::vector<value_type> Refs, llvm::BumpPtrAllocator Arena,
427 size_t NumRefs)
428 : Arena(std::move(Arena)), Refs(std::move(Refs)), NumRefs(NumRefs) {}
429
430 llvm::BumpPtrAllocator Arena;
431 std::vector<value_type> Refs;
432 // Number of all references.
433 size_t NumRefs = 0;
434 };
435
436 struct FuzzyFindRequest {
437 /// \brief A query string for the fuzzy find. This is matched against symbols'
438 /// un-qualified identifiers and should not contain qualifiers like "::".
439 std::string Query;
440 /// \brief If this is non-empty, symbols must be in at least one of the scopes
441 /// (e.g. namespaces) excluding nested scopes. For example, if a scope "xyz::"
442 /// is provided, the matched symbols must be defined in namespace xyz but not
443 /// namespace xyz::abc.
444 ///
445 /// The global scope is "", a top level scope is "foo::", etc.
446 std::vector<std::string> Scopes;
447 /// If set to true, allow symbols from any scope. Scopes explicitly listed
448 /// above will be ranked higher.
449 bool AnyScope = false;
450 /// \brief The number of top candidates to return. The index may choose to
451 /// return more than this, e.g. if it doesn't know which candidates are best.
452 llvm::Optional<uint32_t> Limit;
453 /// If set to true, only symbols for completion support will be considered.
454 bool RestrictForCodeCompletion = false;
455 /// Contextually relevant files (e.g. the file we're code-completing in).
456 /// Paths should be absolute.
457 std::vector<std::string> ProximityPaths;
458
459 // FIXME(ibiryukov): add expected type to the request.
460
461 bool operator==(const FuzzyFindRequest &Req) const {
462 return std::tie(Query, Scopes, Limit, RestrictForCodeCompletion,
463 ProximityPaths) ==
464 std::tie(Req.Query, Req.Scopes, Req.Limit,
465 Req.RestrictForCodeCompletion, Req.ProximityPaths);
466 }
467 bool operator!=(const FuzzyFindRequest &Req) const { return !(*this == Req); }
468 };
469 bool fromJSON(const llvm::json::Value &Value, FuzzyFindRequest &Request);
470 llvm::json::Value toJSON(const FuzzyFindRequest &Request);
471
472 struct LookupRequest {
473 llvm::DenseSet<SymbolID> IDs;
474 };
475
476 struct RefsRequest {
477 llvm::DenseSet<SymbolID> IDs;
478 RefKind Filter = RefKind::All;
479 /// If set, limit the number of refers returned from the index. The index may
480 /// choose to return less than this, e.g. it tries to avoid returning stale
481 /// results.
482 llvm::Optional<uint32_t> Limit;
483 };
484
485 /// Interface for symbol indexes that can be used for searching or
486 /// matching symbols among a set of symbols based on names or unique IDs.
487 class SymbolIndex {
488 public:
489 virtual ~SymbolIndex() = default;
490
491 /// \brief Matches symbols in the index fuzzily and applies \p Callback on
492 /// each matched symbol before returning.
493 /// If returned Symbols are used outside Callback, they must be deep-copied!
494 ///
495 /// Returns true if there may be more results (limited by Req.Limit).
496 virtual bool
497 fuzzyFind(const FuzzyFindRequest &Req,
498 llvm::function_ref<void(const Symbol &)> Callback) const = 0;
499
500 /// Looks up symbols with any of the given symbol IDs and applies \p Callback
501 /// on each matched symbol.
502 /// The returned symbol must be deep-copied if it's used outside Callback.
503 virtual void
504 lookup(const LookupRequest &Req,
505 llvm::function_ref<void(const Symbol &)> Callback) const = 0;
506
507 /// Finds all occurrences (e.g. references, declarations, definitions) of a
508 /// symbol and applies \p Callback on each result.
509 ///
510 /// Results should be returned in arbitrary order.
511 /// The returned result must be deep-copied if it's used outside Callback.
512 virtual void refs(const RefsRequest &Req,
513 llvm::function_ref<void(const Ref &)> Callback) const = 0;
514
515 /// Returns estimated size of index (in bytes).
516 // FIXME(kbobyrev): Currently, this only returns the size of index itself
517 // excluding the size of actual symbol slab index refers to. We should include
518 // both.
519 virtual size_t estimateMemoryUsage() const = 0;
520 };
521
522 // Delegating implementation of SymbolIndex whose delegate can be swapped out.
523 class SwapIndex : public SymbolIndex {
524 public:
525 // If an index is not provided, reset() must be called.
526 SwapIndex(std::unique_ptr<SymbolIndex> Index = nullptr)
527 : Index(std::move(Index)) {}
528 void reset(std::unique_ptr<SymbolIndex>);
529
530 // SymbolIndex methods delegate to the current index, which is kept alive
531 // until the call returns (even if reset() is called).
532 bool fuzzyFind(const FuzzyFindRequest &,
533 llvm::function_ref<void(const Symbol &)>) const override;
534 void lookup(const LookupRequest &,
535 llvm::function_ref<void(const Symbol &)>) const override;
536 void refs(const RefsRequest &,
537 llvm::function_ref<void(const Ref &)>) const override;
538 size_t estimateMemoryUsage() const override;
539
540 private:
541 std::shared_ptr<SymbolIndex> snapshot() const;
542 mutable std::mutex Mutex;
543 std::shared_ptr<SymbolIndex> Index;
544 };
545
546 } // namespace clangd
547 } // namespace clang
548
549 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_H
clang::clangd::RefKind::Unknown
clang::clangd::SymbolSlab::bytes
size_t bytes() const
Definition: Index.h:307
clang::clangd::SymbolSlab
Definition: Index.h:292
clang::clangd::RefsRequest::IDs
llvm::DenseSet< SymbolID > IDs
Definition: Index.h:477
clang::clangd::toJSON
llvm::json::Value toJSON(const FuzzyFindRequest &Request)
Definition: Index.cpp:189
llvm
Some operations such as code completion produce a set of candidates.
Definition: YAMLGenerator.cpp:28
clang::clangd::SwapIndex::SwapIndex
SwapIndex(std::unique_ptr< SymbolIndex > Index=nullptr)
Definition: Index.h:526
clang::clangd::SymbolLocation::Position::setColumn
void setColumn(uint32_t Column)
Definition: Index.cpp:29
clang::clangd::SymbolSlab::Builder::find
const Symbol * find(const SymbolID &ID)
Definition: Index.h:323
clang::clangd::FuzzyFindRequest::RestrictForCodeCompletion
bool RestrictForCodeCompletion
If set to true, only symbols for completion support will be considered.
Definition: Index.h:454
clang::clangd::SymbolLocation
Definition: Index.h:34
clang::clangd::SymbolLocation::Position::column
uint32_t column() const
Definition: Index.h:45
clang::clangd::RefSlab
Definition: Index.h:388
clang::clangd::RefKind::Declaration
clang::clangd::SymbolLocation::Position::setLine
void setLine(uint32_t Line)
Definition: Index.cpp:22
clang::clangd::SymbolSlab::const_iterator
std::vector< Symbol >::const_iterator const_iterator
Definition: Index.h:294
clang::clangd::SymbolIndex
Interface for symbol indexes that can be used for searching or matching symbols among a set of symbol...
Definition: Index.h:487
clang::clangd::operator==
bool operator==(const SymbolLocation::Position &L, const SymbolLocation::Position &R)
Definition: Index.h:74
clang::clangd::LookupRequest::IDs
llvm::DenseSet< SymbolID > IDs
Definition: Index.h:473
clang::clangd::operator|
SymbolOrigin operator|(SymbolOrigin A, SymbolOrigin B)
Definition: Index.h:134
clang::clangd::Ref
Definition: Index.h:373
clang::clangd::DuplicateHandling::Merge
clang::clangd::RefsRequest
Definition: Index.h:476
clang::clangd::RefKind::All
llvm::DenseMapInfo< clang::clangd::SymbolID >::getEmptyKey
static clang::clangd::SymbolID getEmptyKey()
Definition: Index.h:103
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:29
clang::clangd::Symbol::Scope
llvm::StringRef Scope
Definition: Index.h:168
clang::clangd::RefSlab::numRefs
size_t numRefs() const
Definition: Index.h:402
clang::clangd::FuzzyFindRequest
Definition: Index.h:436
clang::clangd::Symbol::SymbolFlag
SymbolFlag
Definition: Index.h:233
clang::clangd::FuzzyFindRequest::operator==
bool operator==(const FuzzyFindRequest &Req) const
Definition: Index.h:461
clang::clangd::TextDocumentSyncKind::None
Documents should not be synced at all.
clang::clangd::RefSlab::Builder::Builder
Builder()
Definition: Index.h:413
clang::clangd::SymbolSlab::Builder::Builder
Builder()
Definition: Index.h:316
clang::clangd::SymbolSlab::Builder
Definition: Index.h:314
clang::clangd::Symbol::IncludeHeaderWithReferences
Definition: Index.h:207
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:446
clang::clangd::operator<
bool operator<(const SymbolLocation::Position &L, const SymbolLocation::Position &R)
Definition: Index.h:79
clang::clangd::Symbol::ID
SymbolID ID
Definition: Index.h:162
clang::clangd::Symbol::SymInfo
index::SymbolInfo SymInfo
Definition: Index.h:164
clang::clangd::Symbol::IncludeHeaderWithReferences::IncludeHeaderWithReferences
IncludeHeaderWithReferences(llvm::StringRef IncludeHeader, unsigned References)
Definition: Index.h:210
Kind
BindArgumentKind Kind
Definition: AvoidBindCheck.cpp:41
clang::clangd::operator &
SymbolOrigin operator &(SymbolOrigin A, SymbolOrigin B)
Definition: Index.h:141
clang::clangd::RefSlab::begin
const_iterator begin() const
Definition: Index.h:398
clang::clangd::RefSlab::iterator
const_iterator iterator
Definition: Index.h:392
Arena
llvm::BumpPtrAllocator Arena
Definition: Serialization.cpp:189
clang::clangd::Symbol::Definition
SymbolLocation Definition
Definition: Index.h:171
clang::clangd::SymbolOrigin::AST
SymbolInfo
clang::find_all_symbols::SymbolInfo SymbolInfo
Definition: FindAllSymbolsMain.cpp:39
clang::clangd::SymbolSlab::empty
bool empty() const
Definition: Index.h:305
clang::clangd::Symbol::IncludeHeaders
llvm::SmallVector< IncludeHeaderWithReferences, 1 > IncludeHeaders
One Symbol can potentially be incuded via different headers.
Definition: Index.h:231
clang::clangd::Symbol::Signature
llvm::StringRef Signature
A brief description of the symbol that can be appended in the completion candidate list...
Definition: Index.h:189
clang::clangd::SymbolLocation::Position
Definition: Index.h:40
clang::clangd::SymbolLocation::Position::MaxColumn
static constexpr uint32_t MaxColumn
Definition: Index.h:52
clang::clangd::Ref::Location
SymbolLocation Location
Definition: Index.h:375
clang::clangd::SymbolLocation::Position::Position
Position()
Definition: Index.h:41
clang::clangd::SymbolSlab::iterator
const_iterator iterator
Definition: Index.h:295
clang::clangd::Symbol::Documentation
llvm::StringRef Documentation
Documentation including comment for the symbol declaration.
Definition: Index.h:196
clang::clangd::FuzzyFindRequest::Query
std::string Query
A query string for the fuzzy find.
Definition: Index.h:439
clang::clangd::SymbolOrigin::Static
clang::clangd::RefKind::Definition
clang::clangd::RefSlab::size
size_t size() const
Gets the number of symbols.
Definition: Index.h:401
clang::clangd::Symbol::CanonicalDeclaration
SymbolLocation CanonicalDeclaration
Definition: Index.h:180
clang::clangd::RefKind
RefKind
Definition: Index.h:351
clang::clangd::FuzzyFindRequest::operator!=
bool operator!=(const FuzzyFindRequest &Req) const
Definition: Index.h:467
ExpectedTypes.h
clang::clangd::RefSlab::Builder
Definition: Index.h:411
clang::clangd::fromJSON
bool fromJSON(const llvm::json::Value &Parameters, FuzzyFindRequest &Request)
Definition: Index.cpp:176
clang::clangd::SymbolLocation::End
Position End
Definition: Index.h:62
clang::clangd::SwapIndex
Definition: Index.h:523
llvm::DenseMapInfo< clang::clangd::SymbolID >::isEqual
static bool isEqual(const clang::clangd::SymbolID &LHS, const clang::clangd::SymbolID &RHS)
Definition: Index.h:114
clang::clangd::RefKind::Reference
clang::clangd::Symbol
Definition: Index.h:160
clang::clangd::RefSlab::empty
bool empty() const
Definition: Index.h:403
clang::clangd::SymbolLocation::Position::MaxLine
static constexpr uint32_t MaxLine
Definition: Index.h:51
clang::clangd::SymbolLocation::Start
Position Start
The symbol range, using half-open range [Start, End).
Definition: Index.h:61
clang::clangd::LookupRequest
Definition: Index.h:472
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ChangeNamespace.cpp:18
clang::clangd::FuzzyFindRequest::ProximityPaths
std::vector< std::string > ProximityPaths
Contextually relevant files (e.g.
Definition: Index.h:457
clang::clangd::Symbol::Name
llvm::StringRef Name
Definition: Index.h:166
clang::clangd::SymbolSlab::begin
const_iterator begin() const
Definition: Index.h:300
clang::clangd::RefsRequest::Limit
llvm::Optional< uint32_t > Limit
If set, limit the number of refers returned from the index.
Definition: Index.h:482
clang::clangd::operator|=
SymbolOrigin & operator|=(SymbolOrigin &A, SymbolOrigin B)
Definition: Index.h:138
llvm::DenseMapInfo< clang::clangd::SymbolID >::getTombstoneKey
static clang::clangd::SymbolID getTombstoneKey()
Definition: Index.h:107
clang::clangd::SymbolOrigin::Unknown
clang::clangd::FuzzyFindRequest::Limit
llvm::Optional< uint32_t > Limit
The number of top candidates to return.
Definition: Index.h:452
llvm::DenseMapInfo< clang::clangd::SymbolID >::getHashValue
static unsigned getHashValue(const clang::clangd::SymbolID &Sym)
Definition: Index.h:111
clang::clangd::SymbolLocation::Position::line
uint32_t line() const
Definition: Index.h:43
clang::clangd::hash_value
llvm::hash_code hash_value(const SymbolID &ID)
Definition: SymbolID.cpp:51
clang::clangd::Symbol::CompletionSnippetSuffix
llvm::StringRef CompletionSnippetSuffix
What to insert when completing this symbol, after the symbol name.
Definition: Index.h:194
clang::clangd::RefSlab::bytes
size_t bytes() const
Definition: Index.h:405
clang::clangd::SymbolOrigin::Dynamic
clang::clangd::SymbolSlab::end
const_iterator end() const
Definition: Index.h:301
clang::clangd::operator<<
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const CodeCompletion &C)
Definition: CodeComplete.cpp:1719
clang::clangd::Symbol::Type
llvm::StringRef Type
Raw representation of the OpaqueType of the symbol, used for scoring purposes.
Definition: Index.h:205
clang::clangd::CompletionItemKind::Value
clang::clangd::SymbolOrigin
SymbolOrigin
Definition: Index.h:126
clang::clangd::SymbolSlab::size
size_t size() const
Definition: Index.h:304
clang::clangd::SymbolLocation::FileURI
const char * FileURI
Definition: Index.h:72
clang::clangd::Symbol::ReturnType
llvm::StringRef ReturnType
Type when this symbol is used in an expression.
Definition: Index.h:200
clang::doc::SymbolID
std::array< uint8_t, 20 > SymbolID
Definition: Representation.h:31
clang::clangd::SymbolLocation::Position::hasOverflow
bool hasOverflow() const
Definition: Index.h:47
clang::clangd::RefSlab::end
const_iterator end() const
Definition: Index.h:399
clang::clangd::RefSlab::const_iterator
std::vector< value_type >::const_iterator const_iterator
Definition: Index.h:391
clang::clangd::RefSlab::value_type
std::pair< SymbolID, llvm::ArrayRef< Ref > > value_type
Definition: Index.h:390
clang::clangd::Ref::Kind
RefKind Kind
Definition: Index.h:376
SymbolID.h
clang::clangd::visitStrings
void visitStrings(Symbol &S, const Callback &CB)
Definition: Index.h:263
clang::clangd::quality
float quality(const Symbol &S)
Definition: Index.cpp:69
Index
const SymbolIndex * Index
Definition: Dexp.cpp:85
clang::clangd::SymbolID
Definition: SymbolID.h:31