aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/source_analyzer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/source_analyzer.rs')
-rw-r--r--crates/ra_hir/src/source_analyzer.rs35
1 files changed, 1 insertions, 34 deletions
diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs
index 015389fb0..73cff17c9 100644
--- a/crates/ra_hir/src/source_analyzer.rs
+++ b/crates/ra_hir/src/source_analyzer.rs
@@ -7,7 +7,6 @@
7//! purely for "IDE needs". 7//! purely for "IDE needs".
8use std::{iter::once, sync::Arc}; 8use std::{iter::once, sync::Arc};
9 9
10use either::Either;
11use hir_def::{ 10use hir_def::{
12 body::{ 11 body::{
13 scope::{ExprScopes, ScopeId}, 12 scope::{ExprScopes, ScopeId},
@@ -21,7 +20,7 @@ use hir_expand::{hygiene::Hygiene, name::AsName, HirFileId, InFile};
21use hir_ty::{InEnvironment, InferenceResult, TraitEnvironment}; 20use hir_ty::{InEnvironment, InferenceResult, TraitEnvironment};
22use ra_syntax::{ 21use ra_syntax::{
23 ast::{self, AstNode}, 22 ast::{self, AstNode},
24 AstPtr, SyntaxNode, SyntaxNodePtr, TextRange, TextUnit, 23 SyntaxNode, SyntaxNodePtr, TextRange, TextUnit,
25}; 24};
26 25
27use crate::{ 26use crate::{
@@ -251,38 +250,6 @@ impl SourceAnalyzer {
251 resolve_hir_path(db, &self.resolver, &hir_path) 250 resolve_hir_path(db, &self.resolver, &hir_path)
252 } 251 }
253 252
254 fn resolve_local_name(
255 &self,
256 name_ref: &ast::NameRef,
257 ) -> Option<Either<AstPtr<ast::Pat>, AstPtr<ast::SelfParam>>> {
258 let name = name_ref.as_name();
259 let source_map = self.body_source_map.as_ref()?;
260 let scopes = self.scopes.as_ref()?;
261 let scope = scope_for(scopes, source_map, InFile::new(self.file_id, name_ref.syntax()))?;
262 let entry = scopes.resolve_name_in_scope(scope, &name)?;
263 Some(source_map.pat_syntax(entry.pat())?.value)
264 }
265
266 // FIXME: we only use this in `inline_local_variable` assist, ideally, we
267 // should switch to general reference search infra there.
268 pub(crate) fn find_all_refs(&self, pat: &ast::BindPat) -> Vec<ReferenceDescriptor> {
269 let fn_def = pat.syntax().ancestors().find_map(ast::FnDef::cast).unwrap();
270 let ptr = Either::Left(AstPtr::new(&ast::Pat::from(pat.clone())));
271 fn_def
272 .syntax()
273 .descendants()
274 .filter_map(ast::NameRef::cast)
275 .filter(|name_ref| match self.resolve_local_name(&name_ref) {
276 None => false,
277 Some(d_ptr) => d_ptr == ptr,
278 })
279 .map(|name_ref| ReferenceDescriptor {
280 name: name_ref.text().to_string(),
281 range: name_ref.syntax().text_range(),
282 })
283 .collect()
284 }
285
286 pub(crate) fn expand( 253 pub(crate) fn expand(
287 &self, 254 &self,
288 db: &impl HirDatabase, 255 db: &impl HirDatabase,