2020-03-05 05:42:04 -06:00
|
|
|
//! rust-analyzer is lazy and doesn't not compute anything unless asked. This
|
|
|
|
//! sometimes is counter productive when, for example, the first goto definition
|
|
|
|
//! request takes longer to compute. This modules implemented prepopulating of
|
|
|
|
//! various caches, it's not really advanced at the moment.
|
|
|
|
|
2020-10-06 10:58:03 -05:00
|
|
|
use hir::db::DefDatabase;
|
2020-10-24 03:39:57 -05:00
|
|
|
use ide_db::base_db::SourceDatabase;
|
2020-03-05 05:42:04 -06:00
|
|
|
|
2020-10-06 10:58:03 -05:00
|
|
|
use crate::RootDatabase;
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum PrimeCachesProgress {
|
|
|
|
Started,
|
|
|
|
/// We started indexing a crate.
|
|
|
|
StartedOnCrate {
|
|
|
|
on_crate: String,
|
|
|
|
n_done: usize,
|
|
|
|
n_total: usize,
|
|
|
|
},
|
|
|
|
/// We finished indexing all crates.
|
|
|
|
Finished,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn prime_caches(db: &RootDatabase, cb: &(dyn Fn(PrimeCachesProgress) + Sync)) {
|
|
|
|
let _p = profile::span("prime_caches");
|
|
|
|
let graph = db.crate_graph();
|
|
|
|
let topo = &graph.crates_in_topological_order();
|
|
|
|
|
|
|
|
cb(PrimeCachesProgress::Started);
|
2021-05-02 13:45:00 -05:00
|
|
|
// Take care to emit the finish signal even when the computation is canceled.
|
2021-04-20 14:54:05 -05:00
|
|
|
let _d = stdx::defer(|| cb(PrimeCachesProgress::Finished));
|
2020-10-06 10:58:03 -05:00
|
|
|
|
|
|
|
// FIXME: This would be easy to parallelize, since it's in the ideal ordering for that.
|
|
|
|
// Unfortunately rayon prevents panics from propagation out of a `scope`, which breaks
|
|
|
|
// cancellation, so we cannot use rayon.
|
|
|
|
for (i, krate) in topo.iter().enumerate() {
|
2020-10-20 08:38:11 -05:00
|
|
|
let crate_name = graph[*krate].display_name.as_deref().unwrap_or_default().to_string();
|
2020-10-06 10:58:03 -05:00
|
|
|
|
|
|
|
cb(PrimeCachesProgress::StartedOnCrate {
|
|
|
|
on_crate: crate_name,
|
|
|
|
n_done: i,
|
|
|
|
n_total: topo.len(),
|
|
|
|
});
|
|
|
|
db.crate_def_map(*krate);
|
2020-03-05 05:42:04 -06:00
|
|
|
}
|
|
|
|
}
|