about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChayim Refael Friedman <chayimfr@gmail.com>2025-08-21 07:14:55 +0300
committerChayim Refael Friedman <chayimfr@gmail.com>2025-08-21 07:14:55 +0300
commit4a9b73bc98417d2335b7d3d86edf301bdd7be230 (patch)
tree2dda427ebee2e1c89df06eef5dd1a06d3091877f
parentd8b4700b8bb51f2f8ce35461998b318a2cde9787 (diff)
downloadrust-4a9b73bc98417d2335b7d3d86edf301bdd7be230.tar.gz
rust-4a9b73bc98417d2335b7d3d86edf301bdd7be230.zip
Attach the DB in symbol queries
-rw-r--r--src/tools/rust-analyzer/crates/ide-db/src/symbol_index.rs28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/tools/rust-analyzer/crates/ide-db/src/symbol_index.rs b/src/tools/rust-analyzer/crates/ide-db/src/symbol_index.rs
index 78ade30c7e3..76b647f8e9f 100644
--- a/src/tools/rust-analyzer/crates/ide-db/src/symbol_index.rs
+++ b/src/tools/rust-analyzer/crates/ide-db/src/symbol_index.rs
@@ -133,23 +133,27 @@ pub trait SymbolsDatabase: HirDatabase + SourceDatabase {
 fn library_symbols(db: &dyn SymbolsDatabase, source_root_id: SourceRootId) -> Arc<SymbolIndex> {
     let _p = tracing::info_span!("library_symbols").entered();
 
-    let mut symbol_collector = SymbolCollector::new(db);
-
-    db.source_root_crates(source_root_id)
-        .iter()
-        .flat_map(|&krate| Crate::from(krate).modules(db))
-        // we specifically avoid calling other SymbolsDatabase queries here, even though 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
-        // the module or crate indices for those in salsa unless we need to.
-        .for_each(|module| symbol_collector.collect(module));
-
-    Arc::new(SymbolIndex::new(symbol_collector.finish()))
+    // We call this without attaching because this runs in parallel, so we need to attach here.
+    salsa::attach(db, || {
+        let mut symbol_collector = SymbolCollector::new(db);
+
+        db.source_root_crates(source_root_id)
+            .iter()
+            .flat_map(|&krate| Crate::from(krate).modules(db))
+            // we specifically avoid calling other SymbolsDatabase queries here, even though 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
+            // the module or crate indices for those in salsa unless we need to.
+            .for_each(|module| symbol_collector.collect(module));
+
+        Arc::new(SymbolIndex::new(symbol_collector.finish()))
+    })
 }
 
 fn module_symbols(db: &dyn SymbolsDatabase, module: Module) -> Arc<SymbolIndex> {
     let _p = tracing::info_span!("module_symbols").entered();
 
-    Arc::new(SymbolIndex::new(SymbolCollector::new_module(db, module)))
+    // We call this without attaching because this runs in parallel, so we need to attach here.
+    salsa::attach(db, || Arc::new(SymbolIndex::new(SymbolCollector::new_module(db, module))))
 }
 
 pub fn crate_symbols(db: &dyn SymbolsDatabase, krate: Crate) -> Box<[Arc<SymbolIndex>]> {