aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2020-07-01 14:18:51 +0100
committerJonas Schievink <[email protected]>2020-07-01 14:18:51 +0100
commit63ea8f2af097316523f54f09e1c54d515a1bb9fd (patch)
treeee6ac25d659325235b87c82cb78dcbb43b4b789d /crates
parent3f94ad332aa22252a46d948888f5b23c0e21cd38 (diff)
Add a transitive deps iterator to `CrateGraph`
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_db/src/input.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs
index 445a1ee48..aaa492759 100644
--- a/crates/ra_db/src/input.rs
+++ b/crates/ra_db/src/input.rs
@@ -197,6 +197,23 @@ impl CrateGraph {
197 self.arena.keys().copied() 197 self.arena.keys().copied()
198 } 198 }
199 199
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
200 // FIXME: this only finds one crate with the given root; we could have multiple 217 // FIXME: this only finds one crate with the given root; we could have multiple
201 pub fn crate_id_for_crate_root(&self, file_id: FileId) -> Option<CrateId> { 218 pub fn crate_id_for_crate_root(&self, file_id: FileId) -> Option<CrateId> {
202 let (&crate_id, _) = 219 let (&crate_id, _) =