From 468b80485644bf1b15dee97d15029378f0f6d199 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 9 Oct 2020 02:57:35 +0200 Subject: Fix source_to_def for named enum variant fields --- crates/hir/src/semantics/source_to_def.rs | 4 ++++ crates/ide/src/references.rs | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/crates/hir/src/semantics/source_to_def.rs b/crates/hir/src/semantics/source_to_def.rs index 5918b9541..66fc11611 100644 --- a/crates/hir/src/semantics/source_to_def.rs +++ b/crates/hir/src/semantics/source_to_def.rs @@ -189,6 +189,10 @@ impl SourceToDefCtx<'_, '_> { let def = self.type_alias_to_def(container.with_value(it))?; def.into() }, + ast::Variant(it) => { + let def = self.enum_variant_to_def(container.with_value(it))?; + VariantId::from(def).into() + }, _ => continue, } }; diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index e0830eb4f..ae68b4392 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs @@ -405,6 +405,23 @@ enum Foo { ); } + #[test] + fn test_find_all_refs_enum_var_field() { + check( + r#" +enum Foo { + A, + B { field<|>: u8 }, + C, +} +"#, + expect![[r#" + field RECORD_FIELD FileId(0) 26..35 26..31 Other + + "#]], + ); + } + #[test] fn test_find_all_refs_two_modules() { check( -- cgit v1.2.3