Add goto def for enum variant field

This commit is contained in:
unexge 2020-06-06 22:16:59 +03:00
parent d4a92b4fef
commit 73684a4ae2
2 changed files with 25 additions and 0 deletions

View File

@ -886,4 +886,23 @@ mod tests {
"x",
)
}
#[test]
fn goto_def_for_enum_variant_field() {
check_goto(
"
//- /lib.rs
enum Foo {
Bar { x: i32 }
}
fn baz(foo: Foo) {
match foo {
Foo::Bar { x<|> } => x
};
}
",
"x RECORD_FIELD_DEF FileId(1) 21..27 21..22",
"x: i32|x",
);
}
}

View File

@ -126,6 +126,12 @@ fn classify_name_inner(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Opti
Some(name_ref_class.definition())
},
ast::BindPat(it) => {
if let Some(record_field_pat) = it.syntax().parent().and_then(ast::RecordFieldPat::cast) {
return Some(Definition::Field(
sema.resolve_record_field_pat(&record_field_pat)?
));
}
let local = sema.to_def(&it)?;
Some(Definition::Local(local))
},