aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/item_scope.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-12-22 21:42:54 +0000
committerGitHub <[email protected]>2019-12-22 21:42:54 +0000
commit60aa4d12f95477565d5b01f122d2c9dd845015b4 (patch)
tree86f6d29653ba7e548f2a321b2ecdb20e7dc366f4 /crates/ra_hir_def/src/item_scope.rs
parent78f7683b9a1c6192b4828ceedb14ed498b241263 (diff)
parente424545c0f5cbaf135c52764169ea20df7d07d35 (diff)
Merge #2648
2648: Rudimentary name resolution for local items r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir_def/src/item_scope.rs')
-rw-r--r--crates/ra_hir_def/src/item_scope.rs27
1 files changed, 21 insertions, 6 deletions
diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs
index f1adc3b58..b0288ee8d 100644
--- a/crates/ra_hir_def/src/item_scope.rs
+++ b/crates/ra_hir_def/src/item_scope.rs
@@ -51,6 +51,12 @@ impl ItemScope {
51 self.visible.iter().chain(BUILTIN_SCOPE.iter()).map(|(n, def)| (n, *def)) 51 self.visible.iter().chain(BUILTIN_SCOPE.iter()).map(|(n, def)| (n, *def))
52 } 52 }
53 53
54 pub fn entries_without_primitives<'a>(
55 &'a self,
56 ) -> impl Iterator<Item = (&'a Name, PerNs)> + 'a {
57 self.visible.iter().map(|(n, def)| (n, *def))
58 }
59
54 pub fn declarations(&self) -> impl Iterator<Item = ModuleDefId> + '_ { 60 pub fn declarations(&self) -> impl Iterator<Item = ModuleDefId> + '_ {
55 self.defs.iter().copied() 61 self.defs.iter().copied()
56 } 62 }
@@ -70,18 +76,27 @@ impl ItemScope {
70 } 76 }
71 77
72 /// Get a name from current module scope, legacy macros are not included 78 /// Get a name from current module scope, legacy macros are not included
73 pub(crate) fn get(&self, name: &Name, shadow: BuiltinShadowMode) -> Option<&PerNs> { 79 pub(crate) fn get(&self, name: &Name, shadow: BuiltinShadowMode) -> PerNs {
74 match shadow { 80 match shadow {
75 BuiltinShadowMode::Module => self.visible.get(name).or_else(|| BUILTIN_SCOPE.get(name)), 81 BuiltinShadowMode::Module => self
82 .visible
83 .get(name)
84 .or_else(|| BUILTIN_SCOPE.get(name))
85 .copied()
86 .unwrap_or_else(PerNs::none),
76 BuiltinShadowMode::Other => { 87 BuiltinShadowMode::Other => {
77 let item = self.visible.get(name); 88 let item = self.visible.get(name).copied();
78 if let Some(def) = item { 89 if let Some(def) = item {
79 if let Some(ModuleDefId::ModuleId(_)) = def.take_types() { 90 if let Some(ModuleDefId::ModuleId(_)) = def.take_types() {
80 return BUILTIN_SCOPE.get(name).or(item); 91 return BUILTIN_SCOPE
92 .get(name)
93 .copied()
94 .or(item)
95 .unwrap_or_else(PerNs::none);
81 } 96 }
82 } 97 }
83 98
84 item.or_else(|| BUILTIN_SCOPE.get(name)) 99 item.or_else(|| BUILTIN_SCOPE.get(name).copied()).unwrap_or_else(PerNs::none)
85 } 100 }
86 } 101 }
87 } 102 }
@@ -109,7 +124,7 @@ impl ItemScope {
109 self.legacy_macros.insert(name, mac); 124 self.legacy_macros.insert(name, mac);
110 } 125 }
111 126
112 pub(crate) fn push_res(&mut self, name: Name, def: &PerNs) -> bool { 127 pub(crate) fn push_res(&mut self, name: Name, def: PerNs) -> bool {
113 let mut changed = false; 128 let mut changed = false;
114 let existing = self.visible.entry(name.clone()).or_default(); 129 let existing = self.visible.entry(name.clone()).or_default();
115 130