Merge #2007
2007: remove one more dependency on source roots r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
1f4fbc0035
@ -141,14 +141,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_loading_rust_analyzer() {
|
||||
let path = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap().parent().unwrap();
|
||||
let (host, roots) = load_cargo(path).unwrap();
|
||||
let mut n_crates = 0;
|
||||
for (root, _) in roots {
|
||||
for _krate in Crate::source_root_crates(host.raw_database(), root) {
|
||||
n_crates += 1;
|
||||
}
|
||||
}
|
||||
|
||||
let (host, _roots) = load_cargo(path).unwrap();
|
||||
let n_crates = Crate::all(host.raw_database()).len();
|
||||
// RA has quite a few crates, but the exact count doesn't matter
|
||||
assert!(n_crates > 20);
|
||||
}
|
||||
|
@ -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::<HashSet<_>>();
|
||||
|
||||
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();
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use ra_db::{CrateId, Edition, FileId, SourceRootId};
|
||||
use ra_db::{CrateId, Edition, FileId};
|
||||
use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
|
||||
|
||||
use crate::{
|
||||
@ -76,10 +76,8 @@ pub fn edition(self, db: &impl DefDatabase) -> Edition {
|
||||
crate_graph.edition(self.crate_id)
|
||||
}
|
||||
|
||||
// FIXME: should this be in source_binder?
|
||||
pub fn source_root_crates(db: &impl DefDatabase, source_root: SourceRootId) -> Vec<Crate> {
|
||||
let crate_ids = db.source_root_crates(source_root);
|
||||
crate_ids.iter().map(|&crate_id| Crate { crate_id }).collect()
|
||||
pub fn all(db: &impl DefDatabase) -> Vec<Crate> {
|
||||
db.crate_graph().iter().map(|crate_id| Crate { crate_id }).collect()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user