aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/source_binder.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-04-13 09:32:58 +0100
committerAleksey Kladov <[email protected]>2019-04-13 12:16:46 +0100
commit2facb5e061971afbf6bd2fabe3966d5de9d46489 (patch)
tree90c57ec3794cf995efdb224465858323520def52 /crates/ra_hir/src/source_binder.rs
parentb260641e0caa3938151afe66fa3bf5691b8c3caa (diff)
cleanups
Diffstat (limited to 'crates/ra_hir/src/source_binder.rs')
-rw-r--r--crates/ra_hir/src/source_binder.rs14
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;
10use rustc_hash::{FxHashSet, FxHashMap}; 10use rustc_hash::{FxHashSet, FxHashMap};
11use ra_db::{FileId, FilePosition}; 11use ra_db::{FileId, FilePosition};
12use ra_syntax::{ 12use 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::{
19use crate::{ 19use 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)]
207pub struct ReferenceDescriptor {
208 pub range: TextRange,
209 pub name: String,
210}
211
206impl SourceAnalyzer { 212impl 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()