aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/nameres.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-05-30 13:03:58 +0100
committerAleksey Kladov <[email protected]>2019-05-30 13:03:58 +0100
commit97158f5c8a6dadf3bcf28601f739ab6b7c4464aa (patch)
tree3b1fa7e454c538f767ba8dc512fe1305780902a6 /crates/ra_hir/src/nameres.rs
parent4e5b02966b068a9aecc9d47290e865b0d44ce9ce (diff)
add built-in types to scopes
Diffstat (limited to 'crates/ra_hir/src/nameres.rs')
-rw-r--r--crates/ra_hir/src/nameres.rs19
1 files changed, 15 insertions, 4 deletions
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs
index 51a7b8b95..aa26345b2 100644
--- a/crates/ra_hir/src/nameres.rs
+++ b/crates/ra_hir/src/nameres.rs
@@ -62,9 +62,10 @@ use ra_db::{FileId, Edition};
62use test_utils::tested_by; 62use test_utils::tested_by;
63use ra_syntax::ast; 63use ra_syntax::ast;
64use ra_prof::profile; 64use ra_prof::profile;
65use once_cell::sync::Lazy;
65 66
66use crate::{ 67use crate::{
67 ModuleDef, Name, Crate, Module, MacroDef, KnownName, BuiltinType, 68 ModuleDef, Name, Crate, Module, MacroDef, AsName, BuiltinType,
68 DefDatabase, Path, PathKind, HirFileId, Trait, 69 DefDatabase, Path, PathKind, HirFileId, Trait,
69 ids::MacroDefId, 70 ids::MacroDefId,
70 diagnostics::DiagnosticSink, 71 diagnostics::DiagnosticSink,
@@ -140,12 +141,22 @@ pub struct ModuleScope {
140 macros: FxHashMap<Name, MacroDef>, 141 macros: FxHashMap<Name, MacroDef>,
141} 142}
142 143
144static BUILTIN_SCOPE: Lazy<FxHashMap<Name, Resolution>> = Lazy::new(|| {
145 BuiltinType::ALL
146 .iter()
147 .map(|&(known_name, ty)| {
148 (known_name.as_name(), Resolution { def: PerNs::types(ty.into()), import: None })
149 })
150 .collect()
151});
152
143impl ModuleScope { 153impl ModuleScope {
144 pub fn entries<'a>(&'a self) -> impl Iterator<Item = (&'a Name, &'a Resolution)> + 'a { 154 pub fn entries<'a>(&'a self) -> impl Iterator<Item = (&'a Name, &'a Resolution)> + 'a {
145 self.items.iter() 155 //FIXME: shadowing
156 self.items.iter().chain(BUILTIN_SCOPE.iter())
146 } 157 }
147 pub fn get(&self, name: &Name) -> Option<&Resolution> { 158 pub fn get(&self, name: &Name) -> Option<&Resolution> {
148 self.items.get(name) 159 self.items.get(name).or_else(|| BUILTIN_SCOPE.get(name))
149 } 160 }
150 pub fn traits<'a>(&'a self) -> impl Iterator<Item = Trait> + 'a { 161 pub fn traits<'a>(&'a self) -> impl Iterator<Item = Trait> + 'a {
151 self.items.values().filter_map(|r| match r.def.take_types() { 162 self.items.values().filter_map(|r| match r.def.take_types() {
@@ -154,7 +165,7 @@ impl ModuleScope {
154 }) 165 })
155 } 166 }
156 fn get_item_or_macro(&self, name: &Name) -> Option<ItemOrMacro> { 167 fn get_item_or_macro(&self, name: &Name) -> Option<ItemOrMacro> {
157 match (self.items.get(name), self.macros.get(name)) { 168 match (self.get(name), self.macros.get(name)) {
158 (Some(item), _) if !item.def.is_none() => Some(Either::Left(item.def)), 169 (Some(item), _) if !item.def.is_none() => Some(Either::Left(item.def)),
159 (_, Some(macro_)) => Some(Either::Right(*macro_)), 170 (_, Some(macro_)) => Some(Either::Right(*macro_)),
160 _ => None, 171 _ => None,