aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model_impl
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/code_model_impl')
-rw-r--r--crates/ra_hir/src/code_model_impl/module.rs21
1 files changed, 12 insertions, 9 deletions
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs
index 2ec3ab469..67808d282 100644
--- a/crates/ra_hir/src/code_model_impl/module.rs
+++ b/crates/ra_hir/src/code_model_impl/module.rs
@@ -18,7 +18,7 @@ impl Module {
18 db: &impl HirDatabase, 18 db: &impl HirDatabase,
19 source_root_id: SourceRootId, 19 source_root_id: SourceRootId,
20 module_id: ModuleId, 20 module_id: ModuleId,
21 ) -> Cancelable<Self> { 21 ) -> Self {
22 let module_tree = db.module_tree(source_root_id); 22 let module_tree = db.module_tree(source_root_id);
23 let def_loc = DefLoc { 23 let def_loc = DefLoc {
24 kind: DefKind::Module, 24 kind: DefKind::Module,
@@ -27,8 +27,7 @@ impl Module {
27 source_item_id: module_id.source(&module_tree), 27 source_item_id: module_id.source(&module_tree),
28 }; 28 };
29 let def_id = def_loc.id(db); 29 let def_id = def_loc.id(db);
30 let module = Module::new(def_id); 30 Module::new(def_id)
31 Ok(module)
32 } 31 }
33 32
34 pub(crate) fn name_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> { 33 pub(crate) fn name_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> {
@@ -84,15 +83,15 @@ impl Module {
84 let loc = self.def_id.loc(db); 83 let loc = self.def_id.loc(db);
85 let module_tree = db.module_tree(loc.source_root_id); 84 let module_tree = db.module_tree(loc.source_root_id);
86 let module_id = loc.module_id.crate_root(&module_tree); 85 let module_id = loc.module_id.crate_root(&module_tree);
87 Module::from_module_id(db, loc.source_root_id, module_id) 86 Ok(Module::from_module_id(db, loc.source_root_id, module_id))
88 } 87 }
89 88
90 /// Finds a child module with the specified name. 89 /// Finds a child module with the specified name.
91 pub fn child_impl(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> { 90 pub fn child_impl(&self, db: &impl HirDatabase, name: &Name) -> Option<Module> {
92 let loc = self.def_id.loc(db); 91 let loc = self.def_id.loc(db);
93 let module_tree = db.module_tree(loc.source_root_id); 92 let module_tree = db.module_tree(loc.source_root_id);
94 let child_id = ctry!(loc.module_id.child(&module_tree, name)); 93 let child_id = loc.module_id.child(&module_tree, name)?;
95 Module::from_module_id(db, loc.source_root_id, child_id).map(Some) 94 Some(Module::from_module_id(db, loc.source_root_id, child_id))
96 } 95 }
97 96
98 /// Iterates over all child modules. 97 /// Iterates over all child modules.
@@ -106,7 +105,7 @@ impl Module {
106 .module_id 105 .module_id
107 .children(&module_tree) 106 .children(&module_tree)
108 .map(|(_, module_id)| Module::from_module_id(db, loc.source_root_id, module_id)) 107 .map(|(_, module_id)| Module::from_module_id(db, loc.source_root_id, module_id))
109 .collect::<Cancelable<Vec<_>>>()?; 108 .collect::<Vec<_>>();
110 Ok(children.into_iter()) 109 Ok(children.into_iter())
111 } 110 }
112 111
@@ -114,7 +113,11 @@ impl Module {
114 let loc = self.def_id.loc(db); 113 let loc = self.def_id.loc(db);
115 let module_tree = db.module_tree(loc.source_root_id); 114 let module_tree = db.module_tree(loc.source_root_id);
116 let parent_id = ctry!(loc.module_id.parent(&module_tree)); 115 let parent_id = ctry!(loc.module_id.parent(&module_tree));
117 Module::from_module_id(db, loc.source_root_id, parent_id).map(Some) 116 Ok(Some(Module::from_module_id(
117 db,
118 loc.source_root_id,
119 parent_id,
120 )))
118 } 121 }
119 122
120 /// Returns a `ModuleScope`: a set of items, visible in this module. 123 /// Returns a `ModuleScope`: a set of items, visible in this module.