aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
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
parentb260641e0caa3938151afe66fa3bf5691b8c3caa (diff)
cleanups
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/expr/scope.rs11
-rw-r--r--crates/ra_hir/src/source_binder.rs14
2 files changed, 12 insertions, 13 deletions
diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs
index 7f53f23aa..58f365128 100644
--- a/crates/ra_hir/src/expr/scope.rs
+++ b/crates/ra_hir/src/expr/scope.rs
@@ -1,7 +1,6 @@
1use std::sync::Arc; 1use std::sync::Arc;
2 2
3use rustc_hash::FxHashMap; 3use rustc_hash::FxHashMap;
4use ra_syntax::TextRange;
5use ra_arena::{Arena, RawId, impl_arena_id}; 4use ra_arena::{Arena, RawId, impl_arena_id};
6 5
7use crate::{ 6use crate::{
@@ -171,22 +170,14 @@ fn compute_expr_scopes(expr: ExprId, body: &Body, scopes: &mut ExprScopes, scope
171 }; 170 };
172} 171}
173 172
174#[derive(Debug)]
175pub struct ReferenceDescriptor {
176 pub range: TextRange,
177 pub name: String,
178}
179
180#[cfg(test)] 173#[cfg(test)]
181mod tests { 174mod tests {
182 use ra_db::SourceDatabase; 175 use ra_db::SourceDatabase;
183 use ra_syntax::{algo::find_node_at_offset, AstNode, SyntaxNodePtr}; 176 use ra_syntax::{algo::find_node_at_offset, AstNode, SyntaxNodePtr, ast};
184 use test_utils::{extract_offset, assert_eq_text}; 177 use test_utils::{extract_offset, assert_eq_text};
185 178
186 use crate::{source_binder::SourceAnalyzer, mock::MockDatabase}; 179 use crate::{source_binder::SourceAnalyzer, mock::MockDatabase};
187 180
188 use super::*;
189
190 fn do_check(code: &str, expected: &[&str]) { 181 fn do_check(code: &str, expected: &[&str]) {
191 let (off, code) = extract_offset(code); 182 let (off, code) = extract_offset(code);
192 let code = { 183 let code = {
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()