File tree Expand file tree Collapse file tree 2 files changed +101
-6
lines changed
crates/ide-completion/src/completions Expand file tree Collapse file tree 2 files changed +101
-6
lines changed Original file line number Diff line number Diff line change @@ -363,9 +363,14 @@ pub(crate) fn complete_expr_path(
363363 add_keyword ( "true" , "true" ) ;
364364 add_keyword ( "false" , "false" ) ;
365365
366- if in_condition || in_block_expr {
367- add_keyword ( "letm" , "let mut $0" ) ;
368- add_keyword ( "let" , "let $0" ) ;
366+ if in_condition {
367+ add_keyword ( "letm" , "let mut $1 = $0" ) ;
368+ add_keyword ( "let" , "let $1 = $0" ) ;
369+ }
370+
371+ if in_block_expr {
372+ add_keyword ( "letm" , "let mut $1 = $0;" ) ;
373+ add_keyword ( "let" , "let $1 = $0;" ) ;
369374 }
370375
371376 if after_if_expr {
Original file line number Diff line number Diff line change @@ -336,7 +336,7 @@ fn main() {
336336 }
337337
338338 #[ test]
339- fn completes_let_with_space ( ) {
339+ fn completes_let_in_block ( ) {
340340 check_edit (
341341 "let" ,
342342 r#"
@@ -346,7 +346,7 @@ fn main() {
346346"# ,
347347 r#"
348348fn main() {
349- let $0
349+ let $1 = $0;
350350}
351351"# ,
352352 ) ;
@@ -359,7 +359,97 @@ fn main() {
359359"# ,
360360 r#"
361361fn main() {
362- let mut $0
362+ let mut $1 = $0;
363+ }
364+ "# ,
365+ ) ;
366+ }
367+
368+ #[ test]
369+ fn completes_let_in_condition ( ) {
370+ check_edit (
371+ "let" ,
372+ r#"
373+ fn main() {
374+ if $0 {}
375+ }
376+ "# ,
377+ r#"
378+ fn main() {
379+ if let $1 = $0 {}
380+ }
381+ "# ,
382+ ) ;
383+ check_edit (
384+ "letm" ,
385+ r#"
386+ fn main() {
387+ if $0 {}
388+ }
389+ "# ,
390+ r#"
391+ fn main() {
392+ if let mut $1 = $0 {}
393+ }
394+ "# ,
395+ ) ;
396+ }
397+
398+ #[ test]
399+ fn completes_let_in_no_empty_condition ( ) {
400+ check_edit (
401+ "let" ,
402+ r#"
403+ fn main() {
404+ if $0x {}
405+ }
406+ "# ,
407+ r#"
408+ fn main() {
409+ if let $1 = $0x {}
410+ }
411+ "# ,
412+ ) ;
413+ check_edit (
414+ "letm" ,
415+ r#"
416+ fn main() {
417+ if $0x {}
418+ }
419+ "# ,
420+ r#"
421+ fn main() {
422+ if let mut $1 = $0x {}
423+ }
424+ "# ,
425+ ) ;
426+ }
427+
428+ #[ test]
429+ fn completes_let_in_condition_block ( ) {
430+ check_edit (
431+ "let" ,
432+ r#"
433+ fn main() {
434+ if { $0 } {}
435+ }
436+ "# ,
437+ r#"
438+ fn main() {
439+ if { let $1 = $0; } {}
440+ }
441+ "# ,
442+ ) ;
443+ check_edit (
444+ "letm" ,
445+ r#"
446+ fn main() {
447+ if { $0 } {}
448+ }
449+ "# ,
450+ r#"
451+ fn main() {
452+ if { let mut $1 = $0; } {}
363453}
364454"# ,
365455 ) ;
You can’t perform that action at this time.
0 commit comments