diff --git a/crates/ra_flycheck/Cargo.toml b/crates/ra_flycheck/Cargo.toml index 324c33d9dd..3d5093264e 100644 --- a/crates/ra_flycheck/Cargo.toml +++ b/crates/ra_flycheck/Cargo.toml @@ -4,6 +4,9 @@ name = "ra_flycheck" version = "0.1.0" authors = ["rust-analyzer developers"] +[lib] +doctest = false + [dependencies] crossbeam-channel = "0.4.0" 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 dbb4f38c70..150895abb4 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -243,6 +243,39 @@ mod tests { ); } + #[test] + fn goto_def_for_use_alias() { + covers!(ra_ide_db::goto_def_for_use_alias); + check_goto( + " + //- /lib.rs + 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 { () => { () } } + ", + "foo MACRO_CALL FileId(2) 0..49 29..32", + "#[macro_export]\nmacro_rules! foo { () => { () } }|foo", + ); + } + #[test] fn goto_def_for_macros_in_use_tree() { check_goto( diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs index 7cd2384e9b..d5d06962bb 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, name: &ast::Name) -> Opti match_ast! { match parent { + ast::Alias(it) => { + 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)?; Some(Definition::Local(local)) diff --git a/crates/ra_ide_db/src/marks.rs b/crates/ra_ide_db/src/marks.rs index 03b4be21c9..386fe605c7 100644 --- a/crates/ra_ide_db/src/marks.rs +++ b/crates/ra_ide_db/src/marks.rs @@ -2,6 +2,7 @@ test_utils::marks![ goto_def_for_macros + goto_def_for_use_alias goto_def_for_methods goto_def_for_fields goto_def_for_record_fields