diff options
author | Aleksey Kladov <[email protected]> | 2019-04-13 07:31:03 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-04-13 07:31:03 +0100 |
commit | 3aae223d938e5a36d997c45a0f86cfcabf83b570 (patch) | |
tree | 354c1e3c3a5e07b233c4e8490225f9be720a3315 /crates/ra_hir | |
parent | 58fe5598e70eef6edf109865cb87b806b22536fb (diff) |
hide some scopes
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/expr/scope.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 11 |
2 files changed, 16 insertions, 2 deletions
diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs index 404c979eb..a9be9fbdb 100644 --- a/crates/ra_hir/src/expr/scope.rs +++ b/crates/ra_hir/src/expr/scope.rs | |||
@@ -173,7 +173,10 @@ impl ScopesWithSourceMap { | |||
173 | .unwrap_or(original_scope) | 173 | .unwrap_or(original_scope) |
174 | } | 174 | } |
175 | 175 | ||
176 | pub fn resolve_local_name(&self, name_ref: &ast::NameRef) -> Option<ScopeEntryWithSyntax> { | 176 | pub(crate) fn resolve_local_name( |
177 | &self, | ||
178 | name_ref: &ast::NameRef, | ||
179 | ) -> Option<ScopeEntryWithSyntax> { | ||
177 | let mut shadowed = FxHashSet::default(); | 180 | let mut shadowed = FxHashSet::default(); |
178 | let name = name_ref.as_name(); | 181 | let name = name_ref.as_name(); |
179 | let ret = self | 182 | let ret = self |
@@ -190,7 +193,7 @@ impl ScopesWithSourceMap { | |||
190 | }) | 193 | }) |
191 | } | 194 | } |
192 | 195 | ||
193 | pub fn find_all_refs(&self, pat: &ast::BindPat) -> Vec<ReferenceDescriptor> { | 196 | pub(crate) fn find_all_refs(&self, pat: &ast::BindPat) -> Vec<ReferenceDescriptor> { |
194 | let fn_def = pat.syntax().ancestors().find_map(ast::FnDef::cast).unwrap(); | 197 | let fn_def = pat.syntax().ancestors().find_map(ast::FnDef::cast).unwrap(); |
195 | let ptr = Either::A(AstPtr::new(pat.into())); | 198 | let ptr = Either::A(AstPtr::new(pat.into())); |
196 | fn_def | 199 | fn_def |
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 0d2746ac0..bdb300311 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -17,6 +17,7 @@ use ra_syntax::{ | |||
17 | use crate::{ | 17 | use crate::{ |
18 | HirDatabase, Function, Struct, Enum, Const, Static, Either, DefWithBody, | 18 | HirDatabase, Function, Struct, Enum, Const, Static, Either, DefWithBody, |
19 | AsName, Module, HirFileId, Crate, Trait, Resolver, | 19 | AsName, Module, HirFileId, Crate, Trait, Resolver, |
20 | expr::scope::{ReferenceDescriptor, ScopeEntryWithSyntax}, | ||
20 | ids::LocationCtx, | 21 | ids::LocationCtx, |
21 | expr, AstId | 22 | expr, AstId |
22 | }; | 23 | }; |
@@ -222,6 +223,7 @@ pub struct SourceAnalyzer { | |||
222 | resolver: Resolver, | 223 | resolver: Resolver, |
223 | body_source_map: Option<Arc<crate::expr::BodySourceMap>>, | 224 | body_source_map: Option<Arc<crate::expr::BodySourceMap>>, |
224 | infer: Option<Arc<crate::ty::InferenceResult>>, | 225 | infer: Option<Arc<crate::ty::InferenceResult>>, |
226 | scopes: Option<crate::expr::ScopesWithSourceMap>, | ||
225 | } | 227 | } |
226 | 228 | ||
227 | #[derive(Debug, Clone, PartialEq, Eq)] | 229 | #[derive(Debug, Clone, PartialEq, Eq)] |
@@ -248,6 +250,7 @@ impl SourceAnalyzer { | |||
248 | resolver: resolver_for_node(db, file_id, node, offset), | 250 | resolver: resolver_for_node(db, file_id, node, offset), |
249 | body_source_map: def_with_body.map(|it| it.body_source_map(db)), | 251 | body_source_map: def_with_body.map(|it| it.body_source_map(db)), |
250 | infer: def_with_body.map(|it| it.infer(db)), | 252 | infer: def_with_body.map(|it| it.infer(db)), |
253 | scopes: def_with_body.map(|it| it.scopes(db)), | ||
251 | } | 254 | } |
252 | } | 255 | } |
253 | 256 | ||
@@ -302,6 +305,14 @@ impl SourceAnalyzer { | |||
302 | Some(res) | 305 | Some(res) |
303 | } | 306 | } |
304 | 307 | ||
308 | pub fn find_all_refs(&self, pat: &ast::BindPat) -> Option<Vec<ReferenceDescriptor>> { | ||
309 | self.scopes.as_ref().map(|it| it.find_all_refs(pat)) | ||
310 | } | ||
311 | |||
312 | pub fn resolve_local_name(&self, name_ref: &ast::NameRef) -> Option<ScopeEntryWithSyntax> { | ||
313 | self.scopes.as_ref()?.resolve_local_name(name_ref) | ||
314 | } | ||
315 | |||
305 | #[cfg(test)] | 316 | #[cfg(test)] |
306 | pub(crate) fn body_source_map(&self) -> Arc<crate::expr::BodySourceMap> { | 317 | pub(crate) fn body_source_map(&self) -> Arc<crate::expr::BodySourceMap> { |
307 | self.body_source_map.clone().unwrap() | 318 | self.body_source_map.clone().unwrap() |