mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
4269: add support of use alias semantic in definition r=matklad a=bnjjj close #4202 4293: no doctests for flycheck r=matklad a=matklad bors r+ 🤖 Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
b1a5dc8c8b
4 changed files with 47 additions and 0 deletions
|
@ -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"] }
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -119,6 +119,16 @@ fn classify_name_inner(sema: &Semantics<RootDatabase>, 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))
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue