@@ -11,7 +11,7 @@ use ra_syntax::{
1111use crate :: {
1212 assist_context:: { AssistContext , Assists } ,
1313 ast_transform:: { self , AstTransform , QualifyPaths , SubstituteTypeParams } ,
14- utils:: { get_missing_assoc_items, resolve_target_trait} ,
14+ utils:: { get_missing_assoc_items, render_snippet , resolve_target_trait, Cursor } ,
1515 AssistId ,
1616} ;
1717
@@ -45,7 +45,7 @@ enum AddMissingImplMembersMode {
4545// }
4646//
4747// impl Trait<u32> for () {
48- // fn foo(&self) -> u32 {
48+ // $0fn foo(&self) -> u32 {
4949// todo!()
5050// }
5151//
@@ -89,7 +89,7 @@ pub(crate) fn add_missing_impl_members(acc: &mut Assists, ctx: &AssistContext) -
8989// impl Trait for () {
9090// Type X = ();
9191// fn foo(&self) {}
92- // fn bar(&self) {}
92+ // $0fn bar(&self) {}
9393//
9494// }
9595// ```
@@ -147,7 +147,7 @@ fn add_missing_impl_members_inner(
147147 }
148148
149149 let target = impl_def. syntax ( ) . text_range ( ) ;
150- acc. add ( AssistId ( assist_id) , label, target, |edit | {
150+ acc. add ( AssistId ( assist_id) , label, target, |builder | {
151151 let n_existing_items = impl_item_list. assoc_items ( ) . count ( ) ;
152152 let source_scope = ctx. sema . scope_for_def ( trait_) ;
153153 let target_scope = ctx. sema . scope ( impl_item_list. syntax ( ) ) ;
@@ -162,13 +162,21 @@ fn add_missing_impl_members_inner(
162162 } )
163163 . map ( |it| edit:: remove_attrs_and_docs ( & it) ) ;
164164 let new_impl_item_list = impl_item_list. append_items ( items) ;
165- let cursor_position = {
166- let first_new_item = new_impl_item_list. assoc_items ( ) . nth ( n_existing_items) . unwrap ( ) ;
167- first_new_item. syntax ( ) . text_range ( ) . start ( )
165+ let first_new_item = new_impl_item_list. assoc_items ( ) . nth ( n_existing_items) . unwrap ( ) ;
166+
167+ let original_range = impl_item_list. syntax ( ) . text_range ( ) ;
168+ match ctx. config . snippet_cap {
169+ None => builder. replace ( original_range, new_impl_item_list. to_string ( ) ) ,
170+ Some ( cap) => builder. replace_snippet (
171+ cap,
172+ original_range,
173+ render_snippet (
174+ cap,
175+ new_impl_item_list. syntax ( ) ,
176+ Cursor :: Before ( first_new_item. syntax ( ) ) ,
177+ ) ,
178+ ) ,
168179 } ;
169-
170- edit. replace_ast ( impl_item_list, new_impl_item_list) ;
171- edit. set_cursor ( cursor_position) ;
172180 } )
173181}
174182
@@ -222,7 +230,7 @@ struct S;
222230
223231impl Foo for S {
224232 fn bar(&self) {}
225- <|>type Output;
233+ $0type Output;
226234 const CONST: usize = 42;
227235 fn foo(&self) {
228236 todo!()
@@ -263,7 +271,7 @@ struct S;
263271
264272impl Foo for S {
265273 fn bar(&self) {}
266- <|>fn foo(&self) {
274+ $0fn foo(&self) {
267275 todo!()
268276 }
269277
@@ -283,7 +291,7 @@ impl Foo for S { <|> }"#,
283291trait Foo { fn foo(&self); }
284292struct S;
285293impl Foo for S {
286- <|>fn foo(&self) {
294+ $0fn foo(&self) {
287295 todo!()
288296 }
289297}"# ,
@@ -302,7 +310,7 @@ impl Foo<u32> for S { <|> }"#,
302310trait Foo<T> { fn foo(&self, t: T) -> &T; }
303311struct S;
304312impl Foo<u32> for S {
305- <|>fn foo(&self, t: u32) -> &u32 {
313+ $0fn foo(&self, t: u32) -> &u32 {
306314 todo!()
307315 }
308316}"# ,
@@ -321,7 +329,7 @@ impl<U> Foo<U> for S { <|> }"#,
321329trait Foo<T> { fn foo(&self, t: T) -> &T; }
322330struct S;
323331impl<U> Foo<U> for S {
324- <|>fn foo(&self, t: U) -> &U {
332+ $0fn foo(&self, t: U) -> &U {
325333 todo!()
326334 }
327335}"# ,
@@ -340,7 +348,7 @@ impl Foo for S {}<|>"#,
340348trait Foo { fn foo(&self); }
341349struct S;
342350impl Foo for S {
343- <|>fn foo(&self) {
351+ $0fn foo(&self) {
344352 todo!()
345353 }
346354}"# ,
@@ -365,7 +373,7 @@ mod foo {
365373}
366374struct S;
367375impl foo::Foo for S {
368- <|>fn foo(&self, bar: foo::Bar) {
376+ $0fn foo(&self, bar: foo::Bar) {
369377 todo!()
370378 }
371379}"# ,
@@ -390,7 +398,7 @@ mod foo {
390398}
391399struct S;
392400impl foo::Foo for S {
393- <|>fn foo(&self, bar: foo::Bar<u32>) {
401+ $0fn foo(&self, bar: foo::Bar<u32>) {
394402 todo!()
395403 }
396404}"# ,
@@ -415,7 +423,7 @@ mod foo {
415423}
416424struct S;
417425impl foo::Foo<u32> for S {
418- <|>fn foo(&self, bar: foo::Bar<u32>) {
426+ $0fn foo(&self, bar: foo::Bar<u32>) {
419427 todo!()
420428 }
421429}"# ,
@@ -443,7 +451,7 @@ mod foo {
443451struct Param;
444452struct S;
445453impl foo::Foo<Param> for S {
446- <|>fn foo(&self, bar: Param) {
454+ $0fn foo(&self, bar: Param) {
447455 todo!()
448456 }
449457}"# ,
@@ -470,7 +478,7 @@ mod foo {
470478}
471479struct S;
472480impl foo::Foo for S {
473- <|>fn foo(&self, bar: foo::Bar<u32>::Assoc) {
481+ $0fn foo(&self, bar: foo::Bar<u32>::Assoc) {
474482 todo!()
475483 }
476484}"# ,
@@ -497,7 +505,7 @@ mod foo {
497505}
498506struct S;
499507impl foo::Foo for S {
500- <|>fn foo(&self, bar: foo::Bar<foo::Baz>) {
508+ $0fn foo(&self, bar: foo::Bar<foo::Baz>) {
501509 todo!()
502510 }
503511}"# ,
@@ -522,7 +530,7 @@ mod foo {
522530}
523531struct S;
524532impl foo::Foo for S {
525- <|>fn foo(&self, bar: dyn Fn(u32) -> i32) {
533+ $0fn foo(&self, bar: dyn Fn(u32) -> i32) {
526534 todo!()
527535 }
528536}"# ,
@@ -580,7 +588,7 @@ trait Foo {
580588}
581589struct S;
582590impl Foo for S {
583- <|>type Output;
591+ $0type Output;
584592 fn foo(&self) {
585593 todo!()
586594 }
@@ -614,7 +622,7 @@ trait Foo {
614622}
615623struct S;
616624impl Foo for S {
617- <|>fn valid(some: u32) -> bool { false }
625+ $0fn valid(some: u32) -> bool { false }
618626}"# ,
619627 )
620628 }
@@ -637,7 +645,7 @@ trait Foo<T = Self> {
637645
638646struct S;
639647impl Foo for S {
640- <|>fn bar(&self, other: &Self) {
648+ $0fn bar(&self, other: &Self) {
641649 todo!()
642650 }
643651}"# ,
@@ -662,7 +670,7 @@ trait Foo<T1, T2 = Self> {
662670
663671struct S<T>;
664672impl Foo<T> for S<T> {
665- <|>fn bar(&self, this: &T, that: &Self) {
673+ $0fn bar(&self, this: &T, that: &Self) {
666674 todo!()
667675 }
668676}"# ,
0 commit comments