diff options
-rw-r--r-- | crates/ra_flycheck/Cargo.toml | 3 | ||||
-rw-r--r-- | crates/ra_ide/src/goto_definition.rs | 33 | ||||
-rw-r--r-- | crates/ra_ide_db/src/defs.rs | 10 | ||||
-rw-r--r-- | crates/ra_ide_db/src/marks.rs | 1 |
4 files changed, 47 insertions, 0 deletions
diff --git a/crates/ra_flycheck/Cargo.toml b/crates/ra_flycheck/Cargo.toml index 324c33d9d..3d5093264 100644 --- a/crates/ra_flycheck/Cargo.toml +++ b/crates/ra_flycheck/Cargo.toml | |||
@@ -4,6 +4,9 @@ name = "ra_flycheck" | |||
4 | version = "0.1.0" | 4 | version = "0.1.0" |
5 | authors = ["rust-analyzer developers"] | 5 | authors = ["rust-analyzer developers"] |
6 | 6 | ||
7 | [lib] | ||
8 | doctest = false | ||
9 | |||
7 | [dependencies] | 10 | [dependencies] |
8 | crossbeam-channel = "0.4.0" | 11 | crossbeam-channel = "0.4.0" |
9 | lsp-types = { version = "0.74.0", features = ["proposed"] } | 12 | lsp-types = { version = "0.74.0", features = ["proposed"] } |
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index dbb4f38c7..150895abb 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs | |||
@@ -244,6 +244,39 @@ mod tests { | |||
244 | } | 244 | } |
245 | 245 | ||
246 | #[test] | 246 | #[test] |
247 | fn goto_def_for_use_alias() { | ||
248 | covers!(ra_ide_db::goto_def_for_use_alias); | ||
249 | check_goto( | ||
250 | " | ||
251 | //- /lib.rs | ||
252 | use foo as bar<|>; | ||
253 | |||
254 | |||
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 | |||
270 | //- /foo/lib.rs | ||
271 | #[macro_export] | ||
272 | macro_rules! foo { () => { () } } | ||
273 | ", | ||
274 | "foo MACRO_CALL FileId(2) 0..49 29..32", | ||
275 | "#[macro_export]\nmacro_rules! foo { () => { () } }|foo", | ||
276 | ); | ||
277 | } | ||
278 | |||
279 | #[test] | ||
247 | fn goto_def_for_macros_in_use_tree() { | 280 | fn goto_def_for_macros_in_use_tree() { |
248 | check_goto( | 281 | check_goto( |
249 | " | 282 | " |
diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs index 7cd2384e9..d5d06962b 100644 --- a/crates/ra_ide_db/src/defs.rs +++ b/crates/ra_ide_db/src/defs.rs | |||
@@ -119,6 +119,16 @@ fn classify_name_inner(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Opti | |||
119 | 119 | ||
120 | match_ast! { | 120 | match_ast! { |
121 | match parent { | 121 | match parent { |
122 | ast::Alias(it) => { | ||
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()) | ||
131 | }, | ||
122 | ast::BindPat(it) => { | 132 | ast::BindPat(it) => { |
123 | let local = sema.to_def(&it)?; | 133 | let local = sema.to_def(&it)?; |
124 | Some(Definition::Local(local)) | 134 | Some(Definition::Local(local)) |
diff --git a/crates/ra_ide_db/src/marks.rs b/crates/ra_ide_db/src/marks.rs index 03b4be21c..386fe605c 100644 --- a/crates/ra_ide_db/src/marks.rs +++ b/crates/ra_ide_db/src/marks.rs | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | test_utils::marks![ | 3 | test_utils::marks![ |
4 | goto_def_for_macros | 4 | goto_def_for_macros |
5 | goto_def_for_use_alias | ||
5 | goto_def_for_methods | 6 | goto_def_for_methods |
6 | goto_def_for_fields | 7 | goto_def_for_fields |
7 | goto_def_for_record_fields | 8 | goto_def_for_record_fields |