diff options
Diffstat (limited to 'crates/ra_hir_def/src/nameres')
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index a80067979..04aadead1 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -24,9 +24,9 @@ use crate::{ | |||
24 | }, | 24 | }, |
25 | path::{Path, PathKind}, | 25 | path::{Path, PathKind}, |
26 | per_ns::PerNs, | 26 | per_ns::PerNs, |
27 | AdtId, AstId, AstItemDef, ConstLoc, ContainerId, EnumId, EnumVariantId, FunctionLoc, ImplId, | 27 | AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern, |
28 | Intern, LocalImportId, LocalModuleId, LocationCtx, ModuleDefId, ModuleId, StaticLoc, StructId, | 28 | LocalImportId, LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc, |
29 | TraitId, TypeAliasLoc, UnionId, | 29 | TypeAliasLoc, UnionLoc, |
30 | }; | 30 | }; |
31 | 31 | ||
32 | pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { | 32 | pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { |
@@ -661,9 +661,11 @@ where | |||
661 | krate: self.def_collector.def_map.krate, | 661 | krate: self.def_collector.def_map.krate, |
662 | local_id: self.module_id, | 662 | local_id: self.module_id, |
663 | }; | 663 | }; |
664 | let ctx = LocationCtx::new(self.def_collector.db, module, self.file_id); | 664 | let ast_id = self.raw_items[imp].ast_id; |
665 | let imp_id = ImplId::from_ast_id(ctx, self.raw_items[imp].ast_id); | 665 | let impl_id = |
666 | self.def_collector.def_map.modules[self.module_id].impls.push(imp_id) | 666 | ImplLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) } |
667 | .intern(self.def_collector.db); | ||
668 | self.def_collector.def_map.modules[self.module_id].impls.push(impl_id) | ||
667 | } | 669 | } |
668 | } | 670 | } |
669 | } | 671 | } |
@@ -751,8 +753,6 @@ where | |||
751 | 753 | ||
752 | fn define_def(&mut self, def: &raw::DefData, attrs: &Attrs) { | 754 | fn define_def(&mut self, def: &raw::DefData, attrs: &Attrs) { |
753 | let module = ModuleId { krate: self.def_collector.def_map.krate, local_id: self.module_id }; | 755 | let module = ModuleId { krate: self.def_collector.def_map.krate, local_id: self.module_id }; |
754 | let ctx = LocationCtx::new(self.def_collector.db, module, self.file_id); | ||
755 | |||
756 | // FIXME: check attrs to see if this is an attribute macro invocation; | 756 | // FIXME: check attrs to see if this is an attribute macro invocation; |
757 | // in which case we don't add the invocation, just a single attribute | 757 | // in which case we don't add the invocation, just a single attribute |
758 | // macro invocation | 758 | // macro invocation |
@@ -771,14 +771,20 @@ where | |||
771 | PerNs::values(def.into()) | 771 | PerNs::values(def.into()) |
772 | } | 772 | } |
773 | raw::DefKind::Struct(ast_id) => { | 773 | raw::DefKind::Struct(ast_id) => { |
774 | let id = StructId::from_ast_id(ctx, ast_id).into(); | 774 | let def = StructLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) } |
775 | PerNs::both(id, id) | 775 | .intern(self.def_collector.db); |
776 | PerNs::both(def.into(), def.into()) | ||
776 | } | 777 | } |
777 | raw::DefKind::Union(ast_id) => { | 778 | raw::DefKind::Union(ast_id) => { |
778 | let id = UnionId::from_ast_id(ctx, ast_id).into(); | 779 | let def = UnionLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) } |
779 | PerNs::both(id, id) | 780 | .intern(self.def_collector.db); |
781 | PerNs::both(def.into(), def.into()) | ||
782 | } | ||
783 | raw::DefKind::Enum(ast_id) => { | ||
784 | let def = EnumLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) } | ||
785 | .intern(self.def_collector.db); | ||
786 | PerNs::types(def.into()) | ||
780 | } | 787 | } |
781 | raw::DefKind::Enum(ast_id) => PerNs::types(EnumId::from_ast_id(ctx, ast_id).into()), | ||
782 | raw::DefKind::Const(ast_id) => { | 788 | raw::DefKind::Const(ast_id) => { |
783 | let def = ConstLoc { | 789 | let def = ConstLoc { |
784 | container: ContainerId::ModuleId(module), | 790 | container: ContainerId::ModuleId(module), |
@@ -794,7 +800,12 @@ where | |||
794 | 800 | ||
795 | PerNs::values(def.into()) | 801 | PerNs::values(def.into()) |
796 | } | 802 | } |
797 | raw::DefKind::Trait(ast_id) => PerNs::types(TraitId::from_ast_id(ctx, ast_id).into()), | 803 | raw::DefKind::Trait(ast_id) => { |
804 | let def = TraitLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) } | ||
805 | .intern(self.def_collector.db); | ||
806 | |||
807 | PerNs::types(def.into()) | ||
808 | } | ||
798 | raw::DefKind::TypeAlias(ast_id) => { | 809 | raw::DefKind::TypeAlias(ast_id) => { |
799 | let def = TypeAliasLoc { | 810 | let def = TypeAliasLoc { |
800 | container: ContainerId::ModuleId(module), | 811 | container: ContainerId::ModuleId(module), |