Unnamed repository; edit this file 'description' to name the repository.
Go to declaration goes to field declaration in pattern and expression shorthands
Lukas Wirth 2022-11-25
parent 3c794a3 · commit ae0bdff
-rw-r--r--crates/ide/src/goto_declaration.rs33
1 files changed, 30 insertions, 3 deletions
diff --git a/crates/ide/src/goto_declaration.rs b/crates/ide/src/goto_declaration.rs
index 5c17b7f415..c7130a2a4b 100644
--- a/crates/ide/src/goto_declaration.rs
+++ b/crates/ide/src/goto_declaration.rs
@@ -36,11 +36,11 @@ pub(crate) fn goto_declaration(
match parent {
ast::NameRef(name_ref) => match NameRefClass::classify(&sema, &name_ref)? {
NameRefClass::Definition(it) => Some(it),
- _ => None
+ NameRefClass::FieldShorthand { field_ref, .. } => return field_ref.try_to_nav(db),
},
ast::Name(name) => match NameClass::classify(&sema, &name)? {
- NameClass::Definition(it) => Some(it),
- _ => None
+ NameClass::Definition(it) | NameClass::ConstReference(it) => Some(it),
+ NameClass::PatFieldShorthand { field_ref, .. } => return field_ref.try_to_nav(db),
},
_ => None
}
@@ -183,4 +183,31 @@ impl Trait for () {
"#,
);
}
+
+ #[test]
+ fn goto_decl_field_pat_shorthand() {
+ check(
+ r#"
+struct Foo { field: u32 }
+ //^^^^^
+fn main() {
+ let Foo { field$0 };
+}
+"#,
+ );
+ }
+
+ #[test]
+ fn goto_decl_constructor_shorthand() {
+ check(
+ r#"
+struct Foo { field: u32 }
+ //^^^^^
+fn main() {
+ let field = 0;
+ Foo { field$0 };
+}
+"#,
+ );
+ }
}