From 1555a1aa0d5d45e4b317db272c07ad3e8470553d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 14 Oct 2019 15:15:47 +0300 Subject: remove one more dependency on source roots --- crates/ra_cli/src/analysis_stats.rs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'crates/ra_cli') diff --git a/crates/ra_cli/src/analysis_stats.rs b/crates/ra_cli/src/analysis_stats.rs index a8a110bd9..fe4f57dcd 100644 --- a/crates/ra_cli/src/analysis_stats.rs +++ b/crates/ra_cli/src/analysis_stats.rs @@ -22,16 +22,29 @@ pub fn run( let mut num_crates = 0; let mut visited_modules = HashSet::new(); let mut visit_queue = Vec::new(); - for (source_root_id, project_root) in roots { - if project_root.is_member() { - for krate in Crate::source_root_crates(db, source_root_id) { - num_crates += 1; - let module = - krate.root_module(db).expect("crate in source root without root module"); - visit_queue.push(module); - } + + let members = roots + .into_iter() + .filter_map( + |(source_root_id, project_root)| { + if project_root.is_member() { + Some(source_root_id) + } else { + None + } + }, + ) + .collect::>(); + + for krate in Crate::all(db) { + let module = krate.root_module(db).expect("crate without root module"); + let file_id = module.definition_source(db).file_id; + if members.contains(&db.file_source_root(file_id.original_file(db))) { + num_crates += 1; + visit_queue.push(module); } } + println!("Crates in this dir: {}", num_crates); let mut num_decls = 0; let mut funcs = Vec::new(); -- cgit v1.2.3