add support of use alias semantic in definition #4202

Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
This commit is contained in:
Benjamin Coenen 2020-05-02 21:42:27 +02:00
parent 4613497a77
commit 99c2ca8494
2 changed files with 25 additions and 6 deletions

View file

@ -249,9 +249,24 @@ mod tests {
check_goto(
"
//- /lib.rs
use foo as <|>bar;
use foo as bar<|>;
//- /foo/lib.rs
#[macro_export]
macro_rules! foo { () => { () } }",
"SOURCE_FILE FileId(2) 0..50",
"#[macro_export]\nmacro_rules! foo { () => { () } }\n",
);
}
#[test]
fn goto_def_for_use_alias_foo_macro() {
check_goto(
"
//- /lib.rs
use foo::foo as bar<|>;
//- /foo/lib.rs
#[macro_export]
macro_rules! foo { () => { () } }

View file

@ -11,7 +11,7 @@ use hir::{
};
use ra_prof::profile;
use ra_syntax::{
ast::{self, AstNode, NameOwner},
ast::{self, AstNode},
match_ast,
};
use test_utils::tested_by;
@ -115,15 +115,19 @@ pub fn classify_name(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option
}
fn classify_name_inner(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option<Definition> {
println!("name : {} -- {:?}", name, name);
let parent = name.syntax().parent()?;
println!("parent : {} -- {:?}", parent, parent);
match_ast! {
match parent {
ast::Alias(it) => {
let def = sema.to_def(&it)?;
Some(Definition::ModuleDef(def.into()))
tested_by!(goto_def_for_use_alias; force);
let use_tree = it.syntax().ancestors().find_map(ast::UseTree::cast)?;
let path = use_tree.path()?;
let path_segment = path.segment()?;
let name_ref = path_segment.name_ref()?;
let name_ref_class = classify_name_ref(sema, &name_ref)?;
Some(name_ref_class.definition())
},
ast::BindPat(it) => {
let local = sema.to_def(&it)?;