diff options
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/code_model_impl/module.rs | 64 |
1 files changed, 33 insertions, 31 deletions
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index e5394d440..7215236f9 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs | |||
@@ -147,41 +147,43 @@ impl Module { | |||
147 | .def_id, | 147 | .def_id, |
148 | ); | 148 | ); |
149 | 149 | ||
150 | let segments = &path.segments; | 150 | for name in path.segments.iter() { |
151 | for (idx, name) in segments.iter().enumerate() { | 151 | let curr = match curr_per_ns.as_ref().take_types() { |
152 | let curr = if let Some(r) = curr_per_ns.as_ref().take_types() { | 152 | Some(r) => r, |
153 | r | 153 | None => { |
154 | } else { | 154 | // we still have path segments left, but the path so far |
155 | return PerNs::none(); | 155 | // didn't resolve in the types namespace => no resolution |
156 | // (don't break here because curr_per_ns might contain | ||
157 | // something in the value namespace, and it would be wrong | ||
158 | // to return that) | ||
159 | return PerNs::none(); | ||
160 | } | ||
156 | }; | 161 | }; |
157 | let module = match curr.resolve(db) { | 162 | // resolve segment in curr |
158 | Def::Module(it) => it, | 163 | curr_per_ns = match curr.resolve(db) { |
164 | Def::Module(m) => { | ||
165 | let scope = m.scope(db); | ||
166 | match scope.get(&name) { | ||
167 | Some(r) => r.def_id, | ||
168 | None => PerNs::none(), | ||
169 | } | ||
170 | } | ||
159 | Def::Enum(e) => { | 171 | Def::Enum(e) => { |
160 | if segments.len() == idx + 1 { | 172 | // enum variant |
161 | // enum variant | 173 | let matching_variant = |
162 | let matching_variant = | 174 | e.variants(db).into_iter().find(|(n, _variant)| n == name); |
163 | e.variants(db).into_iter().find(|(n, _variant)| n == name); | 175 | |
164 | 176 | match matching_variant { | |
165 | if let Some((_n, variant)) = matching_variant { | 177 | Some((_n, variant)) => PerNs::both(variant.def_id(), e.def_id()), |
166 | return PerNs::both(variant.def_id(), e.def_id()); | 178 | None => PerNs::none(), |
167 | } else { | ||
168 | return PerNs::none(); | ||
169 | } | ||
170 | } else if segments.len() == idx { | ||
171 | // enum | ||
172 | return PerNs::types(e.def_id()); | ||
173 | } else { | ||
174 | // malformed enum? | ||
175 | return PerNs::none(); | ||
176 | } | 179 | } |
177 | } | 180 | } |
178 | _ => return PerNs::none(), | 181 | _ => { |
179 | }; | 182 | // could be an inherent method call in UFCS form |
180 | let scope = module.scope(db); | 183 | // (`Struct::method`), or some other kind of associated |
181 | curr_per_ns = if let Some(r) = scope.get(&name) { | 184 | // item... Which we currently don't handle (TODO) |
182 | r.def_id | 185 | PerNs::none() |
183 | } else { | 186 | } |
184 | return PerNs::none(); | ||
185 | }; | 187 | }; |
186 | } | 188 | } |
187 | curr_per_ns | 189 | curr_per_ns |