mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
remove one more dependency on source roots
This commit is contained in:
parent
77f2dd96a1
commit
1555a1aa0d
3 changed files with 26 additions and 21 deletions
|
@ -141,14 +141,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_loading_rust_analyzer() {
|
fn test_loading_rust_analyzer() {
|
||||||
let path = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap().parent().unwrap();
|
let path = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap().parent().unwrap();
|
||||||
let (host, roots) = load_cargo(path).unwrap();
|
let (host, _roots) = load_cargo(path).unwrap();
|
||||||
let mut n_crates = 0;
|
let n_crates = Crate::all(host.raw_database()).len();
|
||||||
for (root, _) in roots {
|
|
||||||
for _krate in Crate::source_root_crates(host.raw_database(), root) {
|
|
||||||
n_crates += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// RA has quite a few crates, but the exact count doesn't matter
|
// RA has quite a few crates, but the exact count doesn't matter
|
||||||
assert!(n_crates > 20);
|
assert!(n_crates > 20);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,16 +22,29 @@ pub fn run(
|
||||||
let mut num_crates = 0;
|
let mut num_crates = 0;
|
||||||
let mut visited_modules = HashSet::new();
|
let mut visited_modules = HashSet::new();
|
||||||
let mut visit_queue = Vec::new();
|
let mut visit_queue = Vec::new();
|
||||||
for (source_root_id, project_root) in roots {
|
|
||||||
if project_root.is_member() {
|
let members = roots
|
||||||
for krate in Crate::source_root_crates(db, source_root_id) {
|
.into_iter()
|
||||||
num_crates += 1;
|
.filter_map(
|
||||||
let module =
|
|(source_root_id, project_root)| {
|
||||||
krate.root_module(db).expect("crate in source root without root module");
|
if project_root.is_member() {
|
||||||
visit_queue.push(module);
|
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);
|
println!("Crates in this dir: {}", num_crates);
|
||||||
let mut num_decls = 0;
|
let mut num_decls = 0;
|
||||||
let mut funcs = Vec::new();
|
let mut funcs = Vec::new();
|
||||||
|
|
|
@ -5,7 +5,7 @@ pub(crate) mod docs;
|
||||||
|
|
||||||
use std::sync::Arc;
|
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 ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -76,10 +76,8 @@ impl Crate {
|
||||||
crate_graph.edition(self.crate_id)
|
crate_graph.edition(self.crate_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: should this be in source_binder?
|
pub fn all(db: &impl DefDatabase) -> Vec<Crate> {
|
||||||
pub fn source_root_crates(db: &impl DefDatabase, source_root: SourceRootId) -> Vec<Crate> {
|
db.crate_graph().iter().map(|crate_id| Crate { crate_id }).collect()
|
||||||
let crate_ids = db.source_root_crates(source_root);
|
|
||||||
crate_ids.iter().map(|&crate_id| Crate { crate_id }).collect()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue