aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/source_binder.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/source_binder.rs')
-rw-r--r--crates/ra_hir/src/source_binder.rs38
1 files changed, 8 insertions, 30 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index ca40e3b54..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,
@@ -195,14 +194,6 @@ impl SourceAnalyzer {
195 Some(self.infer.as_ref()?[pat_id].clone()) 194 Some(self.infer.as_ref()?[pat_id].clone())
196 } 195 }
197 196
198 pub fn type_of_pat_by_id(
199 &self,
200 _db: &impl HirDatabase,
201 pat_id: expr::PatId,
202 ) -> Option<crate::Ty> {
203 Some(self.infer.as_ref()?[pat_id].clone())
204 }
205
206 pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> { 197 pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> {
207 let expr_id = self.expr_id(&call.clone().into())?; 198 let expr_id = self.expr_id(&call.clone().into())?;
208 self.infer.as_ref()?.method_resolution(expr_id) 199 self.infer.as_ref()?.method_resolution(expr_id)
@@ -293,23 +284,15 @@ impl SourceAnalyzer {
293 self.resolve_hir_path(db, &hir_path) 284 self.resolve_hir_path(db, &hir_path)
294 } 285 }
295 286
296 pub fn resolve_local_name(&self, name_ref: &ast::NameRef) -> Option<ScopeEntryWithSyntax> { 287 fn resolve_local_name(&self, name_ref: &ast::NameRef) -> Option<ScopeEntryWithSyntax> {
297 let mut shadowed = FxHashSet::default();
298 let name = name_ref.as_name(); 288 let name = name_ref.as_name();
299 let source_map = self.body_source_map.as_ref()?; 289 let source_map = self.body_source_map.as_ref()?;
300 let scopes = self.scopes.as_ref()?; 290 let scopes = self.scopes.as_ref()?;
301 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())?;
302 let ret = scopes 292 let entry = scopes.resolve_name_in_scope(scope, &name)?;
303 .scope_chain(scope) 293 Some(ScopeEntryWithSyntax {
304 .flat_map(|scope| scopes.entries(scope).iter()) 294 name: entry.name().clone(),
305 .filter(|entry| shadowed.insert(entry.name())) 295 ptr: source_map.pat_syntax(entry.pat())?.ast,
306 .filter(|entry| entry.name() == &name)
307 .nth(0);
308 ret.and_then(|entry| {
309 Some(ScopeEntryWithSyntax {
310 name: entry.name().clone(),
311 ptr: source_map.pat_syntax(entry.pat())?.ast,
312 })
313 }) 296 })
314 } 297 }
315 298
@@ -317,9 +300,9 @@ impl SourceAnalyzer {
317 self.resolver.process_all_names(db, f) 300 self.resolver.process_all_names(db, f)
318 } 301 }
319 302
303 // FIXME: we only use this in `inline_local_variable` assist, ideally, we
304 // should switch to general reference search infra there.
320 pub fn find_all_refs(&self, pat: &ast::BindPat) -> Vec<ReferenceDescriptor> { 305 pub fn find_all_refs(&self, pat: &ast::BindPat) -> Vec<ReferenceDescriptor> {
321 // FIXME: at least, this should work with any DefWithBody, but ideally
322 // this should be hir-based altogether
323 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();
324 let ptr = Either::A(AstPtr::new(&ast::Pat::from(pat.clone()))); 307 let ptr = Either::A(AstPtr::new(&ast::Pat::from(pat.clone())));
325 fn_def 308 fn_def
@@ -421,11 +404,6 @@ impl SourceAnalyzer {
421 pub(crate) fn inference_result(&self) -> Arc<crate::ty::InferenceResult> { 404 pub(crate) fn inference_result(&self) -> Arc<crate::ty::InferenceResult> {
422 self.infer.clone().unwrap() 405 self.infer.clone().unwrap()
423 } 406 }
424
425 #[cfg(test)]
426 pub(crate) fn scopes(&self) -> Arc<ExprScopes> {
427 self.scopes.clone().unwrap()
428 }
429} 407}
430 408
431fn scope_for( 409fn scope_for(