include for in convert to guarded return assist

This commit is contained in:
dfireBird 2024-01-20 19:26:50 +05:30
parent 9d8889cdfc
commit 721e79035d
No known key found for this signature in database
GPG key ID: 26D522CA5FC2B93D

View file

@ -8,7 +8,7 @@ use syntax::{
make, make,
}, },
ted, AstNode, ted, AstNode,
SyntaxKind::{FN, LOOP_EXPR, WHILE_EXPR, WHITESPACE}, SyntaxKind::{FN, FOR_EXPR, LOOP_EXPR, WHILE_EXPR, WHITESPACE},
T, T,
}; };
@ -82,7 +82,7 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext<'
let parent_container = parent_block.syntax().parent()?; let parent_container = parent_block.syntax().parent()?;
let early_expression: ast::Expr = match parent_container.kind() { let early_expression: ast::Expr = match parent_container.kind() {
WHILE_EXPR | LOOP_EXPR => make::expr_continue(None), WHILE_EXPR | LOOP_EXPR | FOR_EXPR => make::expr_continue(None),
FN => make::expr_return(None), FN => make::expr_return(None),
_ => return None, _ => return None,
}; };
@ -426,6 +426,32 @@ fn main() {
); );
} }
#[test]
fn convert_let_inside_for() {
check_assist(
convert_to_guarded_return,
r#"
fn main() {
for n in ns {
if$0 let Some(n) = n {
foo(n);
bar();
}
}
}
"#,
r#"
fn main() {
for n in ns {
let Some(n) = n else { continue };
foo(n);
bar();
}
}
"#,
);
}
#[test] #[test]
fn convert_arbitrary_if_let_patterns() { fn convert_arbitrary_if_let_patterns() {
check_assist( check_assist(