clang-tools 19.0.0git
Public Member Functions | Static Public Member Functions | List of all members
clang::clangd::MemIndex Class Reference

MemIndex is a naive in-memory index suitable for a small set of symbols. More...

#include <MemIndex.h>

Inheritance diagram for clang::clangd::MemIndex:
Inheritance graph
[legend]

Public Member Functions

 MemIndex ()=default
 
template<typename SymbolRange , typename RefRange , typename RelationRange >
 MemIndex (SymbolRange &&Symbols, RefRange &&Refs, RelationRange &&Relations)
 
template<typename SymbolRange , typename RefRange , typename RelationRange , typename Payload >
 MemIndex (SymbolRange &&Symbols, RefRange &&Refs, RelationRange &&Relations, Payload &&BackingData, size_t BackingDataSize)
 
template<typename SymbolRange , typename RefRange , typename RelationRange , typename FileRange , typename Payload >
 MemIndex (SymbolRange &&Symbols, RefRange &&Refs, RelationRange &&Relations, FileRange &&Files, IndexContents IdxContents, Payload &&BackingData, size_t BackingDataSize)
 
bool fuzzyFind (const FuzzyFindRequest &Req, llvm::function_ref< void(const Symbol &)> Callback) const override
 Matches symbols in the index fuzzily and applies Callback on each matched symbol before returning.
 
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.
 
bool refs (const RefsRequest &Req, llvm::function_ref< void(const Ref &)> Callback) const override
 Finds all occurrences (e.g.
 
void relations (const RelationsRequest &Req, llvm::function_ref< void(const SymbolID &, const Symbol &)> Callback) const override
 
llvm::unique_function< IndexContents(llvm::StringRef) const > indexedFiles () const override
 
size_t estimateMemoryUsage () const override
 Returns estimated size of index (in bytes).
 
- Public Member Functions inherited from clang::clangd::SymbolIndex
virtual ~SymbolIndex ()=default
 
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 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.
 
virtual bool refs (const RefsRequest &Req, llvm::function_ref< void(const Ref &)> Callback) const =0
 Finds all occurrences (e.g.
 
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.Predicate, and invokes Callback for (S, O) in each.
 
virtual IndexedFiles indexedFiles () const =0
 
virtual size_t estimateMemoryUsage () const =0
 Returns estimated size of index (in bytes).
 

Static Public Member Functions

static std::unique_ptr< SymbolIndexbuild (SymbolSlab Symbols, RefSlab Refs, RelationSlab Relations)
 Builds an index from slabs. The index takes ownership of the data.
 

Additional Inherited Members

- Public Types inherited from clang::clangd::SymbolIndex
using IndexedFiles = llvm::unique_function< IndexContents(llvm::StringRef) const >
 Returns function which checks if the specified file was used to build this index or not.
 

Detailed Description

MemIndex is a naive in-memory index suitable for a small set of symbols.

Definition at line 20 of file MemIndex.h.

Constructor & Destructor Documentation

◆ MemIndex() [1/4]

clang::clangd::MemIndex::MemIndex ( )
default

◆ MemIndex() [2/4]

template<typename SymbolRange , typename RefRange , typename RelationRange >
clang::clangd::MemIndex::MemIndex ( SymbolRange &&  Symbols,
RefRange &&  Refs,
RelationRange &&  Relations 
)
inline

Definition at line 25 of file MemIndex.h.

References clang::clangd::Symbols.

◆ MemIndex() [3/4]

template<typename SymbolRange , typename RefRange , typename RelationRange , typename Payload >
clang::clangd::MemIndex::MemIndex ( SymbolRange &&  Symbols,
RefRange &&  Refs,
RelationRange &&  Relations,
Payload &&  BackingData,
size_t  BackingDataSize 
)
inline

Definition at line 38 of file MemIndex.h.

◆ MemIndex() [4/4]

template<typename SymbolRange , typename RefRange , typename RelationRange , typename FileRange , typename Payload >
clang::clangd::MemIndex::MemIndex ( SymbolRange &&  Symbols,
RefRange &&  Refs,
RelationRange &&  Relations,
FileRange &&  Files,
IndexContents  IdxContents,
Payload &&  BackingData,
size_t  BackingDataSize 
)
inline

Definition at line 50 of file MemIndex.h.

Member Function Documentation

◆ build()

std::unique_ptr< SymbolIndex > clang::clangd::MemIndex::build ( SymbolSlab  Symbols,
RefSlab  Refs,
RelationSlab  Relations 
)
static

Builds an index from slabs. The index takes ownership of the data.

Definition at line 17 of file MemIndex.cpp.

References clang::clangd::SymbolSlab::bytes().

Referenced by clang::clangd::createIndex(), and clang::clangd::loadIndex().

◆ estimateMemoryUsage()

size_t clang::clangd::MemIndex::estimateMemoryUsage ( ) const
overridevirtual

Returns estimated size of index (in bytes).

Implements clang::clangd::SymbolIndex.

Definition at line 115 of file MemIndex.cpp.

◆ fuzzyFind()

bool clang::clangd::MemIndex::fuzzyFind ( const FuzzyFindRequest Req,
llvm::function_ref< void(const Symbol &)>  Callback 
) const
overridevirtual

Matches symbols in the index fuzzily and applies Callback on each matched symbol before returning.

If returned Symbols are used outside Callback, they must be deep-copied!

Returns true if there may be more results (limited by Req.Limit).

Implements clang::clangd::SymbolIndex.

Definition at line 26 of file MemIndex.cpp.

References clang::clangd::FuzzyFindRequest::AnyScope, clang::clangd::Symbol::Flags, clang::clangd::Symbol::IndexedForCodeCompletion, clang::clangd::FuzzyFindRequest::Limit, clang::clangd::Symbol::Name, clang::clangd::TopN< T, Compare >::push(), clang::clangd::FuzzyFindRequest::Query, clang::clangd::FuzzyFindRequest::RestrictForCodeCompletion, Results, clang::clangd::Symbol::Scope, clang::clangd::FuzzyFindRequest::Scopes, Score, and SPAN_ATTACH.

◆ indexedFiles()

llvm::unique_function< IndexContents(llvm::StringRef) const > clang::clangd::MemIndex::indexedFiles ( ) const
overridevirtual

Implements clang::clangd::SymbolIndex.

Definition at line 109 of file MemIndex.cpp.

References clang::clangd::None.

◆ lookup()

void clang::clangd::MemIndex::lookup ( const LookupRequest Req,
llvm::function_ref< void(const Symbol &)>  Callback 
) const
overridevirtual

Looks up symbols with any of the given symbol IDs and applies Callback on each matched symbol.

The returned symbol must be deep-copied if it's used outside Callback.

Implements clang::clangd::SymbolIndex.

Definition at line 58 of file MemIndex.cpp.

References ID, and clang::clangd::LookupRequest::IDs.

Referenced by relations().

◆ refs()

bool clang::clangd::MemIndex::refs ( const RefsRequest Req,
llvm::function_ref< void(const Ref &)>  Callback 
) const
overridevirtual

Finds all occurrences (e.g.

references, declarations, definitions) of symbols and applies Callback on each result.

Results should be returned in arbitrary order. The returned result must be deep-copied if it's used outside Callback. FIXME: there's no indication which result references which symbol.

Returns true if there will be more results (limited by Req.Limit);

Implements clang::clangd::SymbolIndex.

Definition at line 68 of file MemIndex.cpp.

References clang::clangd::RefsRequest::Filter, clang::clangd::RefsRequest::IDs, and clang::clangd::RefsRequest::Limit.

◆ relations()

void clang::clangd::MemIndex::relations ( const RelationsRequest Req,
llvm::function_ref< void(const SymbolID &, const Symbol &)>  Callback 
) const
override

The documentation for this class was generated from the following files: