@@ -3,7 +3,8 @@ use ide_db::assists::AssistId;
33use syntax:: {
44 AstNode , AstToken , SyntaxKind , T ,
55 ast:: {
6- self , HasDocComments , HasGenericParams , HasName , HasVisibility , edit:: AstNodeEdit , make,
6+ self , HasDocComments , HasGenericParams , HasName , HasVisibility , edit:: AstNodeEdit ,
7+ syntax_factory:: SyntaxFactory ,
78 } ,
89 syntax_editor:: { Position , SyntaxEditor } ,
910} ;
@@ -112,7 +113,7 @@ pub(crate) fn generate_trait_from_impl(acc: &mut Assists, ctx: &AssistContext<'_
112113 let make = editor. make ( ) ;
113114 let trait_ast = make. trait_ (
114115 false ,
115- & trait_name ( & impl_assoc_items) . text ( ) ,
116+ & trait_name ( & impl_assoc_items, make ) . text ( ) ,
116117 impl_ast. generic_param_list ( ) ,
117118 impl_ast. where_clause ( ) ,
118119 trait_items,
@@ -124,9 +125,9 @@ pub(crate) fn generate_trait_from_impl(acc: &mut Assists, ctx: &AssistContext<'_
124125 // Change `impl Foo` to `impl NewTrait for Foo`
125126 let mut elements = vec ! [
126127 trait_name_ref. syntax( ) . clone( ) . into( ) ,
127- make:: tokens :: single_space ( ) . into( ) ,
128- make:: token( T ![ for ] ) . into( ) ,
129- make:: tokens :: single_space ( ) . into( ) ,
128+ make. whitespace ( " " ) . into( ) ,
129+ make. token( T ![ for ] ) . into( ) ,
130+ make. whitespace ( " " ) . into( ) ,
130131 ] ;
131132
132133 if let Some ( params) = impl_ast. generic_param_list ( ) {
@@ -146,7 +147,7 @@ pub(crate) fn generate_trait_from_impl(acc: &mut Assists, ctx: &AssistContext<'_
146147 Position :: before ( impl_ast. syntax ( ) ) ,
147148 vec ! [
148149 trait_ast. syntax( ) . clone( ) . into( ) ,
149- make:: tokens :: whitespace( & format!( "\n \n {}" , impl_ast. indent_level( ) ) ) . into( ) ,
150+ make. whitespace( & format!( "\n \n {}" , impl_ast. indent_level( ) ) ) . into( ) ,
150151 ] ,
151152 ) ;
152153
@@ -163,16 +164,16 @@ pub(crate) fn generate_trait_from_impl(acc: &mut Assists, ctx: &AssistContext<'_
163164 Some ( ( ) )
164165}
165166
166- fn trait_name ( items : & ast:: AssocItemList ) -> ast:: Name {
167+ fn trait_name ( items : & ast:: AssocItemList , make : & SyntaxFactory ) -> ast:: Name {
167168 let mut fn_names = items
168169 . assoc_items ( )
169170 . filter_map ( |x| if let ast:: AssocItem :: Fn ( f) = x { f. name ( ) } else { None } ) ;
170171 fn_names
171172 . next ( )
172173 . and_then ( |name| {
173- fn_names. next ( ) . is_none ( ) . then ( || make:: name ( & stdx:: to_camel_case ( & name. text ( ) ) ) )
174+ fn_names. next ( ) . is_none ( ) . then ( || make. name ( & stdx:: to_camel_case ( & name. text ( ) ) ) )
174175 } )
175- . unwrap_or_else ( || make:: name ( "NewTrait" ) )
176+ . unwrap_or_else ( || make. name ( "NewTrait" ) )
176177}
177178
178179/// `E0449` Trait items always share the visibility of their trait
@@ -202,6 +203,7 @@ fn remove_doc_comments(editor: &SyntaxEditor, item: &ast::AssocItem) {
202203}
203204
204205fn strip_body ( editor : & SyntaxEditor , item : & ast:: AssocItem ) {
206+ let make = editor. make ( ) ;
205207 if let ast:: AssocItem :: Fn ( f) = item
206208 && let Some ( body) = f. body ( )
207209 {
@@ -213,7 +215,7 @@ fn strip_body(editor: &SyntaxEditor, item: &ast::AssocItem) {
213215 editor. delete ( prev) ;
214216 }
215217
216- editor. replace ( body. syntax ( ) , make:: tokens :: semicolon ( ) ) ;
218+ editor. replace ( body. syntax ( ) , make. token ( T ! [ ; ] ) ) ;
217219 } ;
218220}
219221
0 commit comments