From ccd1b0800a5de5e046e6e9a4b6f49030c1ce3639 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 28 Nov 2019 12:50:26 +0300 Subject: Rename Source -> InFile --- crates/ra_ide/src/goto_definition.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide/src/goto_definition.rs') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index c10a6c844..76a741207 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -1,6 +1,6 @@ //! FIXME: write short doc here -use hir::{db::AstDatabase, Source}; +use hir::{db::AstDatabase, InFile}; use ra_syntax::{ ast::{self, DocCommentsOwner}, match_ast, AstNode, SyntaxNode, @@ -58,7 +58,7 @@ impl ReferenceResult { pub(crate) fn reference_definition( db: &RootDatabase, - name_ref: Source<&ast::NameRef>, + name_ref: InFile<&ast::NameRef>, ) -> ReferenceResult { use self::ReferenceResult::*; @@ -94,7 +94,7 @@ pub(crate) fn reference_definition( pub(crate) fn name_definition( db: &RootDatabase, - name: Source<&ast::Name>, + name: InFile<&ast::Name>, ) -> Option> { let parent = name.value.syntax().parent()?; @@ -115,7 +115,7 @@ pub(crate) fn name_definition( None } -fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option { +fn named_target(db: &RootDatabase, node: InFile<&SyntaxNode>) -> Option { match_ast! { match (node.value) { ast::StructDef(it) => { -- cgit v1.2.3 From a565072ddeac519eea3b415a57e9fd208e20e562 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 6 Dec 2019 19:30:15 +0100 Subject: Try to make go to definition work in format! SourceAnalyzer didn't work properly within expression macro expansions because it didn't find the enclosing function. Fix this by going up the expansion chain to find ancestors. This makes the test work, but apparently in real usage it's still not working. --- crates/ra_ide/src/goto_definition.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'crates/ra_ide/src/goto_definition.rs') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 76a741207..b1d567ca7 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -693,4 +693,31 @@ mod tests { "foo FN_DEF FileId(1) [52; 63) [55; 58)", ); } + + #[test] + fn goto_through_format() { + check_goto( + " + //- /lib.rs + #[macro_export] + macro_rules! format { + ($($arg:tt)*) => ($crate::fmt::format($crate::__export::format_args!($($arg)*))) + } + #[rustc_builtin_macro] + #[macro_export] + macro_rules! format_args { + ($fmt:expr) => ({ /* compiler built-in */ }); + ($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ }) + } + pub mod __export { + pub use crate::format_args; + } + fn foo() -> i8 {} + fn test() { + format!(\"{}\", fo<|>o()) + } + ", + "foo FN_DEF FileId(1) [359; 376) [362; 365)", + ); + } } -- cgit v1.2.3 From c80dc0ad3aee717f9d15c11d300d0eb1c10f1cc8 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 6 Dec 2019 21:24:41 +0100 Subject: Make the goto_through_format test actually fail :( --- crates/ra_ide/src/goto_definition.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'crates/ra_ide/src/goto_definition.rs') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index b1d567ca7..d3c198813 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -689,11 +689,13 @@ mod tests { fo<|>o(); } } + mod confuse_index { fn foo(); } ", "foo FN_DEF FileId(1) [52; 63) [55; 58)", ); } + #[should_panic] // currently failing because of expr mapping problems #[test] fn goto_through_format() { check_goto( @@ -711,6 +713,7 @@ mod tests { } pub mod __export { pub use crate::format_args; + fn foo() {} // for index confusion } fn foo() -> i8 {} fn test() { -- cgit v1.2.3 From d1a01aa2f8ca9eff9ba2321f2f113623742e212c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 7 Dec 2019 18:54:18 +0100 Subject: Gotodef for TypeParameters --- crates/ra_ide/src/goto_definition.rs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'crates/ra_ide/src/goto_definition.rs') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index d3c198813..64c0cbad4 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -64,9 +64,11 @@ pub(crate) fn reference_definition( let name_kind = classify_name_ref(db, name_ref).map(|d| d.kind); match name_kind { - Some(Macro(mac)) => return Exact(mac.to_nav(db)), - Some(Field(field)) => return Exact(field.to_nav(db)), - Some(AssocItem(assoc)) => return Exact(assoc.to_nav(db)), + Some(Macro(it)) => return Exact(it.to_nav(db)), + Some(Field(it)) => return Exact(it.to_nav(db)), + Some(GenericParam(it)) => return Exact(it.to_nav(db)), + Some(AssocItem(it)) => return Exact(it.to_nav(db)), + Some(Local(it)) => return Exact(it.to_nav(db)), Some(Def(def)) => match NavigationTarget::from_def(db, def) { Some(nav) => return Exact(nav), None => return Approximate(vec![]), @@ -77,10 +79,6 @@ pub(crate) fn reference_definition( // us to the actual type return Exact(imp.to_nav(db)); } - Some(Local(local)) => return Exact(local.to_nav(db)), - Some(GenericParam(_)) => { - // FIXME: go to the generic param def - } None => {} }; @@ -723,4 +721,17 @@ mod tests { "foo FN_DEF FileId(1) [359; 376) [362; 365)", ); } + + #[test] + fn goto_for_type_param() { + check_goto( + " + //- /lib.rs + struct Foo { + t: <|>T, + } + ", + "T TYPE_PARAM FileId(1) [11; 12)", + ); + } } -- cgit v1.2.3 From 88c5b1282a5770097c6c768b24bedfc3a6944e08 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 7 Dec 2019 20:09:53 +0100 Subject: Rename GenericParam -> TypeParam We don't have LifetimeParam yet, but they are planned! --- crates/ra_ide/src/goto_definition.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide/src/goto_definition.rs') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 64c0cbad4..1b968134d 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -66,7 +66,7 @@ pub(crate) fn reference_definition( match name_kind { Some(Macro(it)) => return Exact(it.to_nav(db)), Some(Field(it)) => return Exact(it.to_nav(db)), - Some(GenericParam(it)) => return Exact(it.to_nav(db)), + Some(TypeParam(it)) => return Exact(it.to_nav(db)), Some(AssocItem(it)) => return Exact(it.to_nav(db)), Some(Local(it)) => return Exact(it.to_nav(db)), Some(Def(def)) => match NavigationTarget::from_def(db, def) { -- cgit v1.2.3 From 91f28e43a2686d0ac06f73b5fed11351aad428a9 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 8 Dec 2019 09:26:17 +0100 Subject: Fix expansion of format_args --- crates/ra_ide/src/goto_definition.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'crates/ra_ide/src/goto_definition.rs') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 1b968134d..077b0beda 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -693,7 +693,6 @@ mod tests { ); } - #[should_panic] // currently failing because of expr mapping problems #[test] fn goto_through_format() { check_goto( -- cgit v1.2.3 From 2223620313e94deb04d1565a75004579aa1a9e07 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 8 Dec 2019 11:22:39 +0100 Subject: Fix range in goto_through_format test --- crates/ra_ide/src/goto_definition.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide/src/goto_definition.rs') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 077b0beda..b93d6a931 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -717,7 +717,7 @@ mod tests { format!(\"{}\", fo<|>o()) } ", - "foo FN_DEF FileId(1) [359; 376) [362; 365)", + "foo FN_DEF FileId(1) [398; 415) [401; 404)", ); } -- cgit v1.2.3 From b683cbd93db65f5421ef9b7617a2abfe93928af0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 9 Dec 2019 18:42:45 +0100 Subject: Report correct original range in goto_definition --- crates/ra_ide/src/goto_definition.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'crates/ra_ide/src/goto_definition.rs') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index b93d6a931..cfe62037f 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -19,25 +19,23 @@ pub(crate) fn goto_definition( position: FilePosition, ) -> Option>> { let file = db.parse_or_expand(position.file_id.into())?; - let token = file.token_at_offset(position.offset).filter(|it| !it.kind().is_trivia()).next()?; - let token = descend_into_macros(db, position.file_id, token); + let original_token = + file.token_at_offset(position.offset).filter(|it| !it.kind().is_trivia()).next()?; + let token = descend_into_macros(db, position.file_id, original_token.clone()); - let res = match_ast! { + let nav_targets = match_ast! { match (token.value.parent()) { ast::NameRef(name_ref) => { - let navs = reference_definition(db, token.with_value(&name_ref)).to_vec(); - RangeInfo::new(name_ref.syntax().text_range(), navs.to_vec()) + reference_definition(db, token.with_value(&name_ref)).to_vec() }, ast::Name(name) => { - let navs = name_definition(db, token.with_value(&name))?; - RangeInfo::new(name.syntax().text_range(), navs) - + name_definition(db, token.with_value(&name))? }, _ => return None, } }; - Some(res) + Some(RangeInfo::new(original_token.text_range(), nav_targets)) } #[derive(Debug)] -- cgit v1.2.3 From 4df741ecb2d00c3d8cdbc37d734ff5514dd5e7b0 Mon Sep 17 00:00:00 2001 From: succcubbus <16743652+succcubbus@users.noreply.github.com> Date: Fri, 13 Dec 2019 19:20:02 +0100 Subject: fix goto definition when inbetween tokens fixes both goto_definition and goto_type_definition. before, when running goto between some non-trivia token and an identifier, goto would be attempted for the non-trivia token. but this does not make sense for e.g. L_PAREN or COLONCOLON only for IDENTs. now only IDENTs will be searched for in goto actions. --- crates/ra_ide/src/goto_definition.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide/src/goto_definition.rs') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index cfe62037f..96a73675f 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -3,7 +3,7 @@ use hir::{db::AstDatabase, InFile}; use ra_syntax::{ ast::{self, DocCommentsOwner}, - match_ast, AstNode, SyntaxNode, + match_ast, AstNode, SyntaxKind, SyntaxNode, }; use crate::{ @@ -20,7 +20,7 @@ pub(crate) fn goto_definition( ) -> Option>> { let file = db.parse_or_expand(position.file_id.into())?; let original_token = - file.token_at_offset(position.offset).filter(|it| !it.kind().is_trivia()).next()?; + file.token_at_offset(position.offset).find(|it| it.kind() == SyntaxKind::IDENT)?; let token = descend_into_macros(db, position.file_id, original_token.clone()); let nav_targets = match_ast! { @@ -234,6 +234,18 @@ mod tests { ); } + #[test] + fn goto_definition_works_at_start_of_item() { + check_goto( + " + //- /lib.rs + struct Foo; + enum E { X(<|>Foo) } + ", + "Foo STRUCT_DEF FileId(1) [0; 11) [7; 10)", + ); + } + #[test] fn goto_definition_resolves_correct_name() { check_goto( -- cgit v1.2.3 From 4f7da04c6735e1d00fceb6fc6f83542626ce03c9 Mon Sep 17 00:00:00 2001 From: succcubbus <16743652+succcubbus@users.noreply.github.com> Date: Fri, 13 Dec 2019 21:59:25 +0100 Subject: add tests for goto on tuple fields --- crates/ra_ide/src/goto_definition.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'crates/ra_ide/src/goto_definition.rs') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 96a73675f..30118b43f 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -446,6 +446,22 @@ mod tests { ); } + #[test] + fn goto_for_tuple_fields() { + check_goto( + " + //- /lib.rs + struct Foo(u32); + + fn bar() { + let foo = Foo(0); + foo.<|>0; + } + ", + "TUPLE_FIELD_DEF FileId(1) [11; 14)", + ); + } + #[test] fn goto_definition_works_for_ufcs_inherent_methods() { check_goto( -- cgit v1.2.3 From c82529a97f10b1302d2944f1946bcb3479f64e2d Mon Sep 17 00:00:00 2001 From: succcubbus <16743652+succcubbus@users.noreply.github.com> Date: Fri, 13 Dec 2019 22:00:05 +0100 Subject: for goto and hover pick the token based on a priority --- crates/ra_ide/src/goto_definition.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide/src/goto_definition.rs') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 30118b43f..27052d72b 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -3,7 +3,9 @@ use hir::{db::AstDatabase, InFile}; use ra_syntax::{ ast::{self, DocCommentsOwner}, - match_ast, AstNode, SyntaxKind, SyntaxNode, + match_ast, AstNode, + SyntaxKind::*, + SyntaxNode, SyntaxToken, TokenAtOffset, }; use crate::{ @@ -19,8 +21,7 @@ pub(crate) fn goto_definition( position: FilePosition, ) -> Option>> { let file = db.parse_or_expand(position.file_id.into())?; - let original_token = - file.token_at_offset(position.offset).find(|it| it.kind() == SyntaxKind::IDENT)?; + let original_token = pick_best(file.token_at_offset(position.offset))?; let token = descend_into_macros(db, position.file_id, original_token.clone()); let nav_targets = match_ast! { @@ -38,6 +39,17 @@ pub(crate) fn goto_definition( Some(RangeInfo::new(original_token.text_range(), nav_targets)) } +fn pick_best(tokens: TokenAtOffset) -> Option { + return tokens.max_by_key(priority); + fn priority(n: &SyntaxToken) -> usize { + match n.kind() { + IDENT | INT_NUMBER => 2, + kind if kind.is_trivia() => 0, + _ => 1, + } + } +} + #[derive(Debug)] pub(crate) enum ReferenceResult { Exact(NavigationTarget), -- cgit v1.2.3 From 61360fdfec981eadef1eefb595c8b32c951771e8 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sun, 15 Dec 2019 01:20:07 +0800 Subject: Fix original_source find order --- crates/ra_ide/src/goto_definition.rs | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'crates/ra_ide/src/goto_definition.rs') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index cfe62037f..2c634990d 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -209,7 +209,7 @@ fn named_target(db: &RootDatabase, node: InFile<&SyntaxNode>) -> Option (fn $name() {}) } - define_fn!( - foo - ) + define_fn!(foo); fn bar() { <|>foo(); } ", - "foo FN_DEF FileId(1) [80; 83) [80; 83)", + "foo FN_DEF FileId(1) [64; 80) [75; 78)", + "define_fn!(foo);|foo", ); } #[test] fn goto_definition_works_for_macro_defined_fn_no_arg() { - check_goto( + check_goto_with_range_content( " //- /lib.rs macro_rules! define_fn { @@ -373,7 +390,8 @@ mod tests { <|>foo(); } ", - "foo FN_DEF FileId(1) [39; 42) [39; 42)", + "foo FN_DEF FileId(1) [51; 64) [51; 64)", + "define_fn!();|define_fn!();", ); } -- cgit v1.2.3 From 69c944a1e27212604ce85154fd40cff1d46ad6f3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 18 Dec 2019 14:52:58 +0100 Subject: Add blank lines for readability --- crates/ra_ide/src/goto_definition.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'crates/ra_ide/src/goto_definition.rs') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index bee8e9df2..3b4d89e3e 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -285,8 +285,10 @@ mod tests { mod a; mod b; enum E { X(Foo<|>) } + //- /a.rs struct Foo; + //- /b.rs struct Foo; ", @@ -300,6 +302,7 @@ mod tests { " //- /lib.rs mod <|>foo; + //- /foo.rs // empty ", @@ -310,6 +313,7 @@ mod tests { " //- /lib.rs mod <|>foo; + //- /foo/mod.rs // empty ", -- cgit v1.2.3 From 46a299bceece6f8633d7c1518939efbb3a57fae3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 18 Dec 2019 15:33:36 +0100 Subject: Refactor goto tests to always specify texts --- crates/ra_ide/src/goto_definition.rs | 124 +++++++++++++++++++++-------------- 1 file changed, 74 insertions(+), 50 deletions(-) (limited to 'crates/ra_ide/src/goto_definition.rs') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 3b4d89e3e..48757f170 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -225,30 +225,35 @@ mod tests { use crate::mock_analysis::analysis_and_position; - fn check_goto(fixture: &str, expected: &str) { + fn check_goto(fixture: &str, expected: &str, expected_range: &str) { let (analysis, pos) = analysis_and_position(fixture); let mut navs = analysis.goto_definition(pos).unwrap().unwrap().info; assert_eq!(navs.len(), 1); - let nav = navs.pop().unwrap(); - nav.assert_match(expected); - } - - fn check_goto_with_range_content(fixture: &str, expected: &str, expected_range: &str) { - let (analysis, pos) = analysis_and_position(fixture); - let mut navs = analysis.goto_definition(pos).unwrap().unwrap().info; - assert_eq!(navs.len(), 1); let nav = navs.pop().unwrap(); - let file_text = analysis.file_text(pos.file_id).unwrap(); + let file_text = analysis.file_text(nav.file_id()).unwrap(); - let actual_full_range = &file_text[nav.full_range()]; - let actual_range = &file_text[nav.range()]; + let mut actual = file_text[nav.full_range()].to_string(); + if let Some(focus) = nav.focus_range() { + actual += "|"; + actual += &file_text[focus]; + } + + if !expected_range.contains("...") { + test_utils::assert_eq_text!(&actual, expected_range); + } else { + let mut parts = expected_range.split("..."); + let prefix = parts.next().unwrap(); + let suffix = parts.next().unwrap(); + assert!( + actual.starts_with(prefix) && actual.ends_with(suffix), + "\nExpected: {}\n Actual: {}\n", + expected_range, + actual + ); + } - test_utils::assert_eq_text!( - &format!("{}|{}", actual_full_range, actual_range), - expected_range - ); nav.assert_match(expected); } @@ -261,6 +266,7 @@ mod tests { enum E { X(Foo<|>) } ", "Foo STRUCT_DEF FileId(1) [0; 11) [7; 10)", + "struct Foo;|Foo", ); } @@ -273,6 +279,7 @@ mod tests { enum E { X(<|>Foo) } ", "Foo STRUCT_DEF FileId(1) [0; 11) [7; 10)", + "struct Foo;|Foo", ); } @@ -293,6 +300,7 @@ mod tests { struct Foo; ", "Foo STRUCT_DEF FileId(2) [0; 11) [7; 10)", + "struct Foo;|Foo", ); } @@ -307,6 +315,7 @@ mod tests { // empty ", "foo SOURCE_FILE FileId(2) [0; 10)", + "// empty\n\n", ); check_goto( @@ -318,6 +327,7 @@ mod tests { // empty ", "foo SOURCE_FILE FileId(2) [0; 10)", + "// empty\n\n", ); } @@ -327,17 +337,14 @@ mod tests { check_goto( " //- /lib.rs - macro_rules! foo { - () => { - {} - }; - } + macro_rules! foo { () => { () } } fn bar() { <|>foo!(); } ", - "foo MACRO_CALL FileId(1) [0; 50) [13; 16)", + "foo MACRO_CALL FileId(1) [0; 33) [13; 16)", + "macro_rules! foo { () => { () } }|foo", ); } @@ -354,13 +361,10 @@ mod tests { //- /foo/lib.rs #[macro_export] - macro_rules! foo { - () => { - {} - }; - } + macro_rules! foo { () => { () } } ", - "foo MACRO_CALL FileId(2) [0; 66) [29; 32)", + "foo MACRO_CALL FileId(2) [0; 49) [29; 32)", + "#[macro_export]\nmacro_rules! foo { () => { () } }|foo", ); } @@ -373,19 +377,16 @@ mod tests { //- /foo/lib.rs #[macro_export] - macro_rules! foo { - () => { - {} - }; - } + macro_rules! foo { () => { () } } ", - "foo MACRO_CALL FileId(2) [0; 66) [29; 32)", + "foo MACRO_CALL FileId(2) [0; 49) [29; 32)", + "#[macro_export]\nmacro_rules! foo { () => { () } }|foo", ); } #[test] fn goto_definition_works_for_macro_defined_fn_with_arg() { - check_goto_with_range_content( + check_goto( " //- /lib.rs macro_rules! define_fn { @@ -405,7 +406,7 @@ mod tests { #[test] fn goto_definition_works_for_macro_defined_fn_no_arg() { - check_goto_with_range_content( + check_goto( " //- /lib.rs macro_rules! define_fn { @@ -431,14 +432,15 @@ mod tests { //- /lib.rs struct Foo; impl Foo { - fn frobnicate(&self) { } + fn frobnicate(&self) { } } fn bar(foo: &Foo) { foo.frobnicate<|>(); } ", - "frobnicate FN_DEF FileId(1) [27; 52) [30; 40)", + "frobnicate FN_DEF FileId(1) [27; 51) [30; 40)", + "fn frobnicate(&self) { }|frobnicate", ); } @@ -457,6 +459,7 @@ mod tests { } ", "spam RECORD_FIELD_DEF FileId(1) [17; 26) [17; 21)", + "spam: u32|spam", ); } @@ -477,6 +480,7 @@ mod tests { } ", "spam RECORD_FIELD_DEF FileId(1) [17; 26) [17; 21)", + "spam: u32|spam", ); } @@ -493,6 +497,7 @@ mod tests { } ", "TUPLE_FIELD_DEF FileId(1) [11; 14)", + "u32", ); } @@ -503,14 +508,15 @@ mod tests { //- /lib.rs struct Foo; impl Foo { - fn frobnicate() { } + fn frobnicate() { } } fn bar(foo: &Foo) { Foo::frobnicate<|>(); } ", - "frobnicate FN_DEF FileId(1) [27; 47) [30; 40)", + "frobnicate FN_DEF FileId(1) [27; 46) [30; 40)", + "fn frobnicate() { }|frobnicate", ); } @@ -528,6 +534,7 @@ mod tests { } ", "frobnicate FN_DEF FileId(1) [16; 32) [19; 29)", + "fn frobnicate();|frobnicate", ); } @@ -547,6 +554,7 @@ mod tests { } ", "frobnicate FN_DEF FileId(1) [30; 46) [33; 43)", + "fn frobnicate();|frobnicate", ); } @@ -563,6 +571,7 @@ mod tests { } ", "impl IMPL_BLOCK FileId(1) [12; 73)", + "impl Foo {...}", ); check_goto( @@ -576,6 +585,7 @@ mod tests { } ", "impl IMPL_BLOCK FileId(1) [12; 73)", + "impl Foo {...}", ); check_goto( @@ -589,6 +599,7 @@ mod tests { } ", "impl IMPL_BLOCK FileId(1) [15; 75)", + "impl Foo {...}", ); check_goto( @@ -601,6 +612,7 @@ mod tests { } ", "impl IMPL_BLOCK FileId(1) [15; 62)", + "impl Foo {...}", ); } @@ -620,6 +632,7 @@ mod tests { } ", "impl IMPL_BLOCK FileId(1) [49; 115)", + "impl Make for Foo {...}", ); check_goto( @@ -636,6 +649,7 @@ mod tests { } ", "impl IMPL_BLOCK FileId(1) [49; 115)", + "impl Make for Foo {...}", ); } @@ -647,6 +661,7 @@ mod tests { struct Foo<|> { value: u32 } ", "Foo STRUCT_DEF FileId(1) [0; 25) [7; 10)", + "struct Foo { value: u32 }|Foo", ); check_goto( @@ -657,15 +672,16 @@ mod tests { } "#, "field RECORD_FIELD_DEF FileId(1) [17; 30) [17; 22)", + "field: string|field", ); check_goto( " //- /lib.rs - fn foo_test<|>() { - } + fn foo_test<|>() { } ", "foo_test FN_DEF FileId(1) [0; 17) [3; 11)", + "fn foo_test() { }|foo_test", ); check_goto( @@ -676,6 +692,7 @@ mod tests { } ", "Foo ENUM_DEF FileId(1) [0; 25) [5; 8)", + "enum Foo {...}|Foo", ); check_goto( @@ -688,22 +705,25 @@ mod tests { } ", "Variant2 ENUM_VARIANT FileId(1) [29; 37) [29; 37)", + "Variant2|Variant2", ); check_goto( r#" //- /lib.rs - static inner<|>: &str = ""; + static INNER<|>: &str = ""; "#, - "inner STATIC_DEF FileId(1) [0; 24) [7; 12)", + "INNER STATIC_DEF FileId(1) [0; 24) [7; 12)", + "static INNER: &str = \"\";|INNER", ); check_goto( r#" //- /lib.rs - const inner<|>: &str = ""; + const INNER<|>: &str = ""; "#, - "inner CONST_DEF FileId(1) [0; 23) [6; 11)", + "INNER CONST_DEF FileId(1) [0; 23) [6; 11)", + "const INNER: &str = \"\";|INNER", ); check_goto( @@ -712,24 +732,25 @@ mod tests { type Thing<|> = Option<()>; "#, "Thing TYPE_ALIAS_DEF FileId(1) [0; 24) [5; 10)", + "type Thing = Option<()>;|Thing", ); check_goto( r#" //- /lib.rs - trait Foo<|> { - } + trait Foo<|> { } "#, "Foo TRAIT_DEF FileId(1) [0; 13) [6; 9)", + "trait Foo { }|Foo", ); check_goto( r#" //- /lib.rs - mod bar<|> { - } + mod bar<|> { } "#, "bar MODULE FileId(1) [0; 11) [4; 7)", + "mod bar { }|bar", ); } @@ -750,6 +771,7 @@ mod tests { mod confuse_index { fn foo(); } ", "foo FN_DEF FileId(1) [52; 63) [55; 58)", + "fn foo() {}|foo", ); } @@ -778,6 +800,7 @@ mod tests { } ", "foo FN_DEF FileId(1) [398; 415) [401; 404)", + "fn foo() -> i8 {}|foo", ); } @@ -791,6 +814,7 @@ mod tests { } ", "T TYPE_PARAM FileId(1) [11; 12)", + "T", ); } } -- cgit v1.2.3 From 7c25224f0522cb828c4aa2d791562b84ee2995f9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 18 Dec 2019 16:25:15 +0100 Subject: Don't bother with focus range for navigation to locals --- crates/ra_ide/src/goto_definition.rs | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'crates/ra_ide/src/goto_definition.rs') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 48757f170..184555792 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -817,4 +817,45 @@ mod tests { "T", ); } + + #[test] + fn goto_within_macro() { + check_goto( + " + //- /lib.rs + macro_rules! id { + ($($tt:tt)*) => ($($tt)*) + } + + fn foo() { + let x = 1; + id!({ + let y = <|>x; + let z = y; + }); + } + ", + "x BIND_PAT FileId(1) [69; 70)", + "x", + ); + + check_goto( + " + //- /lib.rs + macro_rules! id { + ($($tt:tt)*) => ($($tt)*) + } + + fn foo() { + let x = 1; + id!({ + let y = x; + let z = <|>y; + }); + } + ", + "y BIND_PAT FileId(1) [98; 99)", + "y", + ); + } } -- cgit v1.2.3 From a04177f135be89ddbf1788c6f747c26812e90438 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 20 Dec 2019 11:19:09 +0100 Subject: Add local functions to bodies --- crates/ra_ide/src/goto_definition.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'crates/ra_ide/src/goto_definition.rs') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 184555792..ee4ae3e03 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -858,4 +858,21 @@ mod tests { "y", ); } + + #[test] + fn goto_def_in_local_fn() { + check_goto( + " + //- /lib.rs + fn main() { + fn foo() { + let x = 92; + <|>x; + } + } + ", + "x BIND_PAT FileId(1) [39; 40)", + "x", + ); + } } -- cgit v1.2.3 From 3d4b48e481da35f19366514c0e22ed42fef037a0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 20 Dec 2019 14:47:01 +0100 Subject: Fix resolve for field init shorthand --- crates/ra_ide/src/goto_definition.rs | 57 +++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 20 deletions(-) (limited to 'crates/ra_ide/src/goto_definition.rs') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index ee4ae3e03..9b5744789 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -258,7 +258,7 @@ mod tests { } #[test] - fn goto_definition_works_in_items() { + fn goto_def_in_items() { check_goto( " //- /lib.rs @@ -271,7 +271,7 @@ mod tests { } #[test] - fn goto_definition_works_at_start_of_item() { + fn goto_def_at_start_of_item() { check_goto( " //- /lib.rs @@ -305,7 +305,7 @@ mod tests { } #[test] - fn goto_definition_works_for_module_declaration() { + fn goto_def_for_module_declaration() { check_goto( " //- /lib.rs @@ -332,8 +332,8 @@ mod tests { } #[test] - fn goto_definition_works_for_macros() { - covers!(goto_definition_works_for_macros); + fn goto_def_for_macros() { + covers!(goto_def_for_macros); check_goto( " //- /lib.rs @@ -349,8 +349,8 @@ mod tests { } #[test] - fn goto_definition_works_for_macros_from_other_crates() { - covers!(goto_definition_works_for_macros); + fn goto_def_for_macros_from_other_crates() { + covers!(goto_def_for_macros); check_goto( " //- /lib.rs @@ -369,7 +369,7 @@ mod tests { } #[test] - fn goto_definition_works_for_macros_in_use_tree() { + fn goto_def_for_macros_in_use_tree() { check_goto( " //- /lib.rs @@ -385,7 +385,7 @@ mod tests { } #[test] - fn goto_definition_works_for_macro_defined_fn_with_arg() { + fn goto_def_for_macro_defined_fn_with_arg() { check_goto( " //- /lib.rs @@ -405,7 +405,7 @@ mod tests { } #[test] - fn goto_definition_works_for_macro_defined_fn_no_arg() { + fn goto_def_for_macro_defined_fn_no_arg() { check_goto( " //- /lib.rs @@ -425,8 +425,8 @@ mod tests { } #[test] - fn goto_definition_works_for_methods() { - covers!(goto_definition_works_for_methods); + fn goto_def_for_methods() { + covers!(goto_def_for_methods); check_goto( " //- /lib.rs @@ -445,8 +445,8 @@ mod tests { } #[test] - fn goto_definition_works_for_fields() { - covers!(goto_definition_works_for_fields); + fn goto_def_for_fields() { + covers!(goto_def_for_fields); check_goto( " //- /lib.rs @@ -464,8 +464,8 @@ mod tests { } #[test] - fn goto_definition_works_for_record_fields() { - covers!(goto_definition_works_for_record_fields); + fn goto_def_for_record_fields() { + covers!(goto_def_for_record_fields); check_goto( " //- /lib.rs @@ -502,7 +502,7 @@ mod tests { } #[test] - fn goto_definition_works_for_ufcs_inherent_methods() { + fn goto_def_for_ufcs_inherent_methods() { check_goto( " //- /lib.rs @@ -521,7 +521,7 @@ mod tests { } #[test] - fn goto_definition_works_for_ufcs_trait_methods_through_traits() { + fn goto_def_for_ufcs_trait_methods_through_traits() { check_goto( " //- /lib.rs @@ -539,7 +539,7 @@ mod tests { } #[test] - fn goto_definition_works_for_ufcs_trait_methods_through_self() { + fn goto_def_for_ufcs_trait_methods_through_self() { check_goto( " //- /lib.rs @@ -654,7 +654,7 @@ mod tests { } #[test] - fn goto_definition_works_when_used_on_definition_name_itself() { + fn goto_def_when_used_on_definition_name_itself() { check_goto( " //- /lib.rs @@ -875,4 +875,21 @@ mod tests { "x", ); } + + #[test] + fn goto_def_for_field_init_shorthand() { + covers!(goto_def_for_field_init_shorthand); + check_goto( + " + //- /lib.rs + struct Foo { x: i32 } + fn main() { + let x = 92; + Foo { x<|> }; + } + ", + "x RECORD_FIELD_DEF FileId(1) [13; 19) [13; 14)", + "x: i32|x", + ) + } } -- cgit v1.2.3 From 4a7e19946a60b4cba6ef9d9916ae0fbec65c74da Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 20 Dec 2019 23:11:07 +0800 Subject: Fix parser for macro call in pattern position --- crates/ra_ide/src/goto_definition.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'crates/ra_ide/src/goto_definition.rs') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 9b5744789..79d332e8c 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -424,6 +424,42 @@ mod tests { ); } + #[test] + fn goto_definition_works_for_macro_inside_pattern() { + check_goto( + " + //- /lib.rs + macro_rules! foo {() => {0}} + + fn bar() { + match (0,1) { + (<|>foo!(), _) => {} + } + } + ", + "foo MACRO_CALL FileId(1) [0; 28) [13; 16)", + "macro_rules! foo {() => {0}}|foo", + ); + } + + #[test] + fn goto_definition_works_for_macro_inside_match_arm_lhs() { + check_goto( + " + //- /lib.rs + macro_rules! foo {() => {0}} + + fn bar() { + match 0 { + <|>foo!() => {} + } + } + ", + "foo MACRO_CALL FileId(1) [0; 28) [13; 16)", + "macro_rules! foo {() => {0}}|foo", + ); + } + #[test] fn goto_def_for_methods() { covers!(goto_def_for_methods); -- cgit v1.2.3