File tree Expand file tree Collapse file tree 1 file changed +27
-4
lines changed
crates/ide-assists/src/handlers Expand file tree Collapse file tree 1 file changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -121,15 +121,14 @@ pub(crate) fn extract_expressions_from_format_string(
121
121
let mut placeholder_idx = 1 ;
122
122
123
123
for extracted_args in extracted_args {
124
- // remove expr from format string
125
- args. push_str ( ", " ) ;
126
-
127
124
match extracted_args {
128
- Arg :: Ident ( s) | Arg :: Expr ( s) => {
125
+ Arg :: Expr ( s) => {
126
+ args. push_str ( ", " ) ;
129
127
// insert arg
130
128
args. push_str ( & s) ;
131
129
}
132
130
Arg :: Placeholder => {
131
+ args. push_str ( ", " ) ;
133
132
// try matching with existing argument
134
133
match existing_args. next ( ) {
135
134
Some ( ea) => {
@@ -142,6 +141,7 @@ pub(crate) fn extract_expressions_from_format_string(
142
141
}
143
142
}
144
143
}
144
+ Arg :: Ident ( _s) => ( ) ,
145
145
}
146
146
}
147
147
@@ -292,6 +292,29 @@ fn main() {
292
292
fn main() {
293
293
print!("My name is {} {}"$0, stringify!(Paperino), x + x)
294
294
}
295
+ "# ,
296
+ ) ,
297
+ ) ;
298
+ }
299
+
300
+ #[ test]
301
+ fn extract_only_expressions ( ) {
302
+ check_assist (
303
+ extract_expressions_from_format_string,
304
+ & add_macro_decl (
305
+ r#"
306
+ fn main() {
307
+ let var = 1 + 1;
308
+ print!("foobar {var} {var:?} {x$0 + x}")
309
+ }
310
+ "# ,
311
+ ) ,
312
+ & add_macro_decl (
313
+ r#"
314
+ fn main() {
315
+ let var = 1 + 1;
316
+ print!("foobar {var} {var:?} {}"$0, x + x)
317
+ }
295
318
"# ,
296
319
) ,
297
320
) ;
You can’t perform that action at this time.
0 commit comments