Skip to content

Commit 75ce5dc

Browse files
Merge pull request #20496 from ChayimFriedman2/symbols-attach
Attach the DB in symbol queries
2 parents f9e402d + 243d158 commit 75ce5dc

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

crates/ide-db/src/symbol_index.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,23 +133,27 @@ pub trait SymbolsDatabase: HirDatabase + SourceDatabase {
133133
fn library_symbols(db: &dyn SymbolsDatabase, source_root_id: SourceRootId) -> Arc<SymbolIndex> {
134134
let _p = tracing::info_span!("library_symbols").entered();
135135

136-
let mut symbol_collector = SymbolCollector::new(db);
137-
138-
db.source_root_crates(source_root_id)
139-
.iter()
140-
.flat_map(|&krate| Crate::from(krate).modules(db))
141-
// we specifically avoid calling other SymbolsDatabase queries here, even though they do the same thing,
142-
// as the index for a library is not going to really ever change, and we do not want to store each
143-
// the module or crate indices for those in salsa unless we need to.
144-
.for_each(|module| symbol_collector.collect(module));
145-
146-
Arc::new(SymbolIndex::new(symbol_collector.finish()))
136+
// We call this without attaching because this runs in parallel, so we need to attach here.
137+
salsa::attach(db, || {
138+
let mut symbol_collector = SymbolCollector::new(db);
139+
140+
db.source_root_crates(source_root_id)
141+
.iter()
142+
.flat_map(|&krate| Crate::from(krate).modules(db))
143+
// we specifically avoid calling other SymbolsDatabase queries here, even though they do the same thing,
144+
// as the index for a library is not going to really ever change, and we do not want to store each
145+
// the module or crate indices for those in salsa unless we need to.
146+
.for_each(|module| symbol_collector.collect(module));
147+
148+
Arc::new(SymbolIndex::new(symbol_collector.finish()))
149+
})
147150
}
148151

149152
fn module_symbols(db: &dyn SymbolsDatabase, module: Module) -> Arc<SymbolIndex> {
150153
let _p = tracing::info_span!("module_symbols").entered();
151154

152-
Arc::new(SymbolIndex::new(SymbolCollector::new_module(db, module)))
155+
// We call this without attaching because this runs in parallel, so we need to attach here.
156+
salsa::attach(db, || Arc::new(SymbolIndex::new(SymbolCollector::new_module(db, module))))
153157
}
154158

155159
pub fn crate_symbols(db: &dyn SymbolsDatabase, krate: Crate) -> Box<[Arc<SymbolIndex>]> {

0 commit comments

Comments
 (0)