diff options
Diffstat (limited to 'crates/ra_hir_def/src/nameres.rs')
-rw-r--r-- | crates/ra_hir_def/src/nameres.rs | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index d3ecabb9b..49e33ccc4 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs | |||
@@ -58,7 +58,7 @@ mod tests; | |||
58 | 58 | ||
59 | use std::sync::Arc; | 59 | use std::sync::Arc; |
60 | 60 | ||
61 | use hir_expand::{diagnostics::DiagnosticSink, name::Name, MacroDefId}; | 61 | use hir_expand::{ast_id_map::FileAstId, diagnostics::DiagnosticSink, name::Name, MacroDefId}; |
62 | use once_cell::sync::Lazy; | 62 | use once_cell::sync::Lazy; |
63 | use ra_arena::Arena; | 63 | use ra_arena::Arena; |
64 | use ra_db::{CrateId, Edition, FileId}; | 64 | use ra_db::{CrateId, Edition, FileId}; |
@@ -73,7 +73,7 @@ use crate::{ | |||
73 | diagnostics::DefDiagnostic, path_resolution::ResolveMode, per_ns::PerNs, raw::ImportId, | 73 | diagnostics::DefDiagnostic, path_resolution::ResolveMode, per_ns::PerNs, raw::ImportId, |
74 | }, | 74 | }, |
75 | path::Path, | 75 | path::Path, |
76 | AstId, CrateModuleId, ModuleDefId, ModuleId, TraitId, | 76 | AstId, CrateModuleId, FunctionId, ImplId, ModuleDefId, ModuleId, TraitId, |
77 | }; | 77 | }; |
78 | 78 | ||
79 | /// Contains all top-level defs from a macro-expanded crate | 79 | /// Contains all top-level defs from a macro-expanded crate |
@@ -87,7 +87,7 @@ pub struct CrateDefMap { | |||
87 | prelude: Option<ModuleId>, | 87 | prelude: Option<ModuleId>, |
88 | extern_prelude: FxHashMap<Name, ModuleDefId>, | 88 | extern_prelude: FxHashMap<Name, ModuleDefId>, |
89 | root: CrateModuleId, | 89 | root: CrateModuleId, |
90 | pub modules: Arena<CrateModuleId, ModuleData>, | 90 | modules: Arena<CrateModuleId, ModuleData>, |
91 | 91 | ||
92 | /// Some macros are not well-behavior, which leads to infinite loop | 92 | /// Some macros are not well-behavior, which leads to infinite loop |
93 | /// e.g. macro_rules! foo { ($ty:ty) => { foo!($ty); } } | 93 | /// e.g. macro_rules! foo { ($ty:ty) => { foo!($ty); } } |
@@ -122,11 +122,17 @@ pub struct ModuleData { | |||
122 | /// | 122 | /// |
123 | /// Note that non-inline modules, by definition, live inside non-macro file. | 123 | /// Note that non-inline modules, by definition, live inside non-macro file. |
124 | pub definition: Option<FileId>, | 124 | pub definition: Option<FileId>, |
125 | pub impls: Vec<ImplId>, | ||
126 | } | ||
127 | |||
128 | #[derive(Default, Debug, PartialEq, Eq, Clone)] | ||
129 | pub(crate) struct Declarations { | ||
130 | fns: FxHashMap<FileAstId<ast::FnDef>, FunctionId>, | ||
125 | } | 131 | } |
126 | 132 | ||
127 | #[derive(Debug, Default, PartialEq, Eq, Clone)] | 133 | #[derive(Debug, Default, PartialEq, Eq, Clone)] |
128 | pub struct ModuleScope { | 134 | pub struct ModuleScope { |
129 | pub items: FxHashMap<Name, Resolution>, | 135 | items: FxHashMap<Name, Resolution>, |
130 | /// Macros visable in current module in legacy textual scope | 136 | /// Macros visable in current module in legacy textual scope |
131 | /// | 137 | /// |
132 | /// For macros invoked by an unquatified identifier like `bar!()`, `legacy_macros` will be searched in first. | 138 | /// For macros invoked by an unquatified identifier like `bar!()`, `legacy_macros` will be searched in first. |
@@ -258,6 +264,17 @@ impl CrateDefMap { | |||
258 | let res = self.resolve_path_fp_with_macro(db, ResolveMode::Other, original_module, path); | 264 | let res = self.resolve_path_fp_with_macro(db, ResolveMode::Other, original_module, path); |
259 | (res.resolved_def, res.segment_index) | 265 | (res.resolved_def, res.segment_index) |
260 | } | 266 | } |
267 | |||
268 | pub fn modules(&self) -> impl Iterator<Item = CrateModuleId> + '_ { | ||
269 | self.modules.iter().map(|(id, _data)| id) | ||
270 | } | ||
271 | |||
272 | pub fn modules_for_file(&self, file_id: FileId) -> impl Iterator<Item = CrateModuleId> + '_ { | ||
273 | self.modules | ||
274 | .iter() | ||
275 | .filter(move |(_id, data)| data.definition == Some(file_id)) | ||
276 | .map(|(id, _data)| id) | ||
277 | } | ||
261 | } | 278 | } |
262 | 279 | ||
263 | mod diagnostics { | 280 | mod diagnostics { |