@@ -8,7 +8,7 @@ use crate::{
8
8
utils:: { self , DefaultMethods , IgnoreAssocItems } ,
9
9
} ;
10
10
11
- fn insert_impl ( editor : & mut SyntaxEditor , impl_ : & ast:: Impl , nominal : & ast :: Adt ) {
11
+ fn insert_impl ( editor : & mut SyntaxEditor , impl_ : & ast:: Impl , nominal : & impl Indent ) {
12
12
let indent = nominal. indent_level ( ) ;
13
13
14
14
impl_. indent ( indent) ;
@@ -158,6 +158,8 @@ pub(crate) fn generate_impl_trait(acc: &mut Assists, ctx: &AssistContext<'_>) ->
158
158
format ! ( "Generate `{name}` impl for type" ) ,
159
159
target,
160
160
|edit| {
161
+ let mut editor = edit. make_editor ( trait_. syntax ( ) ) ;
162
+
161
163
let holder_arg = ast:: GenericArg :: TypeArg ( make:: type_arg ( make:: ty_placeholder ( ) ) ) ;
162
164
let missing_items = utils:: filter_assoc_items (
163
165
& ctx. sema ,
@@ -182,8 +184,6 @@ pub(crate) fn generate_impl_trait(acc: &mut Assists, ctx: &AssistContext<'_>) ->
182
184
)
183
185
. clone_for_update ( ) ;
184
186
185
- let trait_ = edit. make_mut ( trait_) ;
186
-
187
187
if !missing_items. is_empty ( ) {
188
188
utils:: add_trait_assoc_items_to_impl (
189
189
& ctx. sema ,
@@ -198,26 +198,31 @@ pub(crate) fn generate_impl_trait(acc: &mut Assists, ctx: &AssistContext<'_>) ->
198
198
if let Some ( cap) = ctx. config . snippet_cap {
199
199
if let Some ( generics) = impl_. trait_ ( ) . and_then ( |it| it. generic_arg_list ( ) ) {
200
200
for generic in generics. generic_args ( ) {
201
- edit. add_placeholder_snippet ( cap, generic) ;
201
+ let placeholder = edit. make_placeholder_snippet ( cap) ;
202
+ editor. add_annotation ( generic. syntax ( ) , placeholder) ;
202
203
}
203
204
}
204
205
205
206
if let Some ( ty) = impl_. self_ty ( ) {
206
- edit. add_placeholder_snippet ( cap, ty) ;
207
+ let placeholder = edit. make_placeholder_snippet ( cap) ;
208
+ editor. add_annotation ( ty. syntax ( ) , placeholder) ;
207
209
}
208
210
209
211
if let Some ( expr) =
210
212
impl_. assoc_item_list ( ) . and_then ( |it| it. assoc_items ( ) . find_map ( extract_expr) )
211
213
{
212
- edit. add_tabstop_before ( cap, expr) ;
214
+ let tabstop = edit. make_tabstop_before ( cap) ;
215
+ editor. add_annotation ( expr. syntax ( ) , tabstop) ;
213
216
} else if let Some ( l_curly) =
214
217
impl_. assoc_item_list ( ) . and_then ( |it| it. l_curly_token ( ) )
215
218
{
216
- edit. add_tabstop_after_token ( cap, l_curly) ;
219
+ let tabstop = edit. make_tabstop_after ( cap) ;
220
+ editor. add_annotation ( l_curly, tabstop) ;
217
221
}
218
222
}
219
223
220
- insert_impl ( impl_, & trait_) ;
224
+ insert_impl ( & mut editor, & impl_, & trait_) ;
225
+ edit. add_file_edits ( ctx. vfs_file_id ( ) , editor) ;
221
226
} ,
222
227
)
223
228
}
@@ -755,6 +760,43 @@ mod tests {
755
760
) ;
756
761
}
757
762
763
+ #[ test]
764
+ fn test_add_impl_trait_indent ( ) {
765
+ check_assist (
766
+ generate_impl_trait,
767
+ r#"
768
+ mod foo {
769
+ mod bar {
770
+ trait $0Foo {
771
+ type Output;
772
+
773
+ fn foo(&self) -> Self::Output;
774
+ }
775
+ }
776
+ }
777
+ "# ,
778
+ r#"
779
+ mod foo {
780
+ mod bar {
781
+ trait Foo {
782
+ type Output;
783
+
784
+ fn foo(&self) -> Self::Output;
785
+ }
786
+
787
+ impl Foo for ${1:_} {
788
+ type Output;
789
+
790
+ fn foo(&self) -> Self::Output {
791
+ $0todo!()
792
+ }
793
+ }
794
+ }
795
+ }
796
+ "# ,
797
+ ) ;
798
+ }
799
+
758
800
#[ test]
759
801
fn test_add_impl_trait_empty ( ) {
760
802
check_assist (
0 commit comments