aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model_impl/module.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/code_model_impl/module.rs')
-rw-r--r--crates/ra_hir/src/code_model_impl/module.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs
index e9ff06dc8..775dd6709 100644
--- a/crates/ra_hir/src/code_model_impl/module.rs
+++ b/crates/ra_hir/src/code_model_impl/module.rs
@@ -95,6 +95,21 @@ impl Module {
95 Module::from_module_id(db, loc.source_root_id, child_id).map(Some) 95 Module::from_module_id(db, loc.source_root_id, child_id).map(Some)
96 } 96 }
97 97
98 /// Iterates over all child modules.
99 pub fn children_impl(&self, db: &impl HirDatabase) -> Cancelable<impl Iterator<Item = Module>> {
100 // FIXME this should be implementable without collecting into a vec, but
101 // it's kind of hard since the iterator needs to keep a reference to the
102 // module tree.
103 let loc = self.def_id.loc(db);
104 let module_tree = db.module_tree(loc.source_root_id)?;
105 let children = loc
106 .module_id
107 .children(&module_tree)
108 .map(|(_, module_id)| Module::from_module_id(db, loc.source_root_id, module_id))
109 .collect::<Cancelable<Vec<_>>>()?;
110 Ok(children.into_iter())
111 }
112
98 pub fn parent_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> { 113 pub fn parent_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> {
99 let loc = self.def_id.loc(db); 114 let loc = self.def_id.loc(db);
100 let module_tree = db.module_tree(loc.source_root_id)?; 115 let module_tree = db.module_tree(loc.source_root_id)?;