@@ -54,7 +54,11 @@ pub(crate) fn add_format_like_completions(
54
54
if let Ok ( ( out, exprs) ) = parse_format_exprs ( receiver_text. text ( ) ) {
55
55
let exprs = with_placeholders ( exprs) ;
56
56
for ( label, macro_name) in KINDS {
57
- let snippet = format ! ( r#"{macro_name}({out}, {})"# , exprs. join( ", " ) ) ;
57
+ let snippet = if exprs. is_empty ( ) {
58
+ format ! ( r#"{}({})"# , macro_name, out)
59
+ } else {
60
+ format ! ( r#"{}({}, {})"# , macro_name, out, exprs. join( ", " ) )
61
+ } ;
58
62
59
63
postfix_snippet ( label, macro_name, & snippet) . add_to ( acc) ;
60
64
}
@@ -72,10 +76,9 @@ mod tests {
72
76
( "eprintln!" , "{}" , r#"eprintln!("{}", $1)"# ) ,
73
77
(
74
78
"log::info!" ,
75
- "{} {expr } {} {2 + 2}" ,
76
- r#"log::info!("{} {} {} {}", $1, expr , $2, 2 + 2)"# ,
79
+ "{} {ident } {} {2 + 2}" ,
80
+ r#"log::info!("{} {ident } {} {}", $1, $2, 2 + 2)"# ,
77
81
) ,
78
- ( "format!" , "{expr:?}" , r#"format!("{:?}", expr)"# ) ,
79
82
] ;
80
83
81
84
for ( kind, input, output) in test_vector {
@@ -85,4 +88,18 @@ mod tests {
85
88
assert_eq ! ( & snippet, output) ;
86
89
}
87
90
}
91
+
92
+ #[ test]
93
+ fn test_into_suggestion_no_epxrs ( ) {
94
+ let test_vector = & [
95
+ ( "println!" , "{ident}" , r#"println!("{ident}")"# ) ,
96
+ ( "format!" , "{ident:?}" , r#"format!("{ident:?}")"# ) ,
97
+ ] ;
98
+
99
+ for ( kind, input, output) in test_vector {
100
+ let ( parsed_string, _exprs) = parse_format_exprs ( input) . unwrap ( ) ;
101
+ let snippet = format ! ( r#"{}("{}")"# , kind, parsed_string) ;
102
+ assert_eq ! ( & snippet, output) ;
103
+ }
104
+ }
88
105
}
0 commit comments