aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-12-20 15:47:22 +0000
committerAleksey Kladov <[email protected]>2019-12-20 15:52:02 +0000
commit7adb53319d963d0a40906a6847124974da1d5183 (patch)
treea4bb71f92d6492e7826f0c54a44e09cd1647e701
parente6b1194f2f33722f0cfed32465f778b256162626 (diff)
Make items private
-rw-r--r--crates/ra_hir_def/src/item_scope.rs76
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs12
2 files changed, 42 insertions, 46 deletions
diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs
index f4fb768cd..ac56986cd 100644
--- a/crates/ra_hir_def/src/item_scope.rs
+++ b/crates/ra_hir_def/src/item_scope.rs
@@ -9,7 +9,7 @@ use crate::{per_ns::PerNs, BuiltinType, ImplId, LocalImportId, MacroDefId, Modul
9 9
10#[derive(Debug, Default, PartialEq, Eq)] 10#[derive(Debug, Default, PartialEq, Eq)]
11pub struct ItemScope { 11pub struct ItemScope {
12 pub(crate) items: FxHashMap<Name, Resolution>, 12 items: FxHashMap<Name, Resolution>,
13 pub(crate) impls: Vec<ImplId>, 13 pub(crate) impls: Vec<ImplId>,
14 /// Macros visible in current module in legacy textual scope 14 /// Macros visible in current module in legacy textual scope
15 /// 15 ///
@@ -47,41 +47,6 @@ pub(crate) enum BuiltinShadowMode {
47/// Legacy macros can only be accessed through special methods like `get_legacy_macros`. 47/// Legacy macros can only be accessed through special methods like `get_legacy_macros`.
48/// Other methods will only resolve values, types and module scoped macros only. 48/// Other methods will only resolve values, types and module scoped macros only.
49impl ItemScope { 49impl ItemScope {
50 pub fn push_res(
51 &mut self,
52 name: Name,
53 res: &Resolution,
54 import: Option<LocalImportId>,
55 ) -> bool {
56 let mut changed = false;
57 let existing = self.items.entry(name.clone()).or_default();
58
59 if existing.def.types.is_none() && res.def.types.is_some() {
60 existing.def.types = res.def.types;
61 existing.import = import.or(res.import);
62 changed = true;
63 }
64 if existing.def.values.is_none() && res.def.values.is_some() {
65 existing.def.values = res.def.values;
66 existing.import = import.or(res.import);
67 changed = true;
68 }
69 if existing.def.macros.is_none() && res.def.macros.is_some() {
70 existing.def.macros = res.def.macros;
71 existing.import = import.or(res.import);
72 changed = true;
73 }
74
75 if existing.def.is_none()
76 && res.def.is_none()
77 && existing.import.is_none()
78 && res.import.is_some()
79 {
80 existing.import = res.import;
81 }
82 changed
83 }
84
85 pub fn entries<'a>(&'a self) -> impl Iterator<Item = (&'a Name, &'a Resolution)> + 'a { 50 pub fn entries<'a>(&'a self) -> impl Iterator<Item = (&'a Name, &'a Resolution)> + 'a {
86 //FIXME: shadowing 51 //FIXME: shadowing
87 self.items.iter().chain(BUILTIN_SCOPE.iter()) 52 self.items.iter().chain(BUILTIN_SCOPE.iter())
@@ -138,6 +103,45 @@ impl ItemScope {
138 pub(crate) fn get_legacy_macro(&self, name: &Name) -> Option<MacroDefId> { 103 pub(crate) fn get_legacy_macro(&self, name: &Name) -> Option<MacroDefId> {
139 self.legacy_macros.get(name).copied() 104 self.legacy_macros.get(name).copied()
140 } 105 }
106
107 pub(crate) fn push_res(
108 &mut self,
109 name: Name,
110 res: &Resolution,
111 import: Option<LocalImportId>,
112 ) -> bool {
113 let mut changed = false;
114 let existing = self.items.entry(name.clone()).or_default();
115
116 if existing.def.types.is_none() && res.def.types.is_some() {
117 existing.def.types = res.def.types;
118 existing.import = import.or(res.import);
119 changed = true;
120 }
121 if existing.def.values.is_none() && res.def.values.is_some() {
122 existing.def.values = res.def.values;
123 existing.import = import.or(res.import);
124 changed = true;
125 }
126 if existing.def.macros.is_none() && res.def.macros.is_some() {
127 existing.def.macros = res.def.macros;
128 existing.import = import.or(res.import);
129 changed = true;
130 }
131
132 if existing.def.is_none()
133 && res.def.is_none()
134 && existing.import.is_none()
135 && res.import.is_some()
136 {
137 existing.import = res.import;
138 }
139 changed
140 }
141
142 pub(crate) fn collect_resolutions(&self) -> Vec<(Name, Resolution)> {
143 self.items.iter().map(|(name, res)| (name.clone(), res.clone())).collect()
144 }
141} 145}
142 146
143#[derive(Debug, Clone, PartialEq, Eq, Default)] 147#[derive(Debug, Clone, PartialEq, Eq, Default)]
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index 95c499ec9..d62fae8a6 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -372,11 +372,7 @@ where
372 let scope = &item_map[m.local_id].scope; 372 let scope = &item_map[m.local_id].scope;
373 373
374 // Module scoped macros is included 374 // Module scoped macros is included
375 let items = scope 375 let items = scope.collect_resolutions();
376 .items
377 .iter()
378 .map(|(name, res)| (name.clone(), res.clone()))
379 .collect::<Vec<_>>();
380 376
381 self.update(module_id, Some(import_id), &items); 377 self.update(module_id, Some(import_id), &items);
382 } else { 378 } else {
@@ -386,11 +382,7 @@ where
386 let scope = &self.def_map[m.local_id].scope; 382 let scope = &self.def_map[m.local_id].scope;
387 383
388 // Module scoped macros is included 384 // Module scoped macros is included
389 let items = scope 385 let items = scope.collect_resolutions();
390 .items
391 .iter()
392 .map(|(name, res)| (name.clone(), res.clone()))
393 .collect::<Vec<_>>();
394 386
395 self.update(module_id, Some(import_id), &items); 387 self.update(module_id, Some(import_id), &items);
396 // record the glob import in case we add further items 388 // record the glob import in case we add further items