diff options
author | Benjamin Coenen <[email protected]> | 2020-05-02 20:42:27 +0100 |
---|---|---|
committer | Benjamin Coenen <[email protected]> | 2020-05-02 20:42:27 +0100 |
commit | 99c2ca84945cb12d51ca4353ac20f844e7b40eaa (patch) | |
tree | fa21a4c951157891b8afc82526abb557a4287ceb | |
parent | 4613497a7714c6cd87166e6525d764d75f8acefd (diff) |
add support of use alias semantic in definition #4202
Signed-off-by: Benjamin Coenen <[email protected]>
-rw-r--r-- | crates/ra_ide/src/goto_definition.rs | 17 | ||||
-rw-r--r-- | crates/ra_ide_db/src/defs.rs | 14 |
2 files changed, 25 insertions, 6 deletions
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 31f567541..5b9b3eef8 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs | |||
@@ -249,11 +249,26 @@ mod tests { | |||
249 | check_goto( | 249 | check_goto( |
250 | " | 250 | " |
251 | //- /lib.rs | 251 | //- /lib.rs |
252 | use foo as <|>bar; | 252 | use foo as bar<|>; |
253 | 253 | ||
254 | 254 | ||
255 | //- /foo/lib.rs | 255 | //- /foo/lib.rs |
256 | #[macro_export] | 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 | |||
270 | //- /foo/lib.rs | ||
271 | #[macro_export] | ||
257 | macro_rules! foo { () => { () } } | 272 | macro_rules! foo { () => { () } } |
258 | ", | 273 | ", |
259 | "foo MACRO_CALL FileId(2) 0..49 29..32", | 274 | "foo MACRO_CALL FileId(2) 0..49 29..32", |
diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs index 54543e6e4..d5d06962b 100644 --- a/crates/ra_ide_db/src/defs.rs +++ b/crates/ra_ide_db/src/defs.rs | |||
@@ -11,7 +11,7 @@ use hir::{ | |||
11 | }; | 11 | }; |
12 | use ra_prof::profile; | 12 | use ra_prof::profile; |
13 | use ra_syntax::{ | 13 | use ra_syntax::{ |
14 | ast::{self, AstNode, NameOwner}, | 14 | ast::{self, AstNode}, |
15 | match_ast, | 15 | match_ast, |
16 | }; | 16 | }; |
17 | use test_utils::tested_by; | 17 | use test_utils::tested_by; |
@@ -115,15 +115,19 @@ pub fn classify_name(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option | |||
115 | } | 115 | } |
116 | 116 | ||
117 | fn classify_name_inner(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option<Definition> { | 117 | fn classify_name_inner(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option<Definition> { |
118 | println!("name : {} -- {:?}", name, name); | ||
119 | let parent = name.syntax().parent()?; | 118 | let parent = name.syntax().parent()?; |
120 | println!("parent : {} -- {:?}", parent, parent); | ||
121 | 119 | ||
122 | match_ast! { | 120 | match_ast! { |
123 | match parent { | 121 | match parent { |
124 | ast::Alias(it) => { | 122 | ast::Alias(it) => { |
125 | let def = sema.to_def(&it)?; | 123 | tested_by!(goto_def_for_use_alias; force); |
126 | Some(Definition::ModuleDef(def.into())) | 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()) | ||
127 | }, | 131 | }, |
128 | ast::BindPat(it) => { | 132 | ast::BindPat(it) => { |
129 | let local = sema.to_def(&it)?; | 133 | let local = sema.to_def(&it)?; |