From 3aae223d938e5a36d997c45a0f86cfcabf83b570 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 13 Apr 2019 09:31:03 +0300 Subject: hide some scopes --- crates/ra_hir/src/expr/scope.rs | 7 +++++-- crates/ra_hir/src/source_binder.rs | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir') 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 { .unwrap_or(original_scope) } - pub fn resolve_local_name(&self, name_ref: &ast::NameRef) -> Option { + pub(crate) fn resolve_local_name( + &self, + name_ref: &ast::NameRef, + ) -> Option { let mut shadowed = FxHashSet::default(); let name = name_ref.as_name(); let ret = self @@ -190,7 +193,7 @@ impl ScopesWithSourceMap { }) } - pub fn find_all_refs(&self, pat: &ast::BindPat) -> Vec { + pub(crate) fn find_all_refs(&self, pat: &ast::BindPat) -> Vec { let fn_def = pat.syntax().ancestors().find_map(ast::FnDef::cast).unwrap(); let ptr = Either::A(AstPtr::new(pat.into())); 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::{ use crate::{ HirDatabase, Function, Struct, Enum, Const, Static, Either, DefWithBody, AsName, Module, HirFileId, Crate, Trait, Resolver, + expr::scope::{ReferenceDescriptor, ScopeEntryWithSyntax}, ids::LocationCtx, expr, AstId }; @@ -222,6 +223,7 @@ pub struct SourceAnalyzer { resolver: Resolver, body_source_map: Option>, infer: Option>, + scopes: Option, } #[derive(Debug, Clone, PartialEq, Eq)] @@ -248,6 +250,7 @@ impl SourceAnalyzer { resolver: resolver_for_node(db, file_id, node, offset), body_source_map: def_with_body.map(|it| it.body_source_map(db)), infer: def_with_body.map(|it| it.infer(db)), + scopes: def_with_body.map(|it| it.scopes(db)), } } @@ -302,6 +305,14 @@ impl SourceAnalyzer { Some(res) } + pub fn find_all_refs(&self, pat: &ast::BindPat) -> Option> { + self.scopes.as_ref().map(|it| it.find_all_refs(pat)) + } + + pub fn resolve_local_name(&self, name_ref: &ast::NameRef) -> Option { + self.scopes.as_ref()?.resolve_local_name(name_ref) + } + #[cfg(test)] pub(crate) fn body_source_map(&self) -> Arc { self.body_source_map.clone().unwrap() -- cgit v1.2.3