2021-07-15 19:28:30 +00:00
|
|
|
//! rust-analyzer is lazy and doesn't compute anything unless asked. This
|
2020-03-05 11:42:04 +00:00
|
|
|
//! sometimes is counter productive when, for example, the first goto definition
|
2021-07-15 19:28:30 +00:00
|
|
|
//! request takes longer to compute. This modules implemented prepopulation of
|
2020-03-05 11:42:04 +00:00
|
|
|
//! various caches, it's not really advanced at the moment.
|
|
|
|
|
2020-10-06 15:58:03 +00:00
|
|
|
use hir::db::DefDatabase;
|
2020-10-24 08:39:57 +00:00
|
|
|
use ide_db::base_db::SourceDatabase;
|
2020-03-05 11:42:04 +00:00
|
|
|
|
2020-10-06 15:58:03 +00:00
|
|
|
use crate::RootDatabase;
|
|
|
|
|
2021-08-30 16:18:48 +00:00
|
|
|
/// We started indexing a crate.
|
2020-10-06 15:58:03 +00:00
|
|
|
#[derive(Debug)]
|
2021-08-30 16:18:48 +00:00
|
|
|
pub struct PrimeCachesProgress {
|
|
|
|
pub on_crate: String,
|
|
|
|
pub n_done: usize,
|
|
|
|
pub n_total: usize,
|
2020-10-06 15:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
// 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.
|
2021-06-10 22:27:20 +00:00
|
|
|
for (i, &crate_id) in topo.iter().enumerate() {
|
|
|
|
let crate_name = graph[crate_id].display_name.as_deref().unwrap_or_default().to_string();
|
2020-10-06 15:58:03 +00:00
|
|
|
|
2021-08-30 16:18:48 +00:00
|
|
|
cb(PrimeCachesProgress { on_crate: crate_name, n_done: i, n_total: topo.len() });
|
2021-06-10 22:27:20 +00:00
|
|
|
db.crate_def_map(crate_id);
|
|
|
|
db.import_map(crate_id);
|
2020-03-05 11:42:04 +00:00
|
|
|
}
|
|
|
|
}
|