diff options
author | Paul Daniel Faria <[email protected]> | 2020-06-25 17:42:12 +0100 |
---|---|---|
committer | Paul Daniel Faria <[email protected]> | 2020-06-25 17:42:12 +0100 |
commit | de9e964e4ac21897bd48adbe37f379d74422919f (patch) | |
tree | 75749d75444e360b89b3161623934e2f255ff643 /crates/ra_hir_def/src/nameres | |
parent | 0b657ddbfe9754afce9811c70a4e61e4ea9efeaf (diff) |
Track import type outside of , use enum rather than bool to improve readability
Diffstat (limited to 'crates/ra_hir_def/src/nameres')
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 93f58e2c7..f7b99e0be 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -20,6 +20,7 @@ use test_utils::mark; | |||
20 | use crate::{ | 20 | use crate::{ |
21 | attr::Attrs, | 21 | attr::Attrs, |
22 | db::DefDatabase, | 22 | db::DefDatabase, |
23 | item_scope::ImportType, | ||
23 | item_tree::{ | 24 | item_tree::{ |
24 | self, FileItemTreeId, ItemTree, ItemTreeId, MacroCall, Mod, ModItem, ModKind, StructDefKind, | 25 | self, FileItemTreeId, ItemTree, ItemTreeId, MacroCall, Mod, ModItem, ModKind, StructDefKind, |
25 | }, | 26 | }, |
@@ -80,6 +81,7 @@ pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: CrateDefMap) -> Cr | |||
80 | mod_dirs: FxHashMap::default(), | 81 | mod_dirs: FxHashMap::default(), |
81 | cfg_options, | 82 | cfg_options, |
82 | proc_macros, | 83 | proc_macros, |
84 | import_types: FxHashMap::default(), | ||
83 | }; | 85 | }; |
84 | collector.collect(); | 86 | collector.collect(); |
85 | collector.finish() | 87 | collector.finish() |
@@ -186,6 +188,7 @@ struct DefCollector<'a> { | |||
186 | mod_dirs: FxHashMap<LocalModuleId, ModDir>, | 188 | mod_dirs: FxHashMap<LocalModuleId, ModDir>, |
187 | cfg_options: &'a CfgOptions, | 189 | cfg_options: &'a CfgOptions, |
188 | proc_macros: Vec<(Name, ProcMacroExpander)>, | 190 | proc_macros: Vec<(Name, ProcMacroExpander)>, |
191 | import_types: FxHashMap<Name, ImportType>, | ||
189 | } | 192 | } |
190 | 193 | ||
191 | impl DefCollector<'_> { | 194 | impl DefCollector<'_> { |
@@ -305,7 +308,7 @@ impl DefCollector<'_> { | |||
305 | self.def_map.root, | 308 | self.def_map.root, |
306 | &[(name, PerNs::macros(macro_, Visibility::Public))], | 309 | &[(name, PerNs::macros(macro_, Visibility::Public))], |
307 | Visibility::Public, | 310 | Visibility::Public, |
308 | false, | 311 | ImportType::Named, |
309 | ); | 312 | ); |
310 | } | 313 | } |
311 | } | 314 | } |
@@ -331,7 +334,7 @@ impl DefCollector<'_> { | |||
331 | self.def_map.root, | 334 | self.def_map.root, |
332 | &[(name, PerNs::macros(macro_, Visibility::Public))], | 335 | &[(name, PerNs::macros(macro_, Visibility::Public))], |
333 | Visibility::Public, | 336 | Visibility::Public, |
334 | false, | 337 | ImportType::Named, |
335 | ); | 338 | ); |
336 | } | 339 | } |
337 | 340 | ||
@@ -478,7 +481,7 @@ impl DefCollector<'_> { | |||
478 | .filter(|(_, res)| !res.is_none()) | 481 | .filter(|(_, res)| !res.is_none()) |
479 | .collect::<Vec<_>>(); | 482 | .collect::<Vec<_>>(); |
480 | 483 | ||
481 | self.update(module_id, &items, vis, true); | 484 | self.update(module_id, &items, vis, ImportType::Glob); |
482 | } else { | 485 | } else { |
483 | // glob import from same crate => we do an initial | 486 | // glob import from same crate => we do an initial |
484 | // import, and then need to propagate any further | 487 | // import, and then need to propagate any further |
@@ -500,7 +503,7 @@ impl DefCollector<'_> { | |||
500 | .filter(|(_, res)| !res.is_none()) | 503 | .filter(|(_, res)| !res.is_none()) |
501 | .collect::<Vec<_>>(); | 504 | .collect::<Vec<_>>(); |
502 | 505 | ||
503 | self.update(module_id, &items, vis, true); | 506 | self.update(module_id, &items, vis, ImportType::Glob); |
504 | // record the glob import in case we add further items | 507 | // record the glob import in case we add further items |
505 | let glob = self.glob_imports.entry(m.local_id).or_default(); | 508 | let glob = self.glob_imports.entry(m.local_id).or_default(); |
506 | if !glob.iter().any(|(mid, _)| *mid == module_id) { | 509 | if !glob.iter().any(|(mid, _)| *mid == module_id) { |
@@ -530,7 +533,7 @@ impl DefCollector<'_> { | |||
530 | (name, res) | 533 | (name, res) |
531 | }) | 534 | }) |
532 | .collect::<Vec<_>>(); | 535 | .collect::<Vec<_>>(); |
533 | self.update(module_id, &resolutions, vis, true); | 536 | self.update(module_id, &resolutions, vis, ImportType::Glob); |
534 | } | 537 | } |
535 | Some(d) => { | 538 | Some(d) => { |
536 | log::debug!("glob import {:?} from non-module/enum {:?}", import, d); | 539 | log::debug!("glob import {:?} from non-module/enum {:?}", import, d); |
@@ -556,7 +559,7 @@ impl DefCollector<'_> { | |||
556 | } | 559 | } |
557 | } | 560 | } |
558 | 561 | ||
559 | self.update(module_id, &[(name, def)], vis, false); | 562 | self.update(module_id, &[(name, def)], vis, ImportType::Named); |
560 | } | 563 | } |
561 | None => mark::hit!(bogus_paths), | 564 | None => mark::hit!(bogus_paths), |
562 | } | 565 | } |
@@ -568,9 +571,9 @@ impl DefCollector<'_> { | |||
568 | module_id: LocalModuleId, | 571 | module_id: LocalModuleId, |
569 | resolutions: &[(Name, PerNs)], | 572 | resolutions: &[(Name, PerNs)], |
570 | vis: Visibility, | 573 | vis: Visibility, |
571 | is_from_glob: bool, | 574 | import_type: ImportType, |
572 | ) { | 575 | ) { |
573 | self.update_recursive(module_id, resolutions, vis, is_from_glob, 0) | 576 | self.update_recursive(module_id, resolutions, vis, import_type, 0) |
574 | } | 577 | } |
575 | 578 | ||
576 | fn update_recursive( | 579 | fn update_recursive( |
@@ -582,7 +585,7 @@ impl DefCollector<'_> { | |||
582 | vis: Visibility, | 585 | vis: Visibility, |
583 | // All resolutions are imported with this glob status; the glob status | 586 | // All resolutions are imported with this glob status; the glob status |
584 | // in the `PerNs` values are ignored and overwritten | 587 | // in the `PerNs` values are ignored and overwritten |
585 | is_from_glob: bool, | 588 | import_type: ImportType, |
586 | depth: usize, | 589 | depth: usize, |
587 | ) { | 590 | ) { |
588 | if depth > 100 { | 591 | if depth > 100 { |
@@ -592,8 +595,12 @@ impl DefCollector<'_> { | |||
592 | let scope = &mut self.def_map.modules[module_id].scope; | 595 | let scope = &mut self.def_map.modules[module_id].scope; |
593 | let mut changed = false; | 596 | let mut changed = false; |
594 | for (name, res) in resolutions { | 597 | for (name, res) in resolutions { |
595 | changed |= | 598 | changed |= scope.push_res( |
596 | scope.push_res(name.clone(), res.with_visibility(vis).from_glob(is_from_glob)); | 599 | &mut self.import_types, |
600 | name.clone(), | ||
601 | res.with_visibility(vis), | ||
602 | import_type, | ||
603 | ); | ||
597 | } | 604 | } |
598 | 605 | ||
599 | if !changed { | 606 | if !changed { |
@@ -616,7 +623,7 @@ impl DefCollector<'_> { | |||
616 | glob_importing_module, | 623 | glob_importing_module, |
617 | resolutions, | 624 | resolutions, |
618 | glob_import_vis, | 625 | glob_import_vis, |
619 | true, | 626 | ImportType::Glob, |
620 | depth + 1, | 627 | depth + 1, |
621 | ); | 628 | ); |
622 | } | 629 | } |
@@ -940,7 +947,7 @@ impl ModCollector<'_, '_> { | |||
940 | self.module_id, | 947 | self.module_id, |
941 | &[(name.clone(), PerNs::from_def(id, vis, has_constructor))], | 948 | &[(name.clone(), PerNs::from_def(id, vis, has_constructor))], |
942 | vis, | 949 | vis, |
943 | false, | 950 | ImportType::Named, |
944 | ) | 951 | ) |
945 | } | 952 | } |
946 | } | 953 | } |
@@ -1047,7 +1054,7 @@ impl ModCollector<'_, '_> { | |||
1047 | self.module_id, | 1054 | self.module_id, |
1048 | &[(name, PerNs::from_def(def, vis, false))], | 1055 | &[(name, PerNs::from_def(def, vis, false))], |
1049 | vis, | 1056 | vis, |
1050 | false, | 1057 | ImportType::Named, |
1051 | ); | 1058 | ); |
1052 | res | 1059 | res |
1053 | } | 1060 | } |
@@ -1177,6 +1184,7 @@ mod tests { | |||
1177 | mod_dirs: FxHashMap::default(), | 1184 | mod_dirs: FxHashMap::default(), |
1178 | cfg_options: &CfgOptions::default(), | 1185 | cfg_options: &CfgOptions::default(), |
1179 | proc_macros: Default::default(), | 1186 | proc_macros: Default::default(), |
1187 | import_types: FxHashMap::default(), | ||
1180 | }; | 1188 | }; |
1181 | collector.collect(); | 1189 | collector.collect(); |
1182 | collector.def_map | 1190 | collector.def_map |