Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 2afc124

Browse files
committed
Fix allow extracting function from single brace of block expression
1 parent 51d5862 commit 2afc124

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

crates/ide-assists/src/handlers/extract_function.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ pub(crate) fn extract_function(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
7070
}
7171

7272
let node = ctx.covering_element();
73+
if node.kind() == SyntaxKind::L_CURLY || node.kind() == SyntaxKind::R_CURLY {
74+
cov_mark::hit!(extract_function_in_curly_bracket_is_not_applicable);
75+
return None;
76+
}
77+
7378
if node.kind() == COMMENT {
7479
cov_mark::hit!(extract_function_in_comment_is_not_applicable);
7580
return None;
@@ -5800,4 +5805,16 @@ fn $0fun_name() -> ControlFlow<()> {
58005805
"#,
58015806
);
58025807
}
5808+
5809+
#[test]
5810+
fn in_left_curly_is_not_applicable() {
5811+
cov_mark::check!(extract_function_in_curly_bracket_is_not_applicable);
5812+
check_assist_not_applicable(extract_function, r"fn foo() { $0}$0 ");
5813+
}
5814+
5815+
#[test]
5816+
fn in_right_curly_is_not_applicable() {
5817+
cov_mark::check!(extract_function_in_curly_bracket_is_not_applicable);
5818+
check_assist_not_applicable(extract_function, r"fn foo() $0{$0 } ");
5819+
}
58035820
}

0 commit comments

Comments
 (0)