diff --git a/crates/ide/src/prime_caches.rs b/crates/ide/src/prime_caches.rs index d912a01b84ee..36801c964b52 100644 --- a/crates/ide/src/prime_caches.rs +++ b/crates/ide/src/prime_caches.rs @@ -33,14 +33,15 @@ pub(crate) fn prime_caches(db: &RootDatabase, cb: &(dyn Fn(PrimeCachesProgress) // 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() { - let crate_name = graph[*krate].display_name.as_deref().unwrap_or_default().to_string(); + for (i, &crate_id) in topo.iter().enumerate() { + let crate_name = graph[crate_id].display_name.as_deref().unwrap_or_default().to_string(); cb(PrimeCachesProgress::StartedOnCrate { on_crate: crate_name, n_done: i, n_total: topo.len(), }); - db.crate_def_map(*krate); + db.crate_def_map(crate_id); + db.import_map(crate_id); } } diff --git a/crates/rust-analyzer/src/cli.rs b/crates/rust-analyzer/src/cli.rs index 76b666dc27c7..25ebcc0ece32 100644 --- a/crates/rust-analyzer/src/cli.rs +++ b/crates/rust-analyzer/src/cli.rs @@ -16,7 +16,6 @@ use vfs::Vfs; pub use self::{ analysis_stats::AnalysisStatsCmd, diagnostics::diagnostics, - load_cargo::{load_workspace, load_workspace_at, LoadCargoConfig}, ssr::{apply_ssr_rules, search_for_patterns}, }; diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs index 5364e907c093..843c0ca37b0e 100644 --- a/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/crates/rust-analyzer/src/cli/analysis_stats.rs @@ -70,6 +70,7 @@ impl AnalysisStatsCmd { load_out_dirs_from_check: self.enable_build_scripts, wrap_rustc: false, with_proc_macro: self.enable_proc_macros, + prefill_caches: false, }; let (host, vfs, _proc_macro) = load_workspace_at(&self.path, &cargo_config, &load_cargo_config, &|_| {})?; diff --git a/crates/rust-analyzer/src/cli/diagnostics.rs b/crates/rust-analyzer/src/cli/diagnostics.rs index c33c8179cb3d..dc9a390fe991 100644 --- a/crates/rust-analyzer/src/cli/diagnostics.rs +++ b/crates/rust-analyzer/src/cli/diagnostics.rs @@ -34,8 +34,12 @@ pub fn diagnostics( with_proc_macro: bool, ) -> Result<()> { let cargo_config = Default::default(); - let load_cargo_config = - LoadCargoConfig { load_out_dirs_from_check, with_proc_macro, wrap_rustc: false }; + let load_cargo_config = LoadCargoConfig { + load_out_dirs_from_check, + with_proc_macro, + wrap_rustc: false, + prefill_caches: false, + }; let (host, _vfs, _proc_macro) = load_workspace_at(path, &cargo_config, &load_cargo_config, &|_| {})?; let db = host.raw_database(); diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs index 8cee6547878d..19cb1c046d82 100644 --- a/crates/rust-analyzer/src/cli/load_cargo.rs +++ b/crates/rust-analyzer/src/cli/load_cargo.rs @@ -14,13 +14,14 @@ use vfs::{loader::Handle, AbsPath, AbsPathBuf}; use crate::reload::{ProjectFolders, SourceRootConfig}; -pub struct LoadCargoConfig { - pub load_out_dirs_from_check: bool, - pub wrap_rustc: bool, - pub with_proc_macro: bool, +pub(crate) struct LoadCargoConfig { + pub(crate) load_out_dirs_from_check: bool, + pub(crate) wrap_rustc: bool, + pub(crate) with_proc_macro: bool, + pub(crate) prefill_caches: bool, } -pub fn load_workspace_at( +pub(crate) fn load_workspace_at( root: &Path, cargo_config: &CargoConfig, load_config: &LoadCargoConfig, @@ -33,7 +34,7 @@ pub fn load_workspace_at( load_workspace(workspace, load_config, progress) } -pub fn load_workspace( +fn load_workspace( ws: ProjectWorkspace, config: &LoadCargoConfig, progress: &dyn Fn(String), @@ -82,6 +83,10 @@ pub fn load_workspace( log::debug!("crate graph: {:?}", crate_graph); let host = load_crate_graph(crate_graph, project_folders.source_root_config, &mut vfs, &receiver); + + if config.prefill_caches { + host.analysis().prime_caches(|_| {})?; + } Ok((host, vfs, proc_macro_client)) } @@ -144,6 +149,7 @@ mod tests { load_out_dirs_from_check: false, wrap_rustc: false, with_proc_macro: false, + prefill_caches: false, }; let (host, _vfs, _proc_macro) = load_workspace_at(path, &cargo_config, &load_cargo_config, &|_| {})?; diff --git a/crates/rust-analyzer/src/cli/ssr.rs b/crates/rust-analyzer/src/cli/ssr.rs index 1fd9b5a9b47c..0b3475e09281 100644 --- a/crates/rust-analyzer/src/cli/ssr.rs +++ b/crates/rust-analyzer/src/cli/ssr.rs @@ -13,6 +13,7 @@ pub fn apply_ssr_rules(rules: Vec) -> Result<()> { load_out_dirs_from_check: true, wrap_rustc: false, with_proc_macro: true, + prefill_caches: false, }; let (host, vfs, _proc_macro) = load_workspace_at(&std::env::current_dir()?, &cargo_config, &load_cargo_config, &|_| {})?; @@ -39,8 +40,12 @@ pub fn search_for_patterns(patterns: Vec, debug_snippet: Option