Skip to content

Commit

Permalink
Merge pull request #19279 from Natural-selection1/master
Browse files Browse the repository at this point in the history
Improve keyword completion for 'let' and 'let mut'
  • Loading branch information
Veykril authored Mar 5, 2025
2 parents 27dc614 + 3ef8a37 commit 4552a34
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
3 changes: 2 additions & 1 deletion crates/ide-completion/src/completions/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ pub(crate) fn complete_expr_path(
add_keyword("false", "false");

if in_condition || in_block_expr {
add_keyword("let", "let");
add_keyword("letm", "let mut $0");
add_keyword("let", "let $0");
}

if after_if_expr {
Expand Down
30 changes: 30 additions & 0 deletions crates/ide-completion/src/completions/keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,34 @@ fn main() {
",
)
}

#[test]
fn completes_let_with_space() {
check_edit(
"let",
r#"
fn main() {
$0
}
"#,
r#"
fn main() {
let $0
}
"#,
);
check_edit(
"letm",
r#"
fn main() {
$0
}
"#,
r#"
fn main() {
let mut $0
}
"#,
);
}
}
14 changes: 14 additions & 0 deletions crates/ide-completion/src/tests/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ impl Unit {
kw if let
kw impl
kw let
kw letm
kw loop
kw match
kw mod
Expand Down Expand Up @@ -247,6 +248,7 @@ fn complete_in_block() {
kw if let
kw impl
kw let
kw letm
kw loop
kw match
kw mod
Expand Down Expand Up @@ -297,6 +299,7 @@ fn complete_after_if_expr() {
kw if let
kw impl
kw let
kw letm
kw loop
kw match
kw mod
Expand Down Expand Up @@ -370,6 +373,7 @@ fn completes_in_loop_ctx() {
kw if let
kw impl
kw let
kw letm
kw loop
kw match
kw mod
Expand Down Expand Up @@ -942,6 +946,7 @@ fn foo() { if foo {} $0 }
kw if let
kw impl
kw let
kw letm
kw loop
kw match
kw mod
Expand Down Expand Up @@ -983,6 +988,7 @@ fn foo() { if foo {} el$0 }
kw if let
kw impl
kw let
kw letm
kw loop
kw match
kw mod
Expand Down Expand Up @@ -1072,6 +1078,7 @@ fn foo() { if foo {} $0 let x = 92; }
kw if let
kw impl
kw let
kw letm
kw loop
kw match
kw mod
Expand Down Expand Up @@ -1113,6 +1120,7 @@ fn foo() { if foo {} el$0 let x = 92; }
kw if let
kw impl
kw let
kw letm
kw loop
kw match
kw mod
Expand Down Expand Up @@ -1154,6 +1162,7 @@ fn foo() { if foo {} el$0 { let x = 92; } }
kw if let
kw impl
kw let
kw letm
kw loop
kw match
kw mod
Expand Down Expand Up @@ -1205,6 +1214,7 @@ pub struct UnstableThisShouldNotBeListed;
kw if let
kw impl
kw let
kw letm
kw loop
kw match
kw mod
Expand Down Expand Up @@ -1258,6 +1268,7 @@ pub struct UnstableButWeAreOnNightlyAnyway;
kw if let
kw impl
kw let
kw letm
kw loop
kw match
kw mod
Expand Down Expand Up @@ -1495,6 +1506,7 @@ fn main() {
kw if let
kw impl
kw let
kw letm
kw loop
kw match
kw mod
Expand Down Expand Up @@ -1945,6 +1957,7 @@ fn bar() {
kw if let
kw impl
kw let
kw letm
kw loop
kw match
kw mod
Expand Down Expand Up @@ -2016,6 +2029,7 @@ fn foo() {
kw if let
kw impl
kw let
kw letm
kw loop
kw match
kw mod
Expand Down
1 change: 1 addition & 0 deletions crates/ide-completion/src/tests/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ fn bar() {
kw if let
kw impl
kw let
kw letm
kw loop
kw match
kw mod
Expand Down
4 changes: 4 additions & 0 deletions crates/ide-completion/src/tests/special.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,7 @@ fn here_we_go() {
kw if let
kw impl
kw let
kw letm
kw loop
kw match
kw mod
Expand Down Expand Up @@ -1059,6 +1060,7 @@ fn here_we_go() {
kw if let
kw impl
kw let
kw letm
kw loop
kw match
kw mod
Expand Down Expand Up @@ -1182,6 +1184,7 @@ fn bar() { qu$0 }
kw if let
kw impl
kw let
kw letm
kw loop
kw match
kw mod
Expand Down Expand Up @@ -1437,6 +1440,7 @@ fn foo() {
kw if let
kw impl
kw let
kw letm
kw loop
kw match
kw mod
Expand Down

0 comments on commit 4552a34

Please sign in to comment.