Refactor search

This commit is contained in:
Edwin Cheng 2020-03-22 19:52:45 +08:00
parent 532e178f8e
commit f647faac60

View File

@ -10,9 +10,7 @@
use once_cell::unsync::Lazy;
use ra_db::{FileId, FileRange, SourceDatabaseExt};
use ra_prof::profile;
use ra_syntax::{
algo::find_node_at_offset, ast, match_ast, AstNode, TextRange, TextUnit, TokenAtOffset,
};
use ra_syntax::{ast, match_ast, AstNode, TextRange, TextUnit};
use rustc_hash::FxHashMap;
use test_utils::tested_by;
@ -219,21 +217,11 @@ pub fn find_usages(
continue;
}
let name_ref =
if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(&tree, offset) {
let name_ref: ast::NameRef =
if let Some(name_ref) = sema.find_node_at_offset_with_descend(&tree, offset) {
name_ref
} else {
// Handle macro token cases
let token = match tree.token_at_offset(offset) {
TokenAtOffset::None => continue,
TokenAtOffset::Single(t) => t,
TokenAtOffset::Between(_, t) => t,
};
let expanded = sema.descend_into_macros(token);
match ast::NameRef::cast(expanded.parent()) {
Some(name_ref) => name_ref,
_ => continue,
}
continue;
};
// FIXME: reuse sb