From f69bf6a12b9e6165ad3e4630d2b10776006b943f Mon Sep 17 00:00:00 2001 From: kjeremy Date: Wed, 24 Apr 2019 12:09:29 -0400 Subject: See through references --- crates/ra_ide_api/src/goto_type_definition.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide_api/src/goto_type_definition.rs b/crates/ra_ide_api/src/goto_type_definition.rs index de2b9d3c3..08ef4a86d 100644 --- a/crates/ra_ide_api/src/goto_type_definition.rs +++ b/crates/ra_ide_api/src/goto_type_definition.rs @@ -30,9 +30,12 @@ pub(crate) fn goto_type_definition( return None; }; - let (adt_def, _) = ty.as_adt()?; - let nav = NavigationTarget::from_adt_def(db, adt_def); + let adt_def = ty.autoderef(db).find_map(|ty| match ty.as_adt() { + Some((adt_def, _)) => Some(adt_def), + None => None, + })?; + let nav = NavigationTarget::from_adt_def(db, adt_def); Some(RangeInfo::new(node.range(), vec![nav])) } @@ -63,4 +66,19 @@ mod tests { "Foo STRUCT_DEF FileId(1) [0; 11) [7; 10)", ); } + + #[test] + fn goto_type_definition_works_simple_ref() { + check_goto( + " + //- /lib.rs + struct Foo; + fn foo() { + let f: &Foo; + f<|> + } + ", + "Foo STRUCT_DEF FileId(1) [0; 11) [7; 10)", + ); + } } -- cgit v1.2.3 From 558bdf73c848eaccf3f274248981f56771c0d5ad Mon Sep 17 00:00:00 2001 From: kjeremy Date: Wed, 24 Apr 2019 14:45:02 -0400 Subject: simplify match --- crates/ra_ide_api/src/goto_type_definition.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide_api/src/goto_type_definition.rs b/crates/ra_ide_api/src/goto_type_definition.rs index 08ef4a86d..e456ec5d6 100644 --- a/crates/ra_ide_api/src/goto_type_definition.rs +++ b/crates/ra_ide_api/src/goto_type_definition.rs @@ -30,10 +30,7 @@ pub(crate) fn goto_type_definition( return None; }; - let adt_def = ty.autoderef(db).find_map(|ty| match ty.as_adt() { - Some((adt_def, _)) => Some(adt_def), - None => None, - })?; + let adt_def = ty.autoderef(db).find_map(|ty| ty.as_adt().map(|adt| adt.0))?; let nav = NavigationTarget::from_adt_def(db, adt_def); Some(RangeInfo::new(node.range(), vec![nav])) -- cgit v1.2.3