Make all kind of braces not applicable in function extraction

This commit is contained in:
AmrDeveloper 2023-04-11 11:22:52 +02:00
parent 2afc124cb9
commit 5ded22065e

View File

@ -70,8 +70,8 @@ pub(crate) fn extract_function(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
} }
let node = ctx.covering_element(); let node = ctx.covering_element();
if node.kind() == SyntaxKind::L_CURLY || node.kind() == SyntaxKind::R_CURLY { if matches!(node.kind(), T!['{'] | T!['}'] | T!['('] | T![')'] | T!['['] | T![']']) {
cov_mark::hit!(extract_function_in_curly_bracket_is_not_applicable); cov_mark::hit!(extract_function_in_braces_is_not_applicable);
return None; return None;
} }
@ -5808,13 +5808,37 @@ fn $0fun_name() -> ControlFlow<()> {
#[test] #[test]
fn in_left_curly_is_not_applicable() { fn in_left_curly_is_not_applicable() {
cov_mark::check!(extract_function_in_curly_bracket_is_not_applicable); cov_mark::check!(extract_function_in_braces_is_not_applicable);
check_assist_not_applicable(extract_function, r"fn foo() { $0}$0 "); check_assist_not_applicable(extract_function, r"fn foo() { $0}$0");
} }
#[test] #[test]
fn in_right_curly_is_not_applicable() { fn in_right_curly_is_not_applicable() {
cov_mark::check!(extract_function_in_curly_bracket_is_not_applicable); cov_mark::check!(extract_function_in_braces_is_not_applicable);
check_assist_not_applicable(extract_function, r"fn foo() $0{$0 } "); check_assist_not_applicable(extract_function, r"fn foo() $0{$0 }");
}
#[test]
fn in_left_paren_is_not_applicable() {
cov_mark::check!(extract_function_in_braces_is_not_applicable);
check_assist_not_applicable(extract_function, r"fn foo( $0)$0 { }");
}
#[test]
fn in_right_paren_is_not_applicable() {
cov_mark::check!(extract_function_in_braces_is_not_applicable);
check_assist_not_applicable(extract_function, r"fn foo $0($0 ) { }");
}
#[test]
fn in_left_brack_is_not_applicable() {
cov_mark::check!(extract_function_in_braces_is_not_applicable);
check_assist_not_applicable(extract_function, r"fn foo(arr: &mut [i32$0]$0) {}");
}
#[test]
fn in_right_brack_is_not_applicable() {
cov_mark::check!(extract_function_in_braces_is_not_applicable);
check_assist_not_applicable(extract_function, r"fn foo(arr: &mut $0[$0i32]) {}");
} }
} }