@@ -4,7 +4,8 @@ use itertools::Itertools;
4
4
use syntax:: {
5
5
SyntaxKind ,
6
6
ast:: { self , AstNode , HasAttrs , HasGenericParams , HasVisibility } ,
7
- match_ast, ted,
7
+ match_ast,
8
+ syntax_editor:: { Position , SyntaxEditor } ,
8
9
} ;
9
10
10
11
use crate :: { AssistContext , AssistId , Assists , assist_context:: SourceChangeBuilder } ;
@@ -97,11 +98,14 @@ fn edit_struct_def(
97
98
// Note that we don't need to consider macro files in this function because this is
98
99
// currently not triggered for struct definitions inside macro calls.
99
100
let tuple_fields = record_fields. fields ( ) . filter_map ( |f| {
100
- let field = ast:: make:: tuple_field ( f. visibility ( ) , f. ty ( ) ?) . clone_for_update ( ) ;
101
- ted:: insert_all (
102
- ted:: Position :: first_child_of ( field. syntax ( ) ) ,
101
+ let field = ast:: make:: tuple_field ( f. visibility ( ) , f. ty ( ) ?) ;
102
+ let mut editor = SyntaxEditor :: new ( field. syntax ( ) . clone ( ) ) ;
103
+ editor. insert_all (
104
+ Position :: first_child_of ( field. syntax ( ) ) ,
103
105
f. attrs ( ) . map ( |attr| attr. syntax ( ) . clone_subtree ( ) . clone_for_update ( ) . into ( ) ) . collect ( ) ,
104
106
) ;
107
+ let field_syntax = editor. finish ( ) . new_root ( ) . clone ( ) ;
108
+ let field = ast:: TupleField :: cast ( field_syntax) ?;
105
109
Some ( field)
106
110
} ) ;
107
111
let tuple_fields = ast:: make:: tuple_field_list ( tuple_fields) ;
@@ -1086,8 +1090,7 @@ pub struct $0Foo {
1086
1090
}
1087
1091
"# ,
1088
1092
r#"
1089
- pub struct Foo(#[my_custom_attr]
1090
- u32);
1093
+ pub struct Foo(#[my_custom_attr]u32);
1091
1094
"# ,
1092
1095
) ;
1093
1096
}
0 commit comments