Skip to content

Commit 88fad49

Browse files
committed
Auto merge of #18180 - kpreid:search, r=davidbarsky
feat: Index workspace symbols at startup rather than on the first symbol search. This will eliminate potential many-second delays when performing the first search, at the price of making cache priming (“Indexing N/M” in the VS Code status bar) take a little longer in total. Hopefully this additional time is insignificant because a typical session will involve at least one symbol search. Further improvement would be to do this as a separate parallel task (which will be beneficial if the workspace contains a small number of large crates), but that would require significant additional refactoring of the progress-reporting mechanism to understand multiple tasks per crate. Happy to tackle that in this PR if desired, but I thought I'd propose the minimal change first.
2 parents df478ea + a050c5d commit 88fad49

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

crates/ide-db/src/prime_caches.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::{
1313
salsa::{Database, ParallelDatabase, Snapshot},
1414
Cancelled, CrateId, SourceDatabase, SourceRootDatabase,
1515
},
16+
symbol_index::SymbolsDatabase,
1617
FxIndexMap, RootDatabase,
1718
};
1819

@@ -54,11 +55,13 @@ pub fn parallel_prime_caches(
5455
let (progress_sender, progress_receiver) = crossbeam_channel::unbounded();
5556
let (work_sender, work_receiver) = crossbeam_channel::unbounded();
5657
let graph = graph.clone();
58+
let local_roots = db.local_roots();
5759
let prime_caches_worker = move |db: Snapshot<RootDatabase>| {
5860
while let Ok((crate_id, crate_name)) = work_receiver.recv() {
5961
progress_sender
6062
.send(ParallelPrimeCacheWorkerProgress::BeginCrate { crate_id, crate_name })?;
6163

64+
// Compute the DefMap and possibly ImportMap
6265
let file_id = graph[crate_id].root_file_id;
6366
let root_id = db.file_source_root(file_id);
6467
if db.source_root(root_id).is_library {
@@ -68,6 +71,19 @@ pub fn parallel_prime_caches(
6871
db.import_map(crate_id);
6972
}
7073

74+
// Compute the symbol search index.
75+
// This primes the cache for `ide_db::symbol_index::world_symbols()`.
76+
//
77+
// We do this for workspace crates only (members of local_roots), because doing it
78+
// for all dependencies could be *very* unnecessarily slow in a large project.
79+
//
80+
// FIXME: We should do it unconditionally if the configuration is set to default to
81+
// searching dependencies (rust-analyzer.workspace.symbol.search.scope), but we
82+
// would need to pipe that configuration information down here.
83+
if local_roots.contains(&root_id) {
84+
db.crate_symbols(crate_id.into());
85+
}
86+
7187
progress_sender.send(ParallelPrimeCacheWorkerProgress::EndCrate { crate_id })?;
7288
}
7389

0 commit comments

Comments
 (0)