Skip to content

Commit 63ea8f2

Browse files
author
Jonas Schievink
committed
Add a transitive deps iterator to CrateGraph
1 parent 3f94ad3 commit 63ea8f2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

crates/ra_db/src/input.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,23 @@ impl CrateGraph {
197197
self.arena.keys().copied()
198198
}
199199

200+
/// Returns an iterator over all transitive dependencies of the given crate.
201+
pub fn transitive_deps(&self, of: CrateId) -> impl Iterator<Item = CrateId> + '_ {
202+
let mut worklist = vec![of];
203+
let mut deps = FxHashSet::default();
204+
205+
while let Some(krate) = worklist.pop() {
206+
if !deps.insert(krate) {
207+
continue;
208+
}
209+
210+
worklist.extend(self[krate].dependencies.iter().map(|dep| dep.crate_id));
211+
}
212+
213+
deps.remove(&of);
214+
deps.into_iter()
215+
}
216+
200217
// FIXME: this only finds one crate with the given root; we could have multiple
201218
pub fn crate_id_for_crate_root(&self, file_id: FileId) -> Option<CrateId> {
202219
let (&crate_id, _) =

0 commit comments

Comments
 (0)