Skip to content

Commit b1a5dc8

Browse files
bors[bot]bnjjjmatklad
authored
Merge #4269 #4293
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>
3 parents 0ef4665 + 99c2ca8 + 6af464d commit b1a5dc8

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

crates/ra_flycheck/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ name = "ra_flycheck"
44
version = "0.1.0"
55
authors = ["rust-analyzer developers"]
66

7+
[lib]
8+
doctest = false
9+
710
[dependencies]
811
crossbeam-channel = "0.4.0"
912
lsp-types = { version = "0.74.0", features = ["proposed"] }

crates/ra_ide/src/goto_definition.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,39 @@ mod tests {
243243
);
244244
}
245245

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+
246279
#[test]
247280
fn goto_def_for_macros_in_use_tree() {
248281
check_goto(

crates/ra_ide_db/src/defs.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ fn classify_name_inner(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Opti
119119

120120
match_ast! {
121121
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+
},
122132
ast::BindPat(it) => {
123133
let local = sema.to_def(&it)?;
124134
Some(Definition::Local(local))

crates/ra_ide_db/src/marks.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
test_utils::marks![
44
goto_def_for_macros
5+
goto_def_for_use_alias
56
goto_def_for_methods
67
goto_def_for_fields
78
goto_def_for_record_fields

0 commit comments

Comments
 (0)