From 7d716cbeb984be292802c966f6a858ca5ea29f97 Mon Sep 17 00:00:00 2001 From: Amos Wenger Date: Sat, 21 May 2022 01:32:25 +0200 Subject: [PATCH] Simplify with adt.source() --- .../ide-assists/src/handlers/generate_enum_variant.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/crates/ide-assists/src/handlers/generate_enum_variant.rs b/crates/ide-assists/src/handlers/generate_enum_variant.rs index 98e56a9633e..87800364938 100644 --- a/crates/ide-assists/src/handlers/generate_enum_variant.rs +++ b/crates/ide-assists/src/handlers/generate_enum_variant.rs @@ -59,7 +59,7 @@ fn add_variant_to_accumulator( adt: hir::Enum, name_ref: &ast::NameRef, ) -> Option<()> { - let adt_ast = get_enum_ast(ctx, adt)?; + let adt_ast = adt.source(ctx.db())?.original_ast_node(ctx.db())?.value; let enum_indent_level = IndentLevel::from_node(&adt_ast.syntax()); @@ -80,15 +80,6 @@ fn add_variant_to_accumulator( ) } -fn get_enum_ast(ctx: &AssistContext, adt: hir::Enum) -> Option { - let range = adt.source(ctx.db())?.syntax().original_file_range(ctx.db()); - let file = ctx.sema.parse(range.file_id); - let adt_ast: ast::Enum = - ctx.sema.find_node_at_offset_with_macros(file.syntax(), range.range.start())?; - - Some(adt_ast) -} - #[cfg(test)] mod tests { use crate::tests::{check_assist, check_assist_not_applicable};