aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/source_binder.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-15 11:53:55 +0000
committerGitHub <[email protected]>2019-11-15 11:53:55 +0000
commit04f1bd17cbedfdc89b1061376dabd52aa94cb4a9 (patch)
treeec1b28ac2a90ebbc42d88be3a79065f71ff55db9 /crates/ra_hir/src/source_binder.rs
parent3948de3143d06cc3056b6b8f0d18cb3e1468ae03 (diff)
parentc3f84960aa99529a3afc8f28c16e657fb071db5f (diff)
Merge #2257
2257: Flatten expr module r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/source_binder.rs')
-rw-r--r--crates/ra_hir/src/source_binder.rs30
1 files changed, 8 insertions, 22 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 59046edcc..662d3f880 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -19,7 +19,6 @@ use ra_syntax::{
19 SyntaxKind::*, 19 SyntaxKind::*,
20 SyntaxNode, SyntaxNodePtr, TextRange, TextUnit, 20 SyntaxNode, SyntaxNodePtr, TextRange, TextUnit,
21}; 21};
22use rustc_hash::FxHashSet;
23 22
24use crate::{ 23use crate::{
25 db::HirDatabase, 24 db::HirDatabase,
@@ -285,23 +284,15 @@ impl SourceAnalyzer {
285 self.resolve_hir_path(db, &hir_path) 284 self.resolve_hir_path(db, &hir_path)
286 } 285 }
287 286
288 pub fn resolve_local_name(&self, name_ref: &ast::NameRef) -> Option<ScopeEntryWithSyntax> { 287 fn resolve_local_name(&self, name_ref: &ast::NameRef) -> Option<ScopeEntryWithSyntax> {
289 let mut shadowed = FxHashSet::default();
290 let name = name_ref.as_name(); 288 let name = name_ref.as_name();
291 let source_map = self.body_source_map.as_ref()?; 289 let source_map = self.body_source_map.as_ref()?;
292 let scopes = self.scopes.as_ref()?; 290 let scopes = self.scopes.as_ref()?;
293 let scope = scope_for(scopes, source_map, self.file_id.into(), name_ref.syntax()); 291 let scope = scope_for(scopes, source_map, self.file_id.into(), name_ref.syntax())?;
294 let ret = scopes 292 let entry = scopes.resolve_name_in_scope(scope, &name)?;
295 .scope_chain(scope) 293 Some(ScopeEntryWithSyntax {
296 .flat_map(|scope| scopes.entries(scope).iter()) 294 name: entry.name().clone(),
297 .filter(|entry| shadowed.insert(entry.name())) 295 ptr: source_map.pat_syntax(entry.pat())?.ast,
298 .filter(|entry| entry.name() == &name)
299 .nth(0);
300 ret.and_then(|entry| {
301 Some(ScopeEntryWithSyntax {
302 name: entry.name().clone(),
303 ptr: source_map.pat_syntax(entry.pat())?.ast,
304 })
305 }) 296 })
306 } 297 }
307 298
@@ -309,9 +300,9 @@ impl SourceAnalyzer {
309 self.resolver.process_all_names(db, f) 300 self.resolver.process_all_names(db, f)
310 } 301 }
311 302
303 // FIXME: we only use this in `inline_local_variable` assist, ideally, we
304 // should switch to general reference search infra there.
312 pub fn find_all_refs(&self, pat: &ast::BindPat) -> Vec<ReferenceDescriptor> { 305 pub fn find_all_refs(&self, pat: &ast::BindPat) -> Vec<ReferenceDescriptor> {
313 // FIXME: at least, this should work with any DefWithBody, but ideally
314 // this should be hir-based altogether
315 let fn_def = pat.syntax().ancestors().find_map(ast::FnDef::cast).unwrap(); 306 let fn_def = pat.syntax().ancestors().find_map(ast::FnDef::cast).unwrap();
316 let ptr = Either::A(AstPtr::new(&ast::Pat::from(pat.clone()))); 307 let ptr = Either::A(AstPtr::new(&ast::Pat::from(pat.clone())));
317 fn_def 308 fn_def
@@ -413,11 +404,6 @@ impl SourceAnalyzer {
413 pub(crate) fn inference_result(&self) -> Arc<crate::ty::InferenceResult> { 404 pub(crate) fn inference_result(&self) -> Arc<crate::ty::InferenceResult> {
414 self.infer.clone().unwrap() 405 self.infer.clone().unwrap()
415 } 406 }
416
417 #[cfg(test)]
418 pub(crate) fn scopes(&self) -> Arc<ExprScopes> {
419 self.scopes.clone().unwrap()
420 }
421} 407}
422 408
423fn scope_for( 409fn scope_for(