From 2afc124cb9a06bf404f1f6299d76f5d24f2a16b2 Mon Sep 17 00:00:00 2001 From: AmrDeveloper Date: Sun, 9 Apr 2023 23:44:31 +0200 Subject: [PATCH] Fix allow extracting function from single brace of block expression --- .../src/handlers/extract_function.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crates/ide-assists/src/handlers/extract_function.rs b/crates/ide-assists/src/handlers/extract_function.rs index 0b90c9ba34f..ced1aec7f84 100644 --- a/crates/ide-assists/src/handlers/extract_function.rs +++ b/crates/ide-assists/src/handlers/extract_function.rs @@ -70,6 +70,11 @@ pub(crate) fn extract_function(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op } let node = ctx.covering_element(); + if node.kind() == SyntaxKind::L_CURLY || node.kind() == SyntaxKind::R_CURLY { + cov_mark::hit!(extract_function_in_curly_bracket_is_not_applicable); + return None; + } + if node.kind() == COMMENT { cov_mark::hit!(extract_function_in_comment_is_not_applicable); return None; @@ -5800,4 +5805,16 @@ fn $0fun_name() -> ControlFlow<()> { "#, ); } + + #[test] + fn in_left_curly_is_not_applicable() { + cov_mark::check!(extract_function_in_curly_bracket_is_not_applicable); + check_assist_not_applicable(extract_function, r"fn foo() { $0}$0 "); + } + + #[test] + fn in_right_curly_is_not_applicable() { + cov_mark::check!(extract_function_in_curly_bracket_is_not_applicable); + check_assist_not_applicable(extract_function, r"fn foo() $0{$0 } "); + } }