59
60
/// This manages symbols from files and an in-memory index on all symbols.
60
class FileIndex : public SwapIndex {
61
/// FIXME: Expose an interface to remove files that are closed.
62
64
/// If URISchemes is empty, the default schemes in SymbolCollector will be
64
66
FileIndex(std::vector<std::string> URISchemes = {});
66
/// Update symbols in \p Path with symbols in \p AST. If \p AST is
67
/// nullptr, this removes all symbols in the file.
68
/// If \p AST is not null, \p PP cannot be null and it should be the
69
/// preprocessor that was used to build \p AST.
70
/// If \p TopLevelDecls is set, only these decls are indexed. Otherwise, all
71
/// top level decls obtained from \p AST are indexed.
73
update(PathRef Path, ASTContext *AST, std::shared_ptr<Preprocessor> PP,
74
llvm::Optional<llvm::ArrayRef<Decl *>> TopLevelDecls = llvm::None);
68
// Presents a merged view of the supplied main-file and preamble ASTs.
69
const SymbolIndex &index() const { return *MergedIndex; }
71
/// Update preamble symbols of file \p Path with all declarations in \p AST
72
/// and macros in \p PP.
73
void updatePreamble(PathRef Path, ASTContext &AST,
74
std::shared_ptr<Preprocessor> PP);
76
/// Update symbols from main file \p Path with symbols in \p TopLevelDecls.
77
void updateMain(PathRef Path, ParsedAST &AST,
78
llvm::ArrayRef<Decl *> TopLevelDecls);
77
// Only update() should swap the index.
78
using SwapIndex::reset;
81
81
std::vector<std::string> URISchemes;
83
// Contains information from each file's preamble only.
84
// These are large, but update fairly infrequently (preambles are stable).
85
// Missing information:
86
// - symbol refs (these are always "from the main file")
87
// - definition locations in the main file
89
// FIXME: Because the preambles for different TUs have large overlap and
90
// FileIndex doesn't deduplicate, this uses lots of extra RAM.
91
// The biggest obstacle in fixing this: the obvious approach of partitioning
92
// by declaring file (rather than main file) fails if headers provide
93
// different symbols based on preprocessor state.
94
FileSymbols PreambleSymbols;
95
SwapIndex PreambleIndex;
97
// Contains information from each file's main AST.
98
// These are updated frequently (on file change), but are relatively small.
100
// - refs to symbols declared in the preamble and referenced from main
101
// - symbols declared both in the main file and the preamble
102
// (Note that symbols *only* in the main file are not indexed).
103
FileSymbols MainFileSymbols;
104
SwapIndex MainFileIndex;
106
std::unique_ptr<SymbolIndex> MergedIndex; // Merge preamble and main index.
84
/// Retrieves symbols and refs in \p AST.
109
/// Retrieves symbols and refs of \p Decls in \p AST.
85
110
/// Exposed to assist in unit tests.
86
111
/// If URISchemes is empty, the default schemes in SymbolCollector will be used.
87
/// If \p TopLevelDecls is set, only these decls are indexed. Otherwise, all top
88
/// level decls obtained from \p AST are indexed.
89
112
std::pair<SymbolSlab, RefSlab>
90
indexAST(ASTContext &AST, std::shared_ptr<Preprocessor> PP,
91
llvm::Optional<llvm::ArrayRef<Decl *>> TopLevelDecls = llvm::None,
92
llvm::ArrayRef<std::string> URISchemes = {});
113
indexMainDecls(ParsedAST &AST, llvm::ArrayRef<Decl *> Decls,
114
llvm::ArrayRef<std::string> URISchemes = {});
116
/// Idex declarations from \p AST and macros from \p PP that are declared in
117
/// included headers.
118
/// If URISchemes is empty, the default schemes in SymbolCollector will be used.
119
SymbolSlab indexHeaderSymbols(ASTContext &AST, std::shared_ptr<Preprocessor> PP,
120
llvm::ArrayRef<std::string> URISchemes = {});
94
122
} // namespace clangd
95
123
} // namespace clang