mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 23:24:29 +00:00
Add a transitive deps iterator to CrateGraph
This commit is contained in:
parent
3f94ad332a
commit
63ea8f2af0
1 changed files with 17 additions and 0 deletions
|
@ -197,6 +197,23 @@ impl CrateGraph {
|
|||
self.arena.keys().copied()
|
||||
}
|
||||
|
||||
/// Returns an iterator over all transitive dependencies of the given crate.
|
||||
pub fn transitive_deps(&self, of: CrateId) -> impl Iterator<Item = CrateId> + '_ {
|
||||
let mut worklist = vec![of];
|
||||
let mut deps = FxHashSet::default();
|
||||
|
||||
while let Some(krate) = worklist.pop() {
|
||||
if !deps.insert(krate) {
|
||||
continue;
|
||||
}
|
||||
|
||||
worklist.extend(self[krate].dependencies.iter().map(|dep| dep.crate_id));
|
||||
}
|
||||
|
||||
deps.remove(&of);
|
||||
deps.into_iter()
|
||||
}
|
||||
|
||||
// FIXME: this only finds one crate with the given root; we could have multiple
|
||||
pub fn crate_id_for_crate_root(&self, file_id: FileId) -> Option<CrateId> {
|
||||
let (&crate_id, _) =
|
||||
|
|
Loading…
Reference in a new issue