diff --git a/crates/ide_db/src/symbol_index.rs b/crates/ide_db/src/symbol_index.rs index 6f9e8bf0ed4..b1546dd4d06 100644 --- a/crates/ide_db/src/symbol_index.rs +++ b/crates/ide_db/src/symbol_index.rs @@ -94,12 +94,18 @@ impl Query { #[salsa::query_group(SymbolsDatabaseStorage)] pub trait SymbolsDatabase: HirDatabase + SourceDatabaseExt + Upcast { + /// The symbol index for a given module. These modules should only be in source roots that + /// are inside local_roots. fn module_symbols(&self, module_id: ModuleId) -> Arc; + + /// The symbol index for a given source root within library_roots. fn library_symbols(&self, source_root_id: SourceRootId) -> Arc; + /// The set of "local" (that is, from the current workspace) roots. /// Files in local roots are assumed to change frequently. #[salsa::input] fn local_roots(&self) -> Arc>; + /// The set of roots for crates.io libraries. /// Files in libraries are assumed to never change. #[salsa::input] @@ -114,6 +120,9 @@ fn library_symbols(db: &dyn SymbolsDatabase, source_root_id: SourceRootId) -> Ar .source_root_crates(source_root_id) .iter() .flat_map(|&krate| module_ids_for_crate(db.upcast(), krate)) + // we specifically avoid calling SymbolsDatabase::module_symbols here, even they do the same thing, + // as the index for a library is not going to really ever change, and we do not want to store each + // module's index in salsa. .map(|module_id| SymbolCollector::collect(db, module_id)) .flatten() .collect(); @@ -129,11 +138,23 @@ fn module_symbols(db: &dyn SymbolsDatabase, module_id: ModuleId) -> Arc(DB); +impl Snap> { + fn new(db: &DB) -> Self { + Self(db.snapshot()) + } +} impl Clone for Snap> { fn clone(&self) -> Snap> { Snap(self.0.snapshot()) } } +impl std::ops::Deref for Snap { + type Target = DB; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} // Feature: Workspace Symbol // @@ -164,12 +185,10 @@ impl Clone for Snap> { pub fn world_symbols(db: &RootDatabase, query: Query) -> Vec { let _p = profile::span("world_symbols").detail(|| query.query.clone()); - let snap = Snap(db.snapshot()); - let indices = if query.libs { db.library_roots() .par_iter() - .map_with(snap, |snap, &root| snap.0.library_symbols(root)) + .map_with(Snap::new(db), |snap, &root| snap.library_symbols(root)) .collect() } else { let mut module_ids = Vec::new(); @@ -183,7 +202,7 @@ pub fn world_symbols(db: &RootDatabase, query: Query) -> Vec { module_ids .par_iter() - .map_with(snap, |snap, &module_id| snap.0.module_symbols(module_id)) + .map_with(Snap::new(db), |snap, &module_id| snap.module_symbols(module_id)) .collect() }; @@ -194,10 +213,9 @@ pub fn crate_symbols(db: &RootDatabase, krate: CrateId, query: Query) -> Vec = module_ids .par_iter() - .map_with(snap, |snap, &module_id| snap.0.module_symbols(module_id)) + .map_with(Snap::new(db), |snap, &module_id| snap.module_symbols(module_id)) .collect(); query.search(indices)