diff options
author | Seivan Heidari <[email protected]> | 2019-11-15 15:30:21 +0000 |
---|---|---|
committer | Seivan Heidari <[email protected]> | 2019-11-15 15:30:21 +0000 |
commit | cb26df950699586b314731fb70786e0db8eaa049 (patch) | |
tree | 29a1fd853757824572bfebc956d20458d827926f /crates/ra_hir_def/src/nameres.rs | |
parent | c622413bc72ea56d5f62a16788d897cb61eca948 (diff) | |
parent | c6f05abfbbfa2fd1ff06e1adeea7885151aaa768 (diff) |
Merge branch 'master' of https://github.com/rust-analyzer/rust-analyzer into feature/themes
Diffstat (limited to 'crates/ra_hir_def/src/nameres.rs')
-rw-r--r-- | crates/ra_hir_def/src/nameres.rs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index d3ecabb9b..21d5f62e0 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, 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); } } |
@@ -124,6 +124,11 @@ pub struct ModuleData { | |||
124 | pub definition: Option<FileId>, | 124 | pub definition: Option<FileId>, |
125 | } | 125 | } |
126 | 126 | ||
127 | #[derive(Default, Debug, PartialEq, Eq, Clone)] | ||
128 | pub(crate) struct Declarations { | ||
129 | fns: FxHashMap<FileAstId<ast::FnDef>, FunctionId>, | ||
130 | } | ||
131 | |||
127 | #[derive(Debug, Default, PartialEq, Eq, Clone)] | 132 | #[derive(Debug, Default, PartialEq, Eq, Clone)] |
128 | pub struct ModuleScope { | 133 | pub struct ModuleScope { |
129 | pub items: FxHashMap<Name, Resolution>, | 134 | pub items: FxHashMap<Name, Resolution>, |
@@ -258,6 +263,17 @@ impl CrateDefMap { | |||
258 | let res = self.resolve_path_fp_with_macro(db, ResolveMode::Other, original_module, path); | 263 | let res = self.resolve_path_fp_with_macro(db, ResolveMode::Other, original_module, path); |
259 | (res.resolved_def, res.segment_index) | 264 | (res.resolved_def, res.segment_index) |
260 | } | 265 | } |
266 | |||
267 | pub fn modules(&self) -> impl Iterator<Item = CrateModuleId> + '_ { | ||
268 | self.modules.iter().map(|(id, _data)| id) | ||
269 | } | ||
270 | |||
271 | pub fn modules_for_file(&self, file_id: FileId) -> impl Iterator<Item = CrateModuleId> + '_ { | ||
272 | self.modules | ||
273 | .iter() | ||
274 | .filter(move |(_id, data)| data.definition == Some(file_id)) | ||
275 | .map(|(id, _data)| id) | ||
276 | } | ||
261 | } | 277 | } |
262 | 278 | ||
263 | mod diagnostics { | 279 | mod diagnostics { |