File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
crates/ide-assists/src/handlers Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,9 @@ use crate::{
2727// }
2828// ```
2929pub ( crate ) fn invert_if ( acc : & mut Assists , ctx : & AssistContext < ' _ > ) -> Option < ( ) > {
30- let if_keyword = ctx. find_token_syntax_at_offset ( T ! [ if ] ) ?;
30+ let if_keyword = ctx
31+ . find_token_syntax_at_offset ( T ! [ if ] )
32+ . or_else ( || ctx. find_token_syntax_at_offset ( T ! [ else] ) ) ?;
3133 let expr = ast:: IfExpr :: cast ( if_keyword. parent ( ) ?) ?;
3234 let if_range = if_keyword. text_range ( ) ;
3335 let cursor_in_range = if_range. contains_range ( ctx. selection_trimmed ( ) ) ;
@@ -111,6 +113,15 @@ mod tests {
111113 )
112114 }
113115
116+ #[ test]
117+ fn invert_if_on_else_keyword ( ) {
118+ check_assist (
119+ invert_if,
120+ "fn f() { if cond { 3 * 2 } e$0lse { 1 } }" ,
121+ "fn f() { if !cond { 1 } else { 3 * 2 } }" ,
122+ )
123+ }
124+
114125 #[ test]
115126 fn invert_if_doesnt_apply_with_cursor_not_on_if ( ) {
116127 check_assist_not_applicable ( invert_if, "fn f() { if !$0cond { 3 * 2 } else { 1 } }" )
You can’t perform that action at this time.
0 commit comments