From 2facb5e061971afbf6bd2fabe3966d5de9d46489 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 13 Apr 2019 11:32:58 +0300 Subject: cleanups --- crates/ra_hir/src/expr/scope.rs | 11 +---------- crates/ra_hir/src/source_binder.rs | 14 +++++++++++--- 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 @@ use std::sync::Arc; use rustc_hash::FxHashMap; -use ra_syntax::TextRange; use ra_arena::{Arena, RawId, impl_arena_id}; use crate::{ @@ -171,22 +170,14 @@ fn compute_expr_scopes(expr: ExprId, body: &Body, scopes: &mut ExprScopes, scope }; } -#[derive(Debug)] -pub struct ReferenceDescriptor { - pub range: TextRange, - pub name: String, -} - #[cfg(test)] mod tests { use ra_db::SourceDatabase; - use ra_syntax::{algo::find_node_at_offset, AstNode, SyntaxNodePtr}; + use ra_syntax::{algo::find_node_at_offset, AstNode, SyntaxNodePtr, ast}; use test_utils::{extract_offset, assert_eq_text}; use crate::{source_binder::SourceAnalyzer, mock::MockDatabase}; - use super::*; - fn do_check(code: &str, expected: &[&str]) { let (off, code) = extract_offset(code); 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; use rustc_hash::{FxHashSet, FxHashMap}; use ra_db::{FileId, FilePosition}; use ra_syntax::{ - SyntaxNode, AstPtr, TextUnit, SyntaxNodePtr, + SyntaxNode, AstPtr, TextUnit, SyntaxNodePtr, TextRange, ast::{self, AstNode, NameOwner}, algo::find_node_at_offset, SyntaxKind::*, @@ -19,7 +19,7 @@ use ra_syntax::{ use crate::{ HirDatabase, Function, Struct, Enum, Const, Static, Either, DefWithBody, PerNs, Name, AsName, Module, HirFileId, Crate, Trait, Resolver, - expr::{BodySourceMap, scope::{ReferenceDescriptor, ScopeId, ExprScopes}}, + expr::{BodySourceMap, scope::{ScopeId, ExprScopes}}, ids::LocationCtx, expr, AstId }; @@ -203,6 +203,12 @@ impl ScopeEntryWithSyntax { } } +#[derive(Debug)] +pub struct ReferenceDescriptor { + pub range: TextRange, + pub name: String, +} + impl SourceAnalyzer { pub fn new( db: &impl HirDatabase, @@ -318,6 +324,8 @@ impl SourceAnalyzer { } pub fn find_all_refs(&self, pat: &ast::BindPat) -> Vec { + // FIXME: at least, this should work with any DefWithBody, but ideally + // this should be hir-based altogether let fn_def = pat.syntax().ancestors().find_map(ast::FnDef::cast).unwrap(); let ptr = Either::A(AstPtr::new(pat.into())); fn_def @@ -329,7 +337,7 @@ impl SourceAnalyzer { Some(entry) => entry.ptr() == ptr, }) .map(|name_ref| ReferenceDescriptor { - name: name_ref.syntax().text().to_string(), + name: name_ref.text().to_string(), range: name_ref.syntax().range(), }) .collect() -- cgit v1.2.3