diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_batch/src/lib.rs | 10 | ||||
-rw-r--r-- | crates/ra_cli/src/analysis_stats.rs | 29 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 8 |
3 files changed, 26 insertions, 21 deletions
diff --git a/crates/ra_batch/src/lib.rs b/crates/ra_batch/src/lib.rs index 602beb439..df49eb13d 100644 --- a/crates/ra_batch/src/lib.rs +++ b/crates/ra_batch/src/lib.rs | |||
@@ -141,14 +141,8 @@ mod tests { | |||
141 | #[test] | 141 | #[test] |
142 | fn test_loading_rust_analyzer() { | 142 | fn test_loading_rust_analyzer() { |
143 | let path = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap().parent().unwrap(); | 143 | let path = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap().parent().unwrap(); |
144 | let (host, roots) = load_cargo(path).unwrap(); | 144 | let (host, _roots) = load_cargo(path).unwrap(); |
145 | let mut n_crates = 0; | 145 | let n_crates = Crate::all(host.raw_database()).len(); |
146 | for (root, _) in roots { | ||
147 | for _krate in Crate::source_root_crates(host.raw_database(), root) { | ||
148 | n_crates += 1; | ||
149 | } | ||
150 | } | ||
151 | |||
152 | // RA has quite a few crates, but the exact count doesn't matter | 146 | // RA has quite a few crates, but the exact count doesn't matter |
153 | assert!(n_crates > 20); | 147 | assert!(n_crates > 20); |
154 | } | 148 | } |
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( | |||
22 | let mut num_crates = 0; | 22 | let mut num_crates = 0; |
23 | let mut visited_modules = HashSet::new(); | 23 | let mut visited_modules = HashSet::new(); |
24 | let mut visit_queue = Vec::new(); | 24 | let mut visit_queue = Vec::new(); |
25 | for (source_root_id, project_root) in roots { | 25 | |
26 | if project_root.is_member() { | 26 | let members = roots |
27 | for krate in Crate::source_root_crates(db, source_root_id) { | 27 | .into_iter() |
28 | num_crates += 1; | 28 | .filter_map( |
29 | let module = | 29 | |(source_root_id, project_root)| { |
30 | krate.root_module(db).expect("crate in source root without root module"); | 30 | if project_root.is_member() { |
31 | visit_queue.push(module); | 31 | Some(source_root_id) |
32 | } | 32 | } else { |
33 | None | ||
34 | } | ||
35 | }, | ||
36 | ) | ||
37 | .collect::<HashSet<_>>(); | ||
38 | |||
39 | for krate in Crate::all(db) { | ||
40 | let module = krate.root_module(db).expect("crate without root module"); | ||
41 | let file_id = module.definition_source(db).file_id; | ||
42 | if members.contains(&db.file_source_root(file_id.original_file(db))) { | ||
43 | num_crates += 1; | ||
44 | visit_queue.push(module); | ||
33 | } | 45 | } |
34 | } | 46 | } |
47 | |||
35 | println!("Crates in this dir: {}", num_crates); | 48 | println!("Crates in this dir: {}", num_crates); |
36 | let mut num_decls = 0; | 49 | let mut num_decls = 0; |
37 | let mut funcs = Vec::new(); | 50 | let mut funcs = Vec::new(); |
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 8055a07db..8eb3c577d 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -5,7 +5,7 @@ pub(crate) mod docs; | |||
5 | 5 | ||
6 | use std::sync::Arc; | 6 | use std::sync::Arc; |
7 | 7 | ||
8 | use ra_db::{CrateId, Edition, FileId, SourceRootId}; | 8 | use ra_db::{CrateId, Edition, FileId}; |
9 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; | 9 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; |
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
@@ -76,10 +76,8 @@ impl Crate { | |||
76 | crate_graph.edition(self.crate_id) | 76 | crate_graph.edition(self.crate_id) |
77 | } | 77 | } |
78 | 78 | ||
79 | // FIXME: should this be in source_binder? | 79 | pub fn all(db: &impl DefDatabase) -> Vec<Crate> { |
80 | pub fn source_root_crates(db: &impl DefDatabase, source_root: SourceRootId) -> Vec<Crate> { | 80 | db.crate_graph().iter().map(|crate_id| Crate { crate_id }).collect() |
81 | let crate_ids = db.source_root_crates(source_root); | ||
82 | crate_ids.iter().map(|&crate_id| Crate { crate_id }).collect() | ||
83 | } | 81 | } |
84 | } | 82 | } |
85 | 83 | ||