From 082ef52bcb15d779c6aff78d9860d328bf7df9b2 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Mon, 7 Jan 2019 13:44:54 +0100 Subject: Implement basic inherent method resolution --- crates/ra_hir/src/code_model_impl/module.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'crates/ra_hir/src/code_model_impl/module.rs') 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 { Module::from_module_id(db, loc.source_root_id, child_id).map(Some) } + /// Iterates over all child modules. + pub fn children_impl(&self, db: &impl HirDatabase) -> Cancelable> { + // FIXME this should be implementable without collecting into a vec, but + // it's kind of hard since the iterator needs to keep a reference to the + // module tree. + let loc = self.def_id.loc(db); + let module_tree = db.module_tree(loc.source_root_id)?; + let children = loc + .module_id + .children(&module_tree) + .map(|(_, module_id)| Module::from_module_id(db, loc.source_root_id, module_id)) + .collect::>>()?; + Ok(children.into_iter()) + } + pub fn parent_impl(&self, db: &impl HirDatabase) -> Cancelable> { let loc = self.def_id.loc(db); let module_tree = db.module_tree(loc.source_root_id)?; -- cgit v1.2.3