@@ -25,7 +25,7 @@ use crate::{AssistContext, AssistId, Assists};
25
25
// ->
26
26
// ```
27
27
// mod m {
28
- // pub (crate) fn frobnicate() {}
28
+ // $0pub (crate) fn frobnicate() {}
29
29
// }
30
30
// fn main() {
31
31
// m::frobnicate() {}
@@ -62,10 +62,12 @@ fn add_vis_to_referenced_module_def(acc: &mut Assists, ctx: &AssistContext) -> O
62
62
Some ( name) => format ! ( "Change visibility of {} to {}" , name, missing_visibility) ,
63
63
} ;
64
64
65
- acc. add ( AssistId ( "fix_visibility" ) , assist_label, target, |edit| {
66
- edit. set_file ( target_file) ;
67
- edit. insert ( offset, format ! ( "{} " , missing_visibility) ) ;
68
- edit. set_cursor ( offset) ;
65
+ acc. add ( AssistId ( "fix_visibility" ) , assist_label, target, |builder| {
66
+ builder. set_file ( target_file) ;
67
+ match ctx. config . snippet_cap {
68
+ Some ( cap) => builder. insert_snippet ( cap, offset, format ! ( "$0{} " , missing_visibility) ) ,
69
+ None => builder. insert ( offset, format ! ( "{} " , missing_visibility) ) ,
70
+ }
69
71
} )
70
72
}
71
73
@@ -103,10 +105,12 @@ fn add_vis_to_referenced_record_field(acc: &mut Assists, ctx: &AssistContext) ->
103
105
let assist_label =
104
106
format ! ( "Change visibility of {}.{} to {}" , parent_name, target_name, missing_visibility) ;
105
107
106
- acc. add ( AssistId ( "fix_visibility" ) , assist_label, target, |edit| {
107
- edit. set_file ( target_file) ;
108
- edit. insert ( offset, format ! ( "{} " , missing_visibility) ) ;
109
- edit. set_cursor ( offset)
108
+ acc. add ( AssistId ( "fix_visibility" ) , assist_label, target, |builder| {
109
+ builder. set_file ( target_file) ;
110
+ match ctx. config . snippet_cap {
111
+ Some ( cap) => builder. insert_snippet ( cap, offset, format ! ( "$0{} " , missing_visibility) ) ,
112
+ None => builder. insert ( offset, format ! ( "{} " , missing_visibility) ) ,
113
+ }
110
114
} )
111
115
}
112
116
@@ -196,7 +200,7 @@ mod tests {
196
200
fix_visibility,
197
201
r"mod foo { fn foo() {} }
198
202
fn main() { foo::foo<|>() } " ,
199
- r"mod foo { <|>pub (crate) fn foo() {} }
203
+ r"mod foo { $0pub (crate) fn foo() {} }
200
204
fn main() { foo::foo() } " ,
201
205
) ;
202
206
check_assist_not_applicable (
@@ -212,7 +216,7 @@ mod tests {
212
216
fix_visibility,
213
217
r"mod foo { struct Foo; }
214
218
fn main() { foo::Foo<|> } " ,
215
- r"mod foo { <|>pub (crate) struct Foo; }
219
+ r"mod foo { $0pub (crate) struct Foo; }
216
220
fn main() { foo::Foo } " ,
217
221
) ;
218
222
check_assist_not_applicable (
@@ -224,7 +228,7 @@ mod tests {
224
228
fix_visibility,
225
229
r"mod foo { enum Foo; }
226
230
fn main() { foo::Foo<|> } " ,
227
- r"mod foo { <|>pub (crate) enum Foo; }
231
+ r"mod foo { $0pub (crate) enum Foo; }
228
232
fn main() { foo::Foo } " ,
229
233
) ;
230
234
check_assist_not_applicable (
@@ -236,7 +240,7 @@ mod tests {
236
240
fix_visibility,
237
241
r"mod foo { union Foo; }
238
242
fn main() { foo::Foo<|> } " ,
239
- r"mod foo { <|>pub (crate) union Foo; }
243
+ r"mod foo { $0pub (crate) union Foo; }
240
244
fn main() { foo::Foo } " ,
241
245
) ;
242
246
check_assist_not_applicable (
@@ -258,7 +262,7 @@ mod tests {
258
262
//- /foo.rs
259
263
struct Foo;
260
264
" ,
261
- r"<|>pub (crate) struct Foo;
265
+ r"$0pub (crate) struct Foo;
262
266
263
267
" ,
264
268
) ;
@@ -270,7 +274,7 @@ mod tests {
270
274
fix_visibility,
271
275
r"mod foo { pub struct Foo { bar: (), } }
272
276
fn main() { foo::Foo { <|>bar: () }; } " ,
273
- r"mod foo { pub struct Foo { <|>pub (crate) bar: (), } }
277
+ r"mod foo { pub struct Foo { $0pub (crate) bar: (), } }
274
278
fn main() { foo::Foo { bar: () }; } " ,
275
279
) ;
276
280
check_assist (
@@ -281,7 +285,7 @@ mod tests {
281
285
//- /foo.rs
282
286
pub struct Foo { bar: () }
283
287
" ,
284
- r"pub struct Foo { <|>pub (crate) bar: () }
288
+ r"pub struct Foo { $0pub (crate) bar: () }
285
289
286
290
" ,
287
291
) ;
@@ -307,7 +311,7 @@ mod tests {
307
311
fix_visibility,
308
312
r"mod foo { pub enum Foo { Bar { bar: () } } }
309
313
fn main() { foo::Foo::Bar { <|>bar: () }; } " ,
310
- r"mod foo { pub enum Foo { Bar { <|>pub (crate) bar: () } } }
314
+ r"mod foo { pub enum Foo { Bar { $0pub (crate) bar: () } } }
311
315
fn main() { foo::Foo::Bar { bar: () }; } " ,
312
316
) ;
313
317
check_assist (
@@ -318,7 +322,7 @@ mod tests {
318
322
//- /foo.rs
319
323
pub enum Foo { Bar { bar: () } }
320
324
" ,
321
- r"pub enum Foo { Bar { <|>pub (crate) bar: () } }
325
+ r"pub enum Foo { Bar { $0pub (crate) bar: () } }
322
326
323
327
" ,
324
328
) ;
@@ -346,7 +350,7 @@ mod tests {
346
350
fix_visibility,
347
351
r"mod foo { pub union Foo { bar: (), } }
348
352
fn main() { foo::Foo { <|>bar: () }; } " ,
349
- r"mod foo { pub union Foo { <|>pub (crate) bar: (), } }
353
+ r"mod foo { pub union Foo { $0pub (crate) bar: (), } }
350
354
fn main() { foo::Foo { bar: () }; } " ,
351
355
) ;
352
356
check_assist (
@@ -357,7 +361,7 @@ mod tests {
357
361
//- /foo.rs
358
362
pub union Foo { bar: () }
359
363
" ,
360
- r"pub union Foo { <|>pub (crate) bar: () }
364
+ r"pub union Foo { $0pub (crate) bar: () }
361
365
362
366
" ,
363
367
) ;
@@ -383,7 +387,7 @@ mod tests {
383
387
fix_visibility,
384
388
r"mod foo { const FOO: () = (); }
385
389
fn main() { foo::FOO<|> } " ,
386
- r"mod foo { <|>pub (crate) const FOO: () = (); }
390
+ r"mod foo { $0pub (crate) const FOO: () = (); }
387
391
fn main() { foo::FOO } " ,
388
392
) ;
389
393
check_assist_not_applicable (
@@ -399,7 +403,7 @@ mod tests {
399
403
fix_visibility,
400
404
r"mod foo { static FOO: () = (); }
401
405
fn main() { foo::FOO<|> } " ,
402
- r"mod foo { <|>pub (crate) static FOO: () = (); }
406
+ r"mod foo { $0pub (crate) static FOO: () = (); }
403
407
fn main() { foo::FOO } " ,
404
408
) ;
405
409
check_assist_not_applicable (
@@ -415,7 +419,7 @@ mod tests {
415
419
fix_visibility,
416
420
r"mod foo { trait Foo { fn foo(&self) {} } }
417
421
fn main() { let x: &dyn foo::<|>Foo; } " ,
418
- r"mod foo { <|>pub (crate) trait Foo { fn foo(&self) {} } }
422
+ r"mod foo { $0pub (crate) trait Foo { fn foo(&self) {} } }
419
423
fn main() { let x: &dyn foo::Foo; } " ,
420
424
) ;
421
425
check_assist_not_applicable (
@@ -431,7 +435,7 @@ mod tests {
431
435
fix_visibility,
432
436
r"mod foo { type Foo = (); }
433
437
fn main() { let x: foo::Foo<|>; } " ,
434
- r"mod foo { <|>pub (crate) type Foo = (); }
438
+ r"mod foo { $0pub (crate) type Foo = (); }
435
439
fn main() { let x: foo::Foo; } " ,
436
440
) ;
437
441
check_assist_not_applicable (
@@ -447,7 +451,7 @@ mod tests {
447
451
fix_visibility,
448
452
r"mod foo { mod bar { fn bar() {} } }
449
453
fn main() { foo::bar<|>::bar(); } " ,
450
- r"mod foo { <|>pub (crate) mod bar { fn bar() {} } }
454
+ r"mod foo { $0pub (crate) mod bar { fn bar() {} } }
451
455
fn main() { foo::bar::bar(); } " ,
452
456
) ;
453
457
@@ -463,7 +467,7 @@ mod tests {
463
467
pub fn baz() {}
464
468
}
465
469
" ,
466
- r"<|>pub (crate) mod bar {
470
+ r"$0pub (crate) mod bar {
467
471
pub fn baz() {}
468
472
}
469
473
@@ -493,7 +497,7 @@ mod tests {
493
497
pub fn baz() {}
494
498
}
495
499
" ,
496
- r"<|>pub (crate) mod bar;
500
+ r"$0pub (crate) mod bar;
497
501
" ,
498
502
) ;
499
503
}
@@ -510,7 +514,7 @@ mod tests {
510
514
mod bar {
511
515
pub fn baz() {}
512
516
}" ,
513
- r"<|>pub (crate) mod bar {
517
+ r"$0pub (crate) mod bar {
514
518
pub fn baz() {}
515
519
}
516
520
" ,
@@ -525,7 +529,7 @@ mod tests {
525
529
foo::Bar<|>
526
530
//- /lib.rs crate:foo
527
531
struct Bar;" ,
528
- r"<|>pub struct Bar;
532
+ r"$0pub struct Bar;
529
533
" ,
530
534
)
531
535
}
@@ -545,7 +549,7 @@ mod tests {
545
549
" ,
546
550
r"
547
551
mod foo {
548
- <|>pub (crate) use bar::Baz;
552
+ $0pub (crate) use bar::Baz;
549
553
mod bar { pub(super) struct Baz; }
550
554
}
551
555
foo::Baz
0 commit comments