10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_H 11 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_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" 43 uint32_t
line()
const {
return Line; }
45 uint32_t
column()
const {
return Column; }
51 static constexpr uint32_t
MaxLine = (1 << 20) - 1;
52 static constexpr uint32_t
MaxColumn = (1 << 12) - 1;
64 explicit operator bool()
const {
return !StringRef(
FileURI).empty(); }
76 return std::make_tuple(L.
line(), L.
column()) ==
135 return static_cast<SymbolOrigin>(
static_cast<uint8_t
>(A) |
136 static_cast<uint8_t>(B));
142 return static_cast<SymbolOrigin>(
static_cast<uint8_t
>(A) &
143 static_cast<uint8_t>(B));
183 unsigned References = 0;
212 : IncludeHeader(IncludeHeader), References(References) {}
221 llvm::StringRef IncludeHeader =
"";
224 unsigned References = 0;
239 IndexedForCodeCompletion = 1 << 0,
243 ImplementationDetail = 1 << 2,
245 VisibleOutsideFile = 1 << 3,
253 static_cast<uint8_t>(B));
271 auto RawCharPointerCB = [&CB](
const char *&P) {
272 llvm::StringRef S(P);
274 assert(!S.data()[S.size()] &&
"Visited StringRef must be null-terminated");
281 CB(Include.IncludeHeader);
304 size_t size()
const {
return Symbols.size(); }
305 bool empty()
const {
return Symbols.empty(); }
308 return sizeof(*this) +
Arena.getTotalMemory() +
309 Symbols.capacity() *
sizeof(
Symbol);
320 void insert(
const Symbol &S);
325 return I ==
SymbolIndex.end() ? nullptr : &Symbols[I->second];
332 llvm::BumpPtrAllocator
Arena;
334 llvm::UniqueStringSaver UniqueStrings;
335 std::vector<Symbol> Symbols;
342 :
Arena(std::move(Arena)), Symbols(std::move(Symbols)) {}
344 llvm::BumpPtrAllocator
Arena;
345 std::vector<Symbol> Symbols;
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),
359 return static_cast<RefKind>(
static_cast<uint8_t
>(L) |
360 static_cast<uint8_t>(R));
364 return static_cast<RefKind>(
static_cast<uint8_t
>(A) &
365 static_cast<uint8_t>(B));
384 llvm::raw_ostream &
operator<<(llvm::raw_ostream &,
const Ref &);
401 size_t size()
const {
return Refs.size(); }
403 bool empty()
const {
return Refs.empty(); }
406 return sizeof(*this) +
Arena.getTotalMemory() +
420 llvm::BumpPtrAllocator
Arena;
421 llvm::UniqueStringSaver UniqueStrings;
422 llvm::DenseMap<SymbolID, std::vector<Ref>> Refs;
426 RefSlab(std::vector<value_type> Refs, llvm::BumpPtrAllocator
Arena,
428 :
Arena(std::move(Arena)), Refs(std::move(Refs)), NumRefs(NumRefs) {}
430 llvm::BumpPtrAllocator
Arena;
431 std::vector<value_type> Refs;
449 bool AnyScope =
false;
454 bool RestrictForCodeCompletion =
false;
462 return std::tie(Query, Scopes, Limit, RestrictForCodeCompletion,
473 llvm::DenseSet<SymbolID>
IDs;
477 llvm::DenseSet<SymbolID>
IDs;
513 llvm::function_ref<
void(
const Ref &)>
Callback)
const = 0;
519 virtual size_t estimateMemoryUsage()
const = 0;
528 void reset(std::unique_ptr<SymbolIndex>);
533 llvm::function_ref<
void(
const Symbol &)>)
const override;
535 llvm::function_ref<
void(
const Symbol &)>)
const override;
537 llvm::function_ref<
void(
const Ref &)>)
const override;
538 size_t estimateMemoryUsage()
const override;
541 std::shared_ptr<SymbolIndex> snapshot()
const;
542 mutable std::mutex Mutex;
543 std::shared_ptr<SymbolIndex>
Index;
549 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_H
llvm::DenseSet< SymbolID > IDs
llvm::json::Value toJSON(const FuzzyFindRequest &Request)
Some operations such as code completion produce a set of candidates.
SwapIndex(std::unique_ptr< SymbolIndex > Index=nullptr)
void setColumn(uint32_t Column)
const Symbol * find(const SymbolID &ID)
bool RestrictForCodeCompletion
If set to true, only symbols for completion support will be considered.
void setLine(uint32_t Line)
std::vector< Symbol >::const_iterator const_iterator
Interface for symbol indexes that can be used for searching or matching symbols among a set of symbol...
bool operator==(const SymbolLocation::Position &L, const SymbolLocation::Position &R)
llvm::DenseSet< SymbolID > IDs
SymbolOrigin operator|(SymbolOrigin A, SymbolOrigin B)
static clang::clangd::SymbolID getEmptyKey()
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
bool operator==(const FuzzyFindRequest &Req) const
Documents should not be synced at all.
std::vector< std::string > Scopes
If this is non-empty, symbols must be in at least one of the scopes (e.g.
bool operator<(const SymbolLocation::Position &L, const SymbolLocation::Position &R)
index::SymbolInfo SymInfo
SymbolOrigin operator &(SymbolOrigin A, SymbolOrigin B)
const_iterator begin() const
llvm::BumpPtrAllocator Arena
SymbolLocation Definition
clang::find_all_symbols::SymbolInfo SymbolInfo
llvm::SmallVector< IncludeHeaderWithReferences, 1 > IncludeHeaders
One Symbol can potentially be incuded via different headers.
llvm::StringRef Signature
A brief description of the symbol that can be appended in the completion candidate list...
static constexpr uint32_t MaxColumn
llvm::StringRef Documentation
Documentation including comment for the symbol declaration.
std::string Query
A query string for the fuzzy find.
size_t size() const
Gets the number of symbols.
SymbolLocation CanonicalDeclaration
bool operator!=(const FuzzyFindRequest &Req) const
bool fromJSON(const llvm::json::Value &Parameters, FuzzyFindRequest &Request)
static bool isEqual(const clang::clangd::SymbolID &LHS, const clang::clangd::SymbolID &RHS)
static constexpr uint32_t MaxLine
Position Start
The symbol range, using half-open range [Start, End).
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::vector< std::string > ProximityPaths
Contextually relevant files (e.g.
const_iterator begin() const
llvm::Optional< uint32_t > Limit
If set, limit the number of refers returned from the index.
SymbolOrigin & operator|=(SymbolOrigin &A, SymbolOrigin B)
static clang::clangd::SymbolID getTombstoneKey()
llvm::Optional< uint32_t > Limit
The number of top candidates to return.
static unsigned getHashValue(const clang::clangd::SymbolID &Sym)
llvm::hash_code hash_value(const SymbolID &ID)
llvm::StringRef CompletionSnippetSuffix
What to insert when completing this symbol, after the symbol name.
const_iterator end() const
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const CodeCompletion &C)
llvm::StringRef Type
Raw representation of the OpaqueType of the symbol, used for scoring purposes.
llvm::StringRef ReturnType
Type when this symbol is used in an expression.
std::array< uint8_t, 20 > SymbolID
const_iterator end() const
std::vector< value_type >::const_iterator const_iterator
std::pair< SymbolID, llvm::ArrayRef< Ref > > value_type
void visitStrings(Symbol &S, const Callback &CB)
float quality(const Symbol &S)
const SymbolIndex * Index