@@ -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 matches ! ( node. kind( ) , T ![ '{' ] | T ![ '}' ] | T ![ '(' ] | T ![ ')' ] | T ![ '[' ] | T ![ ']' ] ) {
74+ cov_mark:: hit!( extract_function_in_braces_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,40 @@ 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_braces_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_braces_is_not_applicable) ;
5818+ check_assist_not_applicable ( extract_function, r"fn foo() $0{$0 }" ) ;
5819+ }
5820+
5821+ #[ test]
5822+ fn in_left_paren_is_not_applicable ( ) {
5823+ cov_mark:: check!( extract_function_in_braces_is_not_applicable) ;
5824+ check_assist_not_applicable ( extract_function, r"fn foo( $0)$0 { }" ) ;
5825+ }
5826+
5827+ #[ test]
5828+ fn in_right_paren_is_not_applicable ( ) {
5829+ cov_mark:: check!( extract_function_in_braces_is_not_applicable) ;
5830+ check_assist_not_applicable ( extract_function, r"fn foo $0($0 ) { }" ) ;
5831+ }
5832+
5833+ #[ test]
5834+ fn in_left_brack_is_not_applicable ( ) {
5835+ cov_mark:: check!( extract_function_in_braces_is_not_applicable) ;
5836+ check_assist_not_applicable ( extract_function, r"fn foo(arr: &mut [i32$0]$0) {}" ) ;
5837+ }
5838+
5839+ #[ test]
5840+ fn in_right_brack_is_not_applicable ( ) {
5841+ cov_mark:: check!( extract_function_in_braces_is_not_applicable) ;
5842+ check_assist_not_applicable ( extract_function, r"fn foo(arr: &mut $0[$0i32]) {}" ) ;
5843+ }
58035844}
0 commit comments