Skip to content

Commit 363297d

Browse files
authored
Merge pull request #19279 from Natural-selection1/master
Improve keyword completion for 'let' and 'let mut'
2 parents b9f5453 + 5421fba commit 363297d

File tree

5 files changed

+51
-1
lines changed

5 files changed

+51
-1
lines changed

src/tools/rust-analyzer/crates/ide-completion/src/completions/expr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ pub(crate) fn complete_expr_path(
365365
add_keyword("false", "false");
366366

367367
if in_condition || in_block_expr {
368-
add_keyword("let", "let");
368+
add_keyword("letm", "let mut $0");
369+
add_keyword("let", "let $0");
369370
}
370371

371372
if after_if_expr {

src/tools/rust-analyzer/crates/ide-completion/src/completions/keyword.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,4 +330,34 @@ fn main() {
330330
",
331331
)
332332
}
333+
334+
#[test]
335+
fn completes_let_with_space() {
336+
check_edit(
337+
"let",
338+
r#"
339+
fn main() {
340+
$0
341+
}
342+
"#,
343+
r#"
344+
fn main() {
345+
let $0
346+
}
347+
"#,
348+
);
349+
check_edit(
350+
"letm",
351+
r#"
352+
fn main() {
353+
$0
354+
}
355+
"#,
356+
r#"
357+
fn main() {
358+
let mut $0
359+
}
360+
"#,
361+
);
362+
}
333363
}

src/tools/rust-analyzer/crates/ide-completion/src/tests/expression.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ impl Unit {
170170
kw if let
171171
kw impl
172172
kw let
173+
kw letm
173174
kw loop
174175
kw match
175176
kw mod
@@ -247,6 +248,7 @@ fn complete_in_block() {
247248
kw if let
248249
kw impl
249250
kw let
251+
kw letm
250252
kw loop
251253
kw match
252254
kw mod
@@ -297,6 +299,7 @@ fn complete_after_if_expr() {
297299
kw if let
298300
kw impl
299301
kw let
302+
kw letm
300303
kw loop
301304
kw match
302305
kw mod
@@ -370,6 +373,7 @@ fn completes_in_loop_ctx() {
370373
kw if let
371374
kw impl
372375
kw let
376+
kw letm
373377
kw loop
374378
kw match
375379
kw mod
@@ -942,6 +946,7 @@ fn foo() { if foo {} $0 }
942946
kw if let
943947
kw impl
944948
kw let
949+
kw letm
945950
kw loop
946951
kw match
947952
kw mod
@@ -983,6 +988,7 @@ fn foo() { if foo {} el$0 }
983988
kw if let
984989
kw impl
985990
kw let
991+
kw letm
986992
kw loop
987993
kw match
988994
kw mod
@@ -1072,6 +1078,7 @@ fn foo() { if foo {} $0 let x = 92; }
10721078
kw if let
10731079
kw impl
10741080
kw let
1081+
kw letm
10751082
kw loop
10761083
kw match
10771084
kw mod
@@ -1113,6 +1120,7 @@ fn foo() { if foo {} el$0 let x = 92; }
11131120
kw if let
11141121
kw impl
11151122
kw let
1123+
kw letm
11161124
kw loop
11171125
kw match
11181126
kw mod
@@ -1154,6 +1162,7 @@ fn foo() { if foo {} el$0 { let x = 92; } }
11541162
kw if let
11551163
kw impl
11561164
kw let
1165+
kw letm
11571166
kw loop
11581167
kw match
11591168
kw mod
@@ -1205,6 +1214,7 @@ pub struct UnstableThisShouldNotBeListed;
12051214
kw if let
12061215
kw impl
12071216
kw let
1217+
kw letm
12081218
kw loop
12091219
kw match
12101220
kw mod
@@ -1258,6 +1268,7 @@ pub struct UnstableButWeAreOnNightlyAnyway;
12581268
kw if let
12591269
kw impl
12601270
kw let
1271+
kw letm
12611272
kw loop
12621273
kw match
12631274
kw mod
@@ -1495,6 +1506,7 @@ fn main() {
14951506
kw if let
14961507
kw impl
14971508
kw let
1509+
kw letm
14981510
kw loop
14991511
kw match
15001512
kw mod
@@ -1945,6 +1957,7 @@ fn bar() {
19451957
kw if let
19461958
kw impl
19471959
kw let
1960+
kw letm
19481961
kw loop
19491962
kw match
19501963
kw mod
@@ -2016,6 +2029,7 @@ fn foo() {
20162029
kw if let
20172030
kw impl
20182031
kw let
2032+
kw letm
20192033
kw loop
20202034
kw match
20212035
kw mod

src/tools/rust-analyzer/crates/ide-completion/src/tests/item.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ fn bar() {
285285
kw if let
286286
kw impl
287287
kw let
288+
kw letm
288289
kw loop
289290
kw match
290291
kw mod

src/tools/rust-analyzer/crates/ide-completion/src/tests/special.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,7 @@ fn here_we_go() {
10091009
kw if let
10101010
kw impl
10111011
kw let
1012+
kw letm
10121013
kw loop
10131014
kw match
10141015
kw mod
@@ -1059,6 +1060,7 @@ fn here_we_go() {
10591060
kw if let
10601061
kw impl
10611062
kw let
1063+
kw letm
10621064
kw loop
10631065
kw match
10641066
kw mod
@@ -1182,6 +1184,7 @@ fn bar() { qu$0 }
11821184
kw if let
11831185
kw impl
11841186
kw let
1187+
kw letm
11851188
kw loop
11861189
kw match
11871190
kw mod
@@ -1437,6 +1440,7 @@ fn foo() {
14371440
kw if let
14381441
kw impl
14391442
kw let
1443+
kw letm
14401444
kw loop
14411445
kw match
14421446
kw mod

0 commit comments

Comments
 (0)