aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir_def/src/item_scope.rs20
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs81
2 files changed, 52 insertions, 49 deletions
diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs
index eab3e2fff..a96b5cfd2 100644
--- a/crates/ra_hir_def/src/item_scope.rs
+++ b/crates/ra_hir_def/src/item_scope.rs
@@ -5,7 +5,7 @@ use hir_expand::name::Name;
5use once_cell::sync::Lazy; 5use once_cell::sync::Lazy;
6use rustc_hash::FxHashMap; 6use rustc_hash::FxHashMap;
7 7
8use crate::{per_ns::PerNs, BuiltinType, ImplId, MacroDefId, ModuleDefId, TraitId}; 8use crate::{per_ns::PerNs, AdtId, BuiltinType, ImplId, MacroDefId, ModuleDefId, TraitId};
9 9
10#[derive(Debug, Default, PartialEq, Eq)] 10#[derive(Debug, Default, PartialEq, Eq)]
11pub struct ItemScope { 11pub struct ItemScope {
@@ -153,3 +153,21 @@ pub struct Resolution {
153 pub def: PerNs, 153 pub def: PerNs,
154 pub(crate) import: bool, 154 pub(crate) import: bool,
155} 155}
156
157impl From<ModuleDefId> for PerNs {
158 fn from(def: ModuleDefId) -> PerNs {
159 match def {
160 ModuleDefId::ModuleId(_) => PerNs::types(def),
161 ModuleDefId::FunctionId(_) => PerNs::values(def),
162 ModuleDefId::AdtId(adt) => match adt {
163 AdtId::StructId(_) | AdtId::UnionId(_) => PerNs::both(def, def),
164 AdtId::EnumId(_) => PerNs::types(def),
165 },
166 ModuleDefId::EnumVariantId(_) => PerNs::both(def, def),
167 ModuleDefId::ConstId(_) | ModuleDefId::StaticId(_) => PerNs::values(def),
168 ModuleDefId::TraitId(_) => PerNs::types(def),
169 ModuleDefId::TypeAliasId(_) => PerNs::types(def),
170 ModuleDefId::BuiltinType(_) => PerNs::types(def),
171 }
172 }
173}
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index 2b194f488..b4e438257 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -714,12 +714,9 @@ where
714 modules[res].scope.define_legacy_macro(name, mac) 714 modules[res].scope.define_legacy_macro(name, mac)
715 } 715 }
716 modules[self.module_id].children.insert(name.clone(), res); 716 modules[self.module_id].children.insert(name.clone(), res);
717 let resolution = Resolution { 717 let module = ModuleId { krate: self.def_collector.def_map.krate, local_id: res };
718 def: PerNs::types( 718 let def: ModuleDefId = module.into();
719 ModuleId { krate: self.def_collector.def_map.krate, local_id: res }.into(), 719 let resolution = Resolution { def: def.into(), import: false };
720 ),
721 import: false,
722 };
723 self.def_collector.update(self.module_id, None, &[(name, resolution)]); 720 self.def_collector.update(self.module_id, None, &[(name, resolution)]);
724 res 721 res
725 } 722 }
@@ -734,63 +731,51 @@ where
734 731
735 let name = def.name.clone(); 732 let name = def.name.clone();
736 let container = ContainerId::ModuleId(module); 733 let container = ContainerId::ModuleId(module);
737 let def: PerNs = match def.kind { 734 let def: ModuleDefId = match def.kind {
738 raw::DefKind::Function(ast_id) => { 735 raw::DefKind::Function(ast_id) => FunctionLoc {
739 let def = FunctionLoc { 736 container: container.into(),
740 container: container.into(), 737 ast_id: AstId::new(self.file_id, ast_id),
741 ast_id: AstId::new(self.file_id, ast_id),
742 }
743 .intern(self.def_collector.db);
744
745 PerNs::values(def.into())
746 } 738 }
739 .intern(self.def_collector.db)
740 .into(),
747 raw::DefKind::Struct(ast_id) => { 741 raw::DefKind::Struct(ast_id) => {
748 let def = StructLoc { container, ast_id: AstId::new(self.file_id, ast_id) } 742 StructLoc { container, ast_id: AstId::new(self.file_id, ast_id) }
749 .intern(self.def_collector.db); 743 .intern(self.def_collector.db)
750 PerNs::both(def.into(), def.into()) 744 .into()
751 } 745 }
752 raw::DefKind::Union(ast_id) => { 746 raw::DefKind::Union(ast_id) => {
753 let def = UnionLoc { container, ast_id: AstId::new(self.file_id, ast_id) } 747 UnionLoc { container, ast_id: AstId::new(self.file_id, ast_id) }
754 .intern(self.def_collector.db); 748 .intern(self.def_collector.db)
755 PerNs::both(def.into(), def.into()) 749 .into()
756 } 750 }
757 raw::DefKind::Enum(ast_id) => { 751 raw::DefKind::Enum(ast_id) => {
758 let def = EnumLoc { container, ast_id: AstId::new(self.file_id, ast_id) } 752 EnumLoc { container, ast_id: AstId::new(self.file_id, ast_id) }
759 .intern(self.def_collector.db); 753 .intern(self.def_collector.db)
760 PerNs::types(def.into()) 754 .into()
761 } 755 }
762 raw::DefKind::Const(ast_id) => { 756 raw::DefKind::Const(ast_id) => {
763 let def = ConstLoc { 757 ConstLoc { container: container.into(), ast_id: AstId::new(self.file_id, ast_id) }
764 container: container.into(), 758 .intern(self.def_collector.db)
765 ast_id: AstId::new(self.file_id, ast_id), 759 .into()
766 }
767 .intern(self.def_collector.db);
768
769 PerNs::values(def.into())
770 } 760 }
771 raw::DefKind::Static(ast_id) => { 761 raw::DefKind::Static(ast_id) => {
772 let def = StaticLoc { container, ast_id: AstId::new(self.file_id, ast_id) } 762 StaticLoc { container, ast_id: AstId::new(self.file_id, ast_id) }
773 .intern(self.def_collector.db); 763 .intern(self.def_collector.db)
774 764 .into()
775 PerNs::values(def.into())
776 } 765 }
777 raw::DefKind::Trait(ast_id) => { 766 raw::DefKind::Trait(ast_id) => {
778 let def = TraitLoc { container, ast_id: AstId::new(self.file_id, ast_id) } 767 TraitLoc { container, ast_id: AstId::new(self.file_id, ast_id) }
779 .intern(self.def_collector.db); 768 .intern(self.def_collector.db)
780 769 .into()
781 PerNs::types(def.into())
782 } 770 }
783 raw::DefKind::TypeAlias(ast_id) => { 771 raw::DefKind::TypeAlias(ast_id) => TypeAliasLoc {
784 let def = TypeAliasLoc { 772 container: container.into(),
785 container: container.into(), 773 ast_id: AstId::new(self.file_id, ast_id),
786 ast_id: AstId::new(self.file_id, ast_id),
787 }
788 .intern(self.def_collector.db);
789
790 PerNs::types(def.into())
791 } 774 }
775 .intern(self.def_collector.db)
776 .into(),
792 }; 777 };
793 let resolution = Resolution { def, import: false }; 778 let resolution = Resolution { def: def.into(), import: false };
794 self.def_collector.update(self.module_id, None, &[(name, resolution)]) 779 self.def_collector.update(self.module_id, None, &[(name, resolution)])
795 } 780 }
796 781