diff options
Diffstat (limited to 'crates/ra_hir/src/code_model_impl')
-rw-r--r-- | crates/ra_hir/src/code_model_impl/module.rs | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index 127dcc570..8668d6c8a 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs | |||
@@ -66,21 +66,21 @@ impl Module { | |||
66 | Some((file_id, src)) | 66 | Some((file_id, src)) |
67 | } | 67 | } |
68 | 68 | ||
69 | pub(crate) fn krate_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> { | 69 | pub(crate) fn krate_impl(&self, db: &impl HirDatabase) -> Option<Crate> { |
70 | let root = self.crate_root(db)?; | 70 | let root = self.crate_root(db); |
71 | let loc = root.def_id.loc(db); | 71 | let loc = root.def_id.loc(db); |
72 | let file_id = loc.source_item_id.file_id.as_original_file(); | 72 | let file_id = loc.source_item_id.file_id.as_original_file(); |
73 | 73 | ||
74 | let crate_graph = db.crate_graph(); | 74 | let crate_graph = db.crate_graph(); |
75 | let crate_id = ctry!(crate_graph.crate_id_for_crate_root(file_id)); | 75 | let crate_id = crate_graph.crate_id_for_crate_root(file_id)?; |
76 | Ok(Some(Crate::new(crate_id))) | 76 | Some(Crate::new(crate_id)) |
77 | } | 77 | } |
78 | 78 | ||
79 | pub(crate) fn crate_root_impl(&self, db: &impl HirDatabase) -> Cancelable<Module> { | 79 | pub(crate) fn crate_root_impl(&self, db: &impl HirDatabase) -> Module { |
80 | let loc = self.def_id.loc(db); | 80 | let loc = self.def_id.loc(db); |
81 | let module_tree = db.module_tree(loc.source_root_id); | 81 | let module_tree = db.module_tree(loc.source_root_id); |
82 | let module_id = loc.module_id.crate_root(&module_tree); | 82 | let module_id = loc.module_id.crate_root(&module_tree); |
83 | Ok(Module::from_module_id(db, loc.source_root_id, module_id)) | 83 | Module::from_module_id(db, loc.source_root_id, module_id) |
84 | } | 84 | } |
85 | 85 | ||
86 | /// Finds a child module with the specified name. | 86 | /// Finds a child module with the specified name. |
@@ -92,7 +92,7 @@ impl Module { | |||
92 | } | 92 | } |
93 | 93 | ||
94 | /// Iterates over all child modules. | 94 | /// Iterates over all child modules. |
95 | pub fn children_impl(&self, db: &impl HirDatabase) -> Cancelable<impl Iterator<Item = Module>> { | 95 | pub fn children_impl(&self, db: &impl HirDatabase) -> impl Iterator<Item = Module> { |
96 | // FIXME this should be implementable without collecting into a vec, but | 96 | // FIXME this should be implementable without collecting into a vec, but |
97 | // it's kind of hard since the iterator needs to keep a reference to the | 97 | // it's kind of hard since the iterator needs to keep a reference to the |
98 | // module tree. | 98 | // module tree. |
@@ -103,18 +103,14 @@ impl Module { | |||
103 | .children(&module_tree) | 103 | .children(&module_tree) |
104 | .map(|(_, module_id)| Module::from_module_id(db, loc.source_root_id, module_id)) | 104 | .map(|(_, module_id)| Module::from_module_id(db, loc.source_root_id, module_id)) |
105 | .collect::<Vec<_>>(); | 105 | .collect::<Vec<_>>(); |
106 | Ok(children.into_iter()) | 106 | children.into_iter() |
107 | } | 107 | } |
108 | 108 | ||
109 | pub fn parent_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> { | 109 | pub fn parent_impl(&self, db: &impl HirDatabase) -> Option<Module> { |
110 | let loc = self.def_id.loc(db); | 110 | let loc = self.def_id.loc(db); |
111 | let module_tree = db.module_tree(loc.source_root_id); | 111 | let module_tree = db.module_tree(loc.source_root_id); |
112 | let parent_id = ctry!(loc.module_id.parent(&module_tree)); | 112 | let parent_id = loc.module_id.parent(&module_tree)?; |
113 | Ok(Some(Module::from_module_id( | 113 | Some(Module::from_module_id(db, loc.source_root_id, parent_id)) |
114 | db, | ||
115 | loc.source_root_id, | ||
116 | parent_id, | ||
117 | ))) | ||
118 | } | 114 | } |
119 | 115 | ||
120 | /// Returns a `ModuleScope`: a set of items, visible in this module. | 116 | /// Returns a `ModuleScope`: a set of items, visible in this module. |
@@ -132,10 +128,10 @@ impl Module { | |||
132 | ) -> Cancelable<PerNs<DefId>> { | 128 | ) -> Cancelable<PerNs<DefId>> { |
133 | let mut curr_per_ns = PerNs::types( | 129 | let mut curr_per_ns = PerNs::types( |
134 | match path.kind { | 130 | match path.kind { |
135 | PathKind::Crate => self.crate_root(db)?, | 131 | PathKind::Crate => self.crate_root(db), |
136 | PathKind::Self_ | PathKind::Plain => self.clone(), | 132 | PathKind::Self_ | PathKind::Plain => self.clone(), |
137 | PathKind::Super => { | 133 | PathKind::Super => { |
138 | if let Some(p) = self.parent(db)? { | 134 | if let Some(p) = self.parent(db) { |
139 | p | 135 | p |
140 | } else { | 136 | } else { |
141 | return Ok(PerNs::none()); | 137 | return Ok(PerNs::none()); |