Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-db/src/symbol_index.rs')
-rw-r--r--crates/ide-db/src/symbol_index.rs45
1 files changed, 24 insertions, 21 deletions
diff --git a/crates/ide-db/src/symbol_index.rs b/crates/ide-db/src/symbol_index.rs
index c15cade84a..c5ea9bcf5f 100644
--- a/crates/ide-db/src/symbol_index.rs
+++ b/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.
+ hir::attach_db(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.
+ hir::attach_db(db, || Arc::new(SymbolIndex::new(SymbolCollector::new_module(db, module))))
}
pub fn crate_symbols(db: &dyn SymbolsDatabase, krate: Crate) -> Box<[Arc<SymbolIndex>]> {
@@ -252,10 +256,10 @@ impl SymbolIndex {
let mut last_batch_start = 0;
for idx in 0..symbols.len() {
- if let Some(next_symbol) = symbols.get(idx + 1) {
- if cmp(&symbols[last_batch_start], next_symbol) == Ordering::Equal {
- continue;
- }
+ if let Some(next_symbol) = symbols.get(idx + 1)
+ && cmp(&symbols[last_batch_start], next_symbol) == Ordering::Equal
+ {
+ continue;
}
let start = last_batch_start;
@@ -357,7 +361,6 @@ impl Query {
hir::ModuleDef::Adt(..)
| hir::ModuleDef::TypeAlias(..)
| hir::ModuleDef::BuiltinType(..)
- | hir::ModuleDef::TraitAlias(..)
| hir::ModuleDef::Trait(..)
);
if non_type_for_type_only_query || !self.matches_assoc_mode(symbol.is_assoc) {
@@ -371,10 +374,10 @@ impl Query {
if self.exclude_imports && symbol.is_import {
continue;
}
- if self.mode.check(&self.query, self.case_sensitive, symbol_name) {
- if let Some(b) = cb(symbol).break_value() {
- return Some(b);
- }
+ if self.mode.check(&self.query, self.case_sensitive, symbol_name)
+ && let Some(b) = cb(symbol).break_value()
+ {
+ return Some(b);
}
}
}