diff options
Diffstat (limited to 'crates/ra_hir/src/source_binder.rs')
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 8d53079c6..bd035ced9 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -10,7 +10,7 @@ use std::sync::Arc; | |||
10 | use rustc_hash::{FxHashSet, FxHashMap}; | 10 | use rustc_hash::{FxHashSet, FxHashMap}; |
11 | use ra_db::{FileId, FilePosition}; | 11 | use ra_db::{FileId, FilePosition}; |
12 | use ra_syntax::{ | 12 | use ra_syntax::{ |
13 | SyntaxNode, AstPtr, TextUnit, SyntaxNodePtr, | 13 | SyntaxNode, AstPtr, TextUnit, SyntaxNodePtr, TextRange, |
14 | ast::{self, AstNode, NameOwner}, | 14 | ast::{self, AstNode, NameOwner}, |
15 | algo::find_node_at_offset, | 15 | algo::find_node_at_offset, |
16 | SyntaxKind::*, | 16 | SyntaxKind::*, |
@@ -19,7 +19,7 @@ use ra_syntax::{ | |||
19 | use crate::{ | 19 | use crate::{ |
20 | HirDatabase, Function, Struct, Enum, Const, Static, Either, DefWithBody, PerNs, Name, | 20 | HirDatabase, Function, Struct, Enum, Const, Static, Either, DefWithBody, PerNs, Name, |
21 | AsName, Module, HirFileId, Crate, Trait, Resolver, | 21 | AsName, Module, HirFileId, Crate, Trait, Resolver, |
22 | expr::{BodySourceMap, scope::{ReferenceDescriptor, ScopeId, ExprScopes}}, | 22 | expr::{BodySourceMap, scope::{ScopeId, ExprScopes}}, |
23 | ids::LocationCtx, | 23 | ids::LocationCtx, |
24 | expr, AstId | 24 | expr, AstId |
25 | }; | 25 | }; |
@@ -203,6 +203,12 @@ impl ScopeEntryWithSyntax { | |||
203 | } | 203 | } |
204 | } | 204 | } |
205 | 205 | ||
206 | #[derive(Debug)] | ||
207 | pub struct ReferenceDescriptor { | ||
208 | pub range: TextRange, | ||
209 | pub name: String, | ||
210 | } | ||
211 | |||
206 | impl SourceAnalyzer { | 212 | impl SourceAnalyzer { |
207 | pub fn new( | 213 | pub fn new( |
208 | db: &impl HirDatabase, | 214 | db: &impl HirDatabase, |
@@ -318,6 +324,8 @@ impl SourceAnalyzer { | |||
318 | } | 324 | } |
319 | 325 | ||
320 | pub fn find_all_refs(&self, pat: &ast::BindPat) -> Vec<ReferenceDescriptor> { | 326 | pub fn find_all_refs(&self, pat: &ast::BindPat) -> Vec<ReferenceDescriptor> { |
327 | // FIXME: at least, this should work with any DefWithBody, but ideally | ||
328 | // this should be hir-based altogether | ||
321 | let fn_def = pat.syntax().ancestors().find_map(ast::FnDef::cast).unwrap(); | 329 | let fn_def = pat.syntax().ancestors().find_map(ast::FnDef::cast).unwrap(); |
322 | let ptr = Either::A(AstPtr::new(pat.into())); | 330 | let ptr = Either::A(AstPtr::new(pat.into())); |
323 | fn_def | 331 | fn_def |
@@ -329,7 +337,7 @@ impl SourceAnalyzer { | |||
329 | Some(entry) => entry.ptr() == ptr, | 337 | Some(entry) => entry.ptr() == ptr, |
330 | }) | 338 | }) |
331 | .map(|name_ref| ReferenceDescriptor { | 339 | .map(|name_ref| ReferenceDescriptor { |
332 | name: name_ref.syntax().text().to_string(), | 340 | name: name_ref.text().to_string(), |
333 | range: name_ref.syntax().range(), | 341 | range: name_ref.syntax().range(), |
334 | }) | 342 | }) |
335 | .collect() | 343 | .collect() |