Skip to content

Commit 99c2ca8

Browse files
committed
add support of use alias semantic in definition #4202
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
1 parent 4613497 commit 99c2ca8

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

crates/ra_ide/src/goto_definition.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,24 @@ mod tests {
249249
check_goto(
250250
"
251251
//- /lib.rs
252-
use foo as <|>bar;
252+
use foo as bar<|>;
253253
254254
255+
//- /foo/lib.rs
256+
#[macro_export]
257+
macro_rules! foo { () => { () } }",
258+
"SOURCE_FILE FileId(2) 0..50",
259+
"#[macro_export]\nmacro_rules! foo { () => { () } }\n",
260+
);
261+
}
262+
263+
#[test]
264+
fn goto_def_for_use_alias_foo_macro() {
265+
check_goto(
266+
"
267+
//- /lib.rs
268+
use foo::foo as bar<|>;
269+
255270
//- /foo/lib.rs
256271
#[macro_export]
257272
macro_rules! foo { () => { () } }

crates/ra_ide_db/src/defs.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use hir::{
1111
};
1212
use ra_prof::profile;
1313
use ra_syntax::{
14-
ast::{self, AstNode, NameOwner},
14+
ast::{self, AstNode},
1515
match_ast,
1616
};
1717
use test_utils::tested_by;
@@ -115,15 +115,19 @@ pub fn classify_name(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option
115115
}
116116

117117
fn classify_name_inner(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option<Definition> {
118-
println!("name : {} -- {:?}", name, name);
119118
let parent = name.syntax().parent()?;
120-
println!("parent : {} -- {:?}", parent, parent);
121119

122120
match_ast! {
123121
match parent {
124122
ast::Alias(it) => {
125-
let def = sema.to_def(&it)?;
126-
Some(Definition::ModuleDef(def.into()))
123+
tested_by!(goto_def_for_use_alias; force);
124+
let use_tree = it.syntax().ancestors().find_map(ast::UseTree::cast)?;
125+
let path = use_tree.path()?;
126+
let path_segment = path.segment()?;
127+
let name_ref = path_segment.name_ref()?;
128+
let name_ref_class = classify_name_ref(sema, &name_ref)?;
129+
130+
Some(name_ref_class.definition())
127131
},
128132
ast::BindPat(it) => {
129133
let local = sema.to_def(&it)?;

0 commit comments

Comments
 (0)