diff options
Diffstat (limited to 'crates/ra_analysis/src/hir/mod.rs')
-rw-r--r-- | crates/ra_analysis/src/hir/mod.rs | 53 |
1 files changed, 0 insertions, 53 deletions
diff --git a/crates/ra_analysis/src/hir/mod.rs b/crates/ra_analysis/src/hir/mod.rs index 5a9086cef..e234173a9 100644 --- a/crates/ra_analysis/src/hir/mod.rs +++ b/crates/ra_analysis/src/hir/mod.rs | |||
@@ -11,15 +11,9 @@ mod function; | |||
11 | mod module; | 11 | mod module; |
12 | mod path; | 12 | mod path; |
13 | 13 | ||
14 | use ra_syntax::{ | ||
15 | ast::{self, AstNode}, | ||
16 | TextRange, | ||
17 | }; | ||
18 | |||
19 | use crate::{ | 14 | use crate::{ |
20 | hir::db::HirDatabase, | 15 | hir::db::HirDatabase, |
21 | loc2id::{DefId, DefLoc}, | 16 | loc2id::{DefId, DefLoc}, |
22 | syntax_ptr::LocalSyntaxPtr, | ||
23 | Cancelable, | 17 | Cancelable, |
24 | }; | 18 | }; |
25 | 19 | ||
@@ -49,50 +43,3 @@ impl DefId { | |||
49 | Ok(res) | 43 | Ok(res) |
50 | } | 44 | } |
51 | } | 45 | } |
52 | |||
53 | #[derive(Debug)] | ||
54 | pub struct ReferenceDescriptor { | ||
55 | pub range: TextRange, | ||
56 | pub name: String, | ||
57 | } | ||
58 | |||
59 | #[derive(Debug)] | ||
60 | pub struct DeclarationDescriptor<'a> { | ||
61 | pat: ast::BindPat<'a>, | ||
62 | pub range: TextRange, | ||
63 | } | ||
64 | |||
65 | impl<'a> DeclarationDescriptor<'a> { | ||
66 | pub fn new(pat: ast::BindPat) -> DeclarationDescriptor { | ||
67 | let range = pat.syntax().range(); | ||
68 | |||
69 | DeclarationDescriptor { pat, range } | ||
70 | } | ||
71 | |||
72 | pub fn find_all_refs(&self) -> Vec<ReferenceDescriptor> { | ||
73 | let name_ptr = LocalSyntaxPtr::new(self.pat.syntax()); | ||
74 | |||
75 | let fn_def = match self.pat.syntax().ancestors().find_map(ast::FnDef::cast) { | ||
76 | Some(def) => def, | ||
77 | None => return Default::default(), | ||
78 | }; | ||
79 | |||
80 | let fn_scopes = FnScopes::new(fn_def); | ||
81 | |||
82 | let refs: Vec<_> = fn_def | ||
83 | .syntax() | ||
84 | .descendants() | ||
85 | .filter_map(ast::NameRef::cast) | ||
86 | .filter(|name_ref| match fn_scopes.resolve_local_name(*name_ref) { | ||
87 | None => false, | ||
88 | Some(entry) => entry.ptr() == name_ptr, | ||
89 | }) | ||
90 | .map(|name_ref| ReferenceDescriptor { | ||
91 | name: name_ref.syntax().text().to_string(), | ||
92 | range: name_ref.syntax().range(), | ||
93 | }) | ||
94 | .collect(); | ||
95 | |||
96 | refs | ||
97 | } | ||
98 | } | ||