diff options
Diffstat (limited to 'crates/ra_hir/src/code_model_impl')
-rw-r--r-- | crates/ra_hir/src/code_model_impl/module.rs | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index 7215236f9..73c212de8 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs | |||
@@ -95,7 +95,7 @@ impl Module { | |||
95 | } | 95 | } |
96 | 96 | ||
97 | /// Finds a child module with the specified name. | 97 | /// Finds a child module with the specified name. |
98 | pub fn child_impl(&self, db: &impl HirDatabase, name: &Name) -> Option<Module> { | 98 | pub(crate) fn child_impl(&self, db: &impl HirDatabase, name: &Name) -> Option<Module> { |
99 | let loc = self.def_id.loc(db); | 99 | let loc = self.def_id.loc(db); |
100 | let module_tree = db.module_tree(loc.source_root_id); | 100 | let module_tree = db.module_tree(loc.source_root_id); |
101 | let child_id = loc.module_id.child(&module_tree, name)?; | 101 | let child_id = loc.module_id.child(&module_tree, name)?; |
@@ -103,7 +103,7 @@ impl Module { | |||
103 | } | 103 | } |
104 | 104 | ||
105 | /// Iterates over all child modules. | 105 | /// Iterates over all child modules. |
106 | pub fn children_impl(&self, db: &impl HirDatabase) -> impl Iterator<Item = Module> { | 106 | pub(crate) fn children_impl(&self, db: &impl HirDatabase) -> impl Iterator<Item = Module> { |
107 | // FIXME this should be implementable without collecting into a vec, but | 107 | // FIXME this should be implementable without collecting into a vec, but |
108 | // it's kind of hard since the iterator needs to keep a reference to the | 108 | // it's kind of hard since the iterator needs to keep a reference to the |
109 | // module tree. | 109 | // module tree. |
@@ -117,7 +117,7 @@ impl Module { | |||
117 | children.into_iter() | 117 | children.into_iter() |
118 | } | 118 | } |
119 | 119 | ||
120 | pub fn parent_impl(&self, db: &impl HirDatabase) -> Option<Module> { | 120 | pub(crate) fn parent_impl(&self, db: &impl HirDatabase) -> Option<Module> { |
121 | let loc = self.def_id.loc(db); | 121 | let loc = self.def_id.loc(db); |
122 | let module_tree = db.module_tree(loc.source_root_id); | 122 | let module_tree = db.module_tree(loc.source_root_id); |
123 | let parent_id = loc.module_id.parent(&module_tree)?; | 123 | let parent_id = loc.module_id.parent(&module_tree)?; |
@@ -125,13 +125,13 @@ impl Module { | |||
125 | } | 125 | } |
126 | 126 | ||
127 | /// Returns a `ModuleScope`: a set of items, visible in this module. | 127 | /// Returns a `ModuleScope`: a set of items, visible in this module. |
128 | pub fn scope_impl(&self, db: &impl HirDatabase) -> ModuleScope { | 128 | pub(crate) fn scope_impl(&self, db: &impl HirDatabase) -> ModuleScope { |
129 | let loc = self.def_id.loc(db); | 129 | let loc = self.def_id.loc(db); |
130 | let item_map = db.item_map(loc.source_root_id); | 130 | let item_map = db.item_map(loc.source_root_id); |
131 | item_map.per_module[&loc.module_id].clone() | 131 | item_map.per_module[&loc.module_id].clone() |
132 | } | 132 | } |
133 | 133 | ||
134 | pub fn resolve_path_impl(&self, db: &impl HirDatabase, path: &Path) -> PerNs<DefId> { | 134 | pub(crate) fn resolve_path_impl(&self, db: &impl HirDatabase, path: &Path) -> PerNs<DefId> { |
135 | let mut curr_per_ns = PerNs::types( | 135 | let mut curr_per_ns = PerNs::types( |
136 | match path.kind { | 136 | match path.kind { |
137 | PathKind::Crate => self.crate_root(db), | 137 | PathKind::Crate => self.crate_root(db), |
@@ -147,7 +147,7 @@ impl Module { | |||
147 | .def_id, | 147 | .def_id, |
148 | ); | 148 | ); |
149 | 149 | ||
150 | for name in path.segments.iter() { | 150 | for segment in path.segments.iter() { |
151 | let curr = match curr_per_ns.as_ref().take_types() { | 151 | let curr = match curr_per_ns.as_ref().take_types() { |
152 | Some(r) => r, | 152 | Some(r) => r, |
153 | None => { | 153 | None => { |
@@ -163,15 +163,17 @@ impl Module { | |||
163 | curr_per_ns = match curr.resolve(db) { | 163 | curr_per_ns = match curr.resolve(db) { |
164 | Def::Module(m) => { | 164 | Def::Module(m) => { |
165 | let scope = m.scope(db); | 165 | let scope = m.scope(db); |
166 | match scope.get(&name) { | 166 | match scope.get(&segment.name) { |
167 | Some(r) => r.def_id, | 167 | Some(r) => r.def_id, |
168 | None => PerNs::none(), | 168 | None => PerNs::none(), |
169 | } | 169 | } |
170 | } | 170 | } |
171 | Def::Enum(e) => { | 171 | Def::Enum(e) => { |
172 | // enum variant | 172 | // enum variant |
173 | let matching_variant = | 173 | let matching_variant = e |
174 | e.variants(db).into_iter().find(|(n, _variant)| n == name); | 174 | .variants(db) |
175 | .into_iter() | ||
176 | .find(|(n, _variant)| n == &segment.name); | ||
175 | 177 | ||
176 | match matching_variant { | 178 | match matching_variant { |
177 | Some((_n, variant)) => PerNs::both(variant.def_id(), e.def_id()), | 179 | Some((_n, variant)) => PerNs::both(variant.def_id(), e.def_id()), |
@@ -189,7 +191,10 @@ impl Module { | |||
189 | curr_per_ns | 191 | curr_per_ns |
190 | } | 192 | } |
191 | 193 | ||
192 | pub fn problems_impl(&self, db: &impl HirDatabase) -> Vec<(TreeArc<SyntaxNode>, Problem)> { | 194 | pub(crate) fn problems_impl( |
195 | &self, | ||
196 | db: &impl HirDatabase, | ||
197 | ) -> Vec<(TreeArc<SyntaxNode>, Problem)> { | ||
193 | let loc = self.def_id.loc(db); | 198 | let loc = self.def_id.loc(db); |
194 | let module_tree = db.module_tree(loc.source_root_id); | 199 | let module_tree = db.module_tree(loc.source_root_id); |
195 | loc.module_id.problems(&module_tree, db) | 200 | loc.module_id.problems(&module_tree, db) |