Improve the let code snippet

This commit is contained in:
A4-Tacks 2025-05-03 12:45:00 +08:00
parent 429027a40f
commit 1327f70349
No known key found for this signature in database
GPG key ID: 86AC1F526BA06668
2 changed files with 101 additions and 6 deletions

View file

@ -363,9 +363,14 @@ pub(crate) fn complete_expr_path(
add_keyword("true", "true");
add_keyword("false", "false");
if in_condition || in_block_expr {
add_keyword("letm", "let mut $0");
add_keyword("let", "let $0");
if in_condition {
add_keyword("letm", "let mut $1 = $0");
add_keyword("let", "let $1 = $0");
}
if in_block_expr {
add_keyword("letm", "let mut $1 = $2;");
add_keyword("let", "let $1 = $2;");
}
if after_if_expr {

View file

@ -336,7 +336,7 @@ fn main() {
}
#[test]
fn completes_let_with_space() {
fn completes_let_in_block() {
check_edit(
"let",
r#"
@ -346,7 +346,7 @@ fn main() {
"#,
r#"
fn main() {
let $0
let $1 = $2;
}
"#,
);
@ -359,7 +359,97 @@ fn main() {
"#,
r#"
fn main() {
let mut $0
let mut $1 = $2;
}
"#,
);
}
#[test]
fn completes_let_in_condition() {
check_edit(
"let",
r#"
fn main() {
if $0 {}
}
"#,
r#"
fn main() {
if let $1 = $0 {}
}
"#,
);
check_edit(
"letm",
r#"
fn main() {
if $0 {}
}
"#,
r#"
fn main() {
if let mut $1 = $0 {}
}
"#,
);
}
#[test]
fn completes_let_in_no_empty_condition() {
check_edit(
"let",
r#"
fn main() {
if $0x {}
}
"#,
r#"
fn main() {
if let $1 = $0x {}
}
"#,
);
check_edit(
"letm",
r#"
fn main() {
if $0x {}
}
"#,
r#"
fn main() {
if let mut $1 = $0x {}
}
"#,
);
}
#[test]
fn completes_let_in_condition_block() {
check_edit(
"let",
r#"
fn main() {
if { $0 } {}
}
"#,
r#"
fn main() {
if { let $1 = $2; } {}
}
"#,
);
check_edit(
"letm",
r#"
fn main() {
if { $0 } {}
}
"#,
r#"
fn main() {
if { let mut $1 = $2; } {}
}
"#,
);