diff options
Diffstat (limited to 'crates/ra_hir/src/nameres.rs')
-rw-r--r-- | crates/ra_hir/src/nameres.rs | 40 |
1 files changed, 11 insertions, 29 deletions
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index 56ed872d5..e962bbd31 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs | |||
@@ -61,9 +61,9 @@ use ra_db::{FileId, Edition}; | |||
61 | use test_utils::tested_by; | 61 | use test_utils::tested_by; |
62 | 62 | ||
63 | use crate::{ | 63 | use crate::{ |
64 | ModuleDef, Name, Crate, Module, | 64 | ModuleDef, Name, Crate, Module, SourceItemId, |
65 | DefDatabase, Path, PathKind, HirFileId, | 65 | DefDatabase, Path, PathKind, HirFileId, Trait, |
66 | ids::{SourceItemId, SourceFileItemId, MacroCallId}, | 66 | ids::MacroDefId, |
67 | diagnostics::DiagnosticSink, | 67 | diagnostics::DiagnosticSink, |
68 | nameres::diagnostics::DefDiagnostic, | 68 | nameres::diagnostics::DefDiagnostic, |
69 | }; | 69 | }; |
@@ -84,9 +84,7 @@ pub struct CrateDefMap { | |||
84 | extern_prelude: FxHashMap<Name, ModuleDef>, | 84 | extern_prelude: FxHashMap<Name, ModuleDef>, |
85 | root: CrateModuleId, | 85 | root: CrateModuleId, |
86 | modules: Arena<CrateModuleId, ModuleData>, | 86 | modules: Arena<CrateModuleId, ModuleData>, |
87 | macros: Arena<CrateMacroId, mbe::MacroRules>, | 87 | public_macros: FxHashMap<Name, MacroDefId>, |
88 | public_macros: FxHashMap<Name, CrateMacroId>, | ||
89 | macro_resolutions: FxHashMap<MacroCallId, (Crate, CrateMacroId)>, | ||
90 | diagnostics: Vec<DefDiagnostic>, | 88 | diagnostics: Vec<DefDiagnostic>, |
91 | } | 89 | } |
92 | 90 | ||
@@ -97,18 +95,6 @@ impl std::ops::Index<CrateModuleId> for CrateDefMap { | |||
97 | } | 95 | } |
98 | } | 96 | } |
99 | 97 | ||
100 | impl std::ops::Index<CrateMacroId> for CrateDefMap { | ||
101 | type Output = mbe::MacroRules; | ||
102 | fn index(&self, id: CrateMacroId) -> &mbe::MacroRules { | ||
103 | &self.macros[id] | ||
104 | } | ||
105 | } | ||
106 | |||
107 | /// An ID of a macro, **local** to a specific crate | ||
108 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
109 | pub(crate) struct CrateMacroId(RawId); | ||
110 | impl_arena_id!(CrateMacroId); | ||
111 | |||
112 | /// An ID of a module, **local** to a specific crate | 98 | /// An ID of a module, **local** to a specific crate |
113 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | 99 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
114 | pub(crate) struct CrateModuleId(RawId); | 100 | pub(crate) struct CrateModuleId(RawId); |
@@ -139,6 +125,12 @@ impl ModuleScope { | |||
139 | pub fn get(&self, name: &Name) -> Option<&Resolution> { | 125 | pub fn get(&self, name: &Name) -> Option<&Resolution> { |
140 | self.items.get(name) | 126 | self.items.get(name) |
141 | } | 127 | } |
128 | pub fn traits<'a>(&'a self) -> impl Iterator<Item = Trait> + 'a { | ||
129 | self.items.values().filter_map(|r| match r.def.take_types() { | ||
130 | Some(ModuleDef::Trait(t)) => Some(t), | ||
131 | _ => None, | ||
132 | }) | ||
133 | } | ||
142 | } | 134 | } |
143 | 135 | ||
144 | #[derive(Debug, Clone, PartialEq, Eq, Default)] | 136 | #[derive(Debug, Clone, PartialEq, Eq, Default)] |
@@ -196,9 +188,7 @@ impl CrateDefMap { | |||
196 | prelude: None, | 188 | prelude: None, |
197 | root, | 189 | root, |
198 | modules, | 190 | modules, |
199 | macros: Arena::default(), | ||
200 | public_macros: FxHashMap::default(), | 191 | public_macros: FxHashMap::default(), |
201 | macro_resolutions: FxHashMap::default(), | ||
202 | diagnostics: Vec::new(), | 192 | diagnostics: Vec::new(), |
203 | } | 193 | } |
204 | }; | 194 | }; |
@@ -232,19 +222,11 @@ impl CrateDefMap { | |||
232 | self.diagnostics.iter().for_each(|it| it.add_to(db, module, sink)) | 222 | self.diagnostics.iter().for_each(|it| it.add_to(db, module, sink)) |
233 | } | 223 | } |
234 | 224 | ||
235 | pub(crate) fn resolve_macro( | ||
236 | &self, | ||
237 | macro_call_id: MacroCallId, | ||
238 | ) -> Option<(Crate, CrateMacroId)> { | ||
239 | self.macro_resolutions.get(¯o_call_id).map(|&it| it) | ||
240 | } | ||
241 | |||
242 | pub(crate) fn find_module_by_source( | 225 | pub(crate) fn find_module_by_source( |
243 | &self, | 226 | &self, |
244 | file_id: HirFileId, | 227 | file_id: HirFileId, |
245 | decl_id: Option<SourceFileItemId>, | 228 | decl_id: Option<SourceItemId>, |
246 | ) -> Option<CrateModuleId> { | 229 | ) -> Option<CrateModuleId> { |
247 | let decl_id = decl_id.map(|it| it.with_file_id(file_id)); | ||
248 | let (module_id, _module_data) = self.modules.iter().find(|(_module_id, module_data)| { | 230 | let (module_id, _module_data) = self.modules.iter().find(|(_module_id, module_data)| { |
249 | if decl_id.is_some() { | 231 | if decl_id.is_some() { |
250 | module_data.declaration == decl_id | 232 | module_data.declaration == decl_id |