From 19e28888aa41b2845b47adb7314aed99d3c48679 Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Fri, 1 May 2020 16:26:22 +0200 Subject: wip Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- crates/ra_ide/src/goto_definition.rs | 18 ++++++++++++++++++ crates/ra_ide_db/src/defs.rs | 8 +++++++- crates/ra_ide_db/src/marks.rs | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 1dfca819d..31f567541 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -243,6 +243,24 @@ 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 { () => { () } } + ", + "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 7cd2384e9..54543e6e4 100644 --- a/crates/ra_ide_db/src/defs.rs +++ b/crates/ra_ide_db/src/defs.rs @@ -11,7 +11,7 @@ use hir::{ }; use ra_prof::profile; use ra_syntax::{ - ast::{self, AstNode}, + ast::{self, AstNode, NameOwner}, match_ast, }; use test_utils::tested_by; @@ -115,10 +115,16 @@ pub fn classify_name(sema: &Semantics, name: &ast::Name) -> Option } fn classify_name_inner(sema: &Semantics, name: &ast::Name) -> Option { + println!("name : {} -- {:?}", name, name); let parent = name.syntax().parent()?; + println!("parent : {} -- {:?}", parent, parent); match_ast! { match parent { + ast::Alias(it) => { + let def = sema.to_def(&it)?; + Some(Definition::ModuleDef(def.into())) + }, 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 03b4be21c..386fe605c 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 -- cgit v1.2.3 From 99c2ca84945cb12d51ca4353ac20f844e7b40eaa Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Sat, 2 May 2020 21:42:27 +0200 Subject: add support of use alias semantic in definition #4202 Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- crates/ra_ide/src/goto_definition.rs | 17 ++++++++++++++++- crates/ra_ide_db/src/defs.rs | 14 +++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 31f567541..5b9b3eef8 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -249,9 +249,24 @@ mod tests { check_goto( " //- /lib.rs - use foo as <|>bar; + 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 { () => { () } } diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs index 54543e6e4..d5d06962b 100644 --- a/crates/ra_ide_db/src/defs.rs +++ b/crates/ra_ide_db/src/defs.rs @@ -11,7 +11,7 @@ use hir::{ }; use ra_prof::profile; use ra_syntax::{ - ast::{self, AstNode, NameOwner}, + ast::{self, AstNode}, match_ast, }; use test_utils::tested_by; @@ -115,15 +115,19 @@ pub fn classify_name(sema: &Semantics, name: &ast::Name) -> Option } fn classify_name_inner(sema: &Semantics, name: &ast::Name) -> Option { - println!("name : {} -- {:?}", name, name); let parent = name.syntax().parent()?; - println!("parent : {} -- {:?}", parent, parent); match_ast! { match parent { ast::Alias(it) => { - let def = sema.to_def(&it)?; - Some(Definition::ModuleDef(def.into())) + 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)?; -- cgit v1.2.3 From 6af464d185dc12db9d523c24c483ad8d6ad53d0e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 4 May 2020 12:26:52 +0200 Subject: no doctests for flycheck --- crates/ra_flycheck/Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) 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" 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"] } -- cgit v1.2.3