aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/code_model_api.rs4
-rw-r--r--crates/ra_hir/src/nameres.rs39
2 files changed, 37 insertions, 6 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index 19f103855..94a08aa63 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -327,7 +327,7 @@ impl Enum {
327 db.enum_data(*self).name.clone() 327 db.enum_data(*self).name.clone()
328 } 328 }
329 329
330 pub fn variants(&self, db: &impl HirDatabase) -> Vec<EnumVariant> { 330 pub fn variants(&self, db: &impl PersistentHirDatabase) -> Vec<EnumVariant> {
331 db.enum_data(*self) 331 db.enum_data(*self)
332 .variants 332 .variants
333 .iter() 333 .iter()
@@ -389,7 +389,7 @@ impl EnumVariant {
389 self.parent 389 self.parent
390 } 390 }
391 391
392 pub fn name(&self, db: &impl HirDatabase) -> Option<Name> { 392 pub fn name(&self, db: &impl PersistentHirDatabase) -> Option<Name> {
393 db.enum_data(self.parent).variants[self.id].name.clone() 393 db.enum_data(self.parent).variants[self.id].name.clone()
394 } 394 }
395 395
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs
index b7382d9c3..0b6ab1211 100644
--- a/crates/ra_hir/src/nameres.rs
+++ b/crates/ra_hir/src/nameres.rs
@@ -264,14 +264,45 @@ where
264 import: &ImportData, 264 import: &ImportData,
265 ) -> ReachedFixedPoint { 265 ) -> ReachedFixedPoint {
266 log::debug!("resolving import: {:?}", import); 266 log::debug!("resolving import: {:?}", import);
267 if import.is_glob {
268 return ReachedFixedPoint::Yes;
269 };
270 let original_module = Module { krate: self.krate, module_id }; 267 let original_module = Module { krate: self.krate, module_id };
271 let (def, reached_fixedpoint) = 268 let (def, reached_fixedpoint) =
272 self.result.resolve_path_fp(self.db, original_module, &import.path); 269 self.result.resolve_path_fp(self.db, original_module, &import.path);
273 270
274 if reached_fixedpoint == ReachedFixedPoint::Yes { 271 if reached_fixedpoint != ReachedFixedPoint::Yes {
272 return reached_fixedpoint;
273 }
274
275 if import.is_glob {
276 log::debug!("glob import: {:?}", import);
277 match def.take_types() {
278 Some(ModuleDef::Module(m)) => {
279 // TODO
280 }
281 Some(ModuleDef::Enum(e)) => {
282 tested_by!(glob_enum);
283 let variants = e.variants(self.db);
284 let resolutions = variants.into_iter()
285 .filter_map(|variant| {
286 let res = Resolution {
287 def: PerNs::both(variant.into(), e.into()),
288 import: Some(import_id),
289 };
290 let name = variant.name(self.db)?;
291 Some((name, res))
292 })
293 .collect::<Vec<_>>();
294 self.update(module_id, |items| {
295 items.items.extend(resolutions);
296 });
297 }
298 Some(d) => {
299 log::debug!("glob import {:?} from non-module/enum {:?}", import, d);
300 }
301 None => {
302 log::debug!("glob import {:?} didn't resolve as type", import);
303 }
304 }
305 } else {
275 let last_segment = import.path.segments.last().unwrap(); 306 let last_segment = import.path.segments.last().unwrap();
276 let name = import.alias.clone().unwrap_or_else(|| last_segment.name.clone()); 307 let name = import.alias.clone().unwrap_or_else(|| last_segment.name.clone());
277 log::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def); 308 log::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def);