From 73684a4ae2ff5251bbff35109d2c9ad40fe4ef01 Mon Sep 17 00:00:00 2001 From: unexge Date: Sat, 6 Jun 2020 22:16:59 +0300 Subject: Add goto def for enum variant field --- crates/ra_ide/src/goto_definition.rs | 19 +++++++++++++++++++ crates/ra_ide_db/src/defs.rs | 6 ++++++ 2 files changed, 25 insertions(+) (limited to 'crates') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index a6c86e99c..693344c31 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -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", + ); + } } diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs index 1db60b87f..52233937c 100644 --- a/crates/ra_ide_db/src/defs.rs +++ b/crates/ra_ide_db/src/defs.rs @@ -126,6 +126,12 @@ fn classify_name_inner(sema: &Semantics, 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)) }, -- cgit v1.2.3