aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/nameres.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/nameres.rs')
-rw-r--r--crates/ra_hir_def/src/nameres.rs35
1 files changed, 11 insertions, 24 deletions
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs
index 3b2e99647..f6cf59c5f 100644
--- a/crates/ra_hir_def/src/nameres.rs
+++ b/crates/ra_hir_def/src/nameres.rs
@@ -66,7 +66,7 @@ use ra_arena::Arena;
66use ra_db::{CrateId, Edition, FileId}; 66use ra_db::{CrateId, Edition, FileId};
67use ra_prof::profile; 67use ra_prof::profile;
68use ra_syntax::ast; 68use ra_syntax::ast;
69use rustc_hash::{FxHashMap, FxHashSet}; 69use rustc_hash::FxHashMap;
70 70
71use crate::{ 71use crate::{
72 builtin_type::BuiltinType, 72 builtin_type::BuiltinType,
@@ -90,18 +90,6 @@ pub struct CrateDefMap {
90 root: LocalModuleId, 90 root: LocalModuleId,
91 modules: Arena<LocalModuleId, ModuleData>, 91 modules: Arena<LocalModuleId, ModuleData>,
92 92
93 /// Some macros are not well-behavior, which leads to infinite loop
94 /// e.g. macro_rules! foo { ($ty:ty) => { foo!($ty); } }
95 /// We mark it down and skip it in collector
96 ///
97 /// FIXME:
98 /// Right now it only handle a poison macro in a single crate,
99 /// such that if other crate try to call that macro,
100 /// the whole process will do again until it became poisoned in that crate.
101 /// We should handle this macro set globally
102 /// However, do we want to put it as a global variable?
103 poison_macros: FxHashSet<MacroDefId>,
104
105 diagnostics: Vec<DefDiagnostic>, 93 diagnostics: Vec<DefDiagnostic>,
106} 94}
107 95
@@ -234,7 +222,6 @@ impl CrateDefMap {
234 prelude: None, 222 prelude: None,
235 root, 223 root,
236 modules, 224 modules,
237 poison_macros: FxHashSet::default(),
238 diagnostics: Vec::new(), 225 diagnostics: Vec::new(),
239 } 226 }
240 }; 227 };
@@ -267,16 +254,6 @@ impl CrateDefMap {
267 self.diagnostics.iter().for_each(|it| it.add_to(db, module, sink)) 254 self.diagnostics.iter().for_each(|it| it.add_to(db, module, sink))
268 } 255 }
269 256
270 pub fn resolve_path(
271 &self,
272 db: &impl DefDatabase,
273 original_module: LocalModuleId,
274 path: &Path,
275 ) -> (PerNs, Option<usize>) {
276 let res = self.resolve_path_fp_with_macro(db, ResolveMode::Other, original_module, path);
277 (res.resolved_def, res.segment_index)
278 }
279
280 pub fn modules(&self) -> impl Iterator<Item = LocalModuleId> + '_ { 257 pub fn modules(&self) -> impl Iterator<Item = LocalModuleId> + '_ {
281 self.modules.iter().map(|(id, _data)| id) 258 self.modules.iter().map(|(id, _data)| id)
282 } 259 }
@@ -287,6 +264,16 @@ impl CrateDefMap {
287 .filter(move |(_id, data)| data.definition == Some(file_id)) 264 .filter(move |(_id, data)| data.definition == Some(file_id))
288 .map(|(id, _data)| id) 265 .map(|(id, _data)| id)
289 } 266 }
267
268 pub(crate) fn resolve_path(
269 &self,
270 db: &impl DefDatabase,
271 original_module: LocalModuleId,
272 path: &Path,
273 ) -> (PerNs, Option<usize>) {
274 let res = self.resolve_path_fp_with_macro(db, ResolveMode::Other, original_module, path);
275 (res.resolved_def, res.segment_index)
276 }
290} 277}
291 278
292impl ModuleData { 279impl ModuleData {