Skip to content

Commit

Permalink
Merge #4269 #4293
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
3 people committed May 4, 2020
3 parents 0ef4665 + 99c2ca8 + 6af464d commit b1a5dc8
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/ra_flycheck/Cargo.toml
Expand Up @@ -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"] }
Expand Down
33 changes: 33 additions & 0 deletions crates/ra_ide/src/goto_definition.rs
Expand Up @@ -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(
Expand Down
10 changes: 10 additions & 0 deletions crates/ra_ide_db/src/defs.rs
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions crates/ra_ide_db/src/marks.rs
Expand Up @@ -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
Expand Down

0 comments on commit b1a5dc8

Please sign in to comment.