Skip to content

Commit 73684a4

Browse files
committed
Add goto def for enum variant field
1 parent d4a92b4 commit 73684a4

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

crates/ra_ide/src/goto_definition.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,4 +886,23 @@ mod tests {
886886
"x",
887887
)
888888
}
889+
890+
#[test]
891+
fn goto_def_for_enum_variant_field() {
892+
check_goto(
893+
"
894+
//- /lib.rs
895+
enum Foo {
896+
Bar { x: i32 }
897+
}
898+
fn baz(foo: Foo) {
899+
match foo {
900+
Foo::Bar { x<|> } => x
901+
};
902+
}
903+
",
904+
"x RECORD_FIELD_DEF FileId(1) 21..27 21..22",
905+
"x: i32|x",
906+
);
907+
}
889908
}

crates/ra_ide_db/src/defs.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ fn classify_name_inner(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Opti
126126
Some(name_ref_class.definition())
127127
},
128128
ast::BindPat(it) => {
129+
if let Some(record_field_pat) = it.syntax().parent().and_then(ast::RecordFieldPat::cast) {
130+
return Some(Definition::Field(
131+
sema.resolve_record_field_pat(&record_field_pat)?
132+
));
133+
}
134+
129135
let local = sema.to_def(&it)?;
130136
Some(Definition::Local(local))
131137
},

0 commit comments

Comments
 (0)