From ac5a3f611b05dbedd286169539335ae9f0fbb7b0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 20 Dec 2019 12:20:49 +0100 Subject: Support for nested ADT --- crates/ra_hir_def/src/body/lower.rs | 26 +++++++++++++++++++------- crates/ra_hir_def/src/lib.rs | 9 +++++---- crates/ra_hir_def/src/nameres/collector.rs | 6 +++--- 3 files changed, 27 insertions(+), 14 deletions(-) (limited to 'crates/ra_hir_def') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 0103a1aab..0d3f946df 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -25,7 +25,7 @@ use crate::{ path::GenericArgs, path::Path, type_ref::{Mutability, TypeRef}, - ContainerId, DefWithBodyId, FunctionLoc, Intern, + ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, StructLoc, UnionLoc, }; pub(super) fn lower( @@ -490,16 +490,28 @@ where } fn collect_block_items(&mut self, block: &ast::Block) { - let container = ContainerId::DefWithBodyId(self.def).into(); + let container = ContainerId::DefWithBodyId(self.def); for item in block.items() { - match item { + let def: ModuleDefId = match item { ast::ModuleItem::FnDef(def) => { let ast_id = self.expander.ast_id(&def); - self.body.defs.push(FunctionLoc { container, ast_id }.intern(self.db).into()) + FunctionLoc { container: container.into(), ast_id }.intern(self.db).into() } - // FIXME: handle other items - _ => (), - } + ast::ModuleItem::StructDef(def) => { + let ast_id = self.expander.ast_id(&def); + StructLoc { container, ast_id }.intern(self.db).into() + } + ast::ModuleItem::EnumDef(def) => { + let ast_id = self.expander.ast_id(&def); + EnumLoc { container, ast_id }.intern(self.db).into() + } + ast::ModuleItem::UnionDef(def) => { + let ast_id = self.expander.ast_id(&def); + UnionLoc { container, ast_id }.intern(self.db).into() + } + _ => continue, + }; + self.body.defs.push(def) } } diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 5e46db1aa..a82de7dec 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -95,7 +95,7 @@ impl_intern_key!(StructId); #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct StructLoc { - pub container: ModuleId, + pub container: ContainerId, pub ast_id: AstId, } @@ -119,7 +119,7 @@ impl_intern_key!(UnionId); #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct UnionLoc { - pub container: ModuleId, + pub container: ContainerId, pub ast_id: AstId, } @@ -143,7 +143,7 @@ impl_intern_key!(EnumId); #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct EnumLoc { - pub container: ModuleId, + pub container: ContainerId, pub ast_id: AstId, } @@ -529,6 +529,7 @@ impl HasModule for AdtId { AdtId::UnionId(it) => it.lookup(db).container, AdtId::EnumId(it) => it.lookup(db).container, } + .module(db) } } @@ -550,7 +551,7 @@ impl HasModule for GenericDefId { GenericDefId::TraitId(it) => it.lookup(db).container, GenericDefId::TypeAliasId(it) => it.lookup(db).module(db), GenericDefId::ImplId(it) => it.lookup(db).container, - GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container, + GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container.module(db), GenericDefId::ConstId(it) => it.lookup(db).module(db), } } diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 0f3319f30..1b39af61e 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -772,17 +772,17 @@ where PerNs::values(def.into()) } raw::DefKind::Struct(ast_id) => { - let def = StructLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) } + let def = StructLoc { container, ast_id: AstId::new(self.file_id, ast_id) } .intern(self.def_collector.db); PerNs::both(def.into(), def.into()) } raw::DefKind::Union(ast_id) => { - let def = UnionLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) } + let def = UnionLoc { container, ast_id: AstId::new(self.file_id, ast_id) } .intern(self.def_collector.db); PerNs::both(def.into(), def.into()) } raw::DefKind::Enum(ast_id) => { - let def = EnumLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) } + let def = EnumLoc { container, ast_id: AstId::new(self.file_id, ast_id) } .intern(self.def_collector.db); PerNs::types(def.into()) } -- cgit v1.2.3