Merge pull request #19735 from A4-Tacks/improve-let-snippet

Improve the let code snippet
This commit is contained in:
Lukas Wirth 2025-05-04 04:06:56 +00:00 committed by GitHub
commit bfb717ac09
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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 = $0;");
add_keyword("let", "let $1 = $0;");
}
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 = $0;
}
"#,
);
@ -359,7 +359,97 @@ fn main() {
"#,
r#"
fn main() {
let mut $0
let mut $1 = $0;
}
"#,
);
}
#[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 = $0; } {}
}
"#,
);
check_edit(
"letm",
r#"
fn main() {
if { $0 } {}
}
"#,
r#"
fn main() {
if { let mut $1 = $0; } {}
}
"#,
);