aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-03-04 13:25:22 +0000
committerAleksey Kladov <[email protected]>2020-03-04 13:25:22 +0000
commitf57682c0b3b17a09d728c77134200b4151b2358d (patch)
tree4f14fda3b2ef64d7fe945a493f4f64c1696ef2cc /crates/ra_hir
parent94189d0a1c8cf24b155fe7bad9b159bc17e997bb (diff)
Remove old find refs infra
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/semantics.rs8
-rw-r--r--crates/ra_hir/src/source_analyzer.rs35
2 files changed, 2 insertions, 41 deletions
diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs
index afc7f7ee7..7ce785791 100644
--- a/crates/ra_hir/src/semantics.rs
+++ b/crates/ra_hir/src/semantics.rs
@@ -19,7 +19,7 @@ use rustc_hash::{FxHashMap, FxHashSet};
19use crate::{ 19use crate::{
20 db::HirDatabase, 20 db::HirDatabase,
21 semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx}, 21 semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx},
22 source_analyzer::{resolve_hir_path, ReferenceDescriptor, SourceAnalyzer}, 22 source_analyzer::{resolve_hir_path, SourceAnalyzer},
23 Function, HirFileId, InFile, Local, MacroDef, Module, ModuleDef, Name, Origin, Path, 23 Function, HirFileId, InFile, Local, MacroDef, Module, ModuleDef, Name, Origin, Path,
24 PathResolution, ScopeDef, StructField, Trait, Type, TypeParam, VariantDef, 24 PathResolution, ScopeDef, StructField, Trait, Type, TypeParam, VariantDef,
25}; 25};
@@ -171,12 +171,6 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
171 SemanticsScope { db: self.db, resolver } 171 SemanticsScope { db: self.db, resolver }
172 } 172 }
173 173
174 // FIXME: we only use this in `inline_local_variable` assist, ideally, we
175 // should switch to general reference search infra there.
176 pub fn find_all_refs(&self, pat: &ast::BindPat) -> Vec<ReferenceDescriptor> {
177 self.analyze(pat.syntax()).find_all_refs(pat)
178 }
179
180 fn analyze(&self, node: &SyntaxNode) -> SourceAnalyzer { 174 fn analyze(&self, node: &SyntaxNode) -> SourceAnalyzer {
181 let src = self.find_file(node.clone()); 175 let src = self.find_file(node.clone());
182 self.analyze2(src.as_ref(), None) 176 self.analyze2(src.as_ref(), None)
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,