@@ -13,7 +13,7 @@ use syntax::{
1313 AstNode ,
1414 ast:: {
1515 self , AssocItem , GenericParam , HasAttrs , HasGenericParams , HasName , HasTypeBounds ,
16- HasVisibility , edit:: AstNodeEdit , make ,
16+ HasVisibility , edit:: AstNodeEdit , syntax_factory :: SyntaxFactory ,
1717 } ,
1818 syntax_editor:: Position ,
1919} ;
@@ -73,45 +73,46 @@ pub(crate) fn generate_blanket_trait_impl(
7373 "Generate blanket trait implementation" ,
7474 name. syntax ( ) . text_range ( ) ,
7575 |builder| {
76- let mut edit = builder. make_editor ( traitd. syntax ( ) ) ;
77- let namety = make:: ty_path ( make:: path_from_text ( & name. text ( ) ) ) ;
76+ let mut editor = builder. make_editor ( traitd. syntax ( ) ) ;
77+ let make = SyntaxFactory :: with_mappings ( ) ;
78+ let namety = make. ty_path ( make. path_from_text ( & name. text ( ) ) ) ;
7879 let trait_where_clause = traitd. where_clause ( ) . map ( |it| it. reset_indent ( ) ) ;
79- let bounds = traitd. type_bound_list ( ) . and_then ( exlucde_sized ) ;
80+ let bounds = traitd. type_bound_list ( ) . and_then ( |list| exclude_sized ( & make , list ) ) ;
8081 let is_unsafe = traitd. unsafe_token ( ) . is_some ( ) ;
81- let thisname = this_name ( & traitd) ;
82- let thisty = make:: ty_path ( make:: path_from_text ( & thisname. text ( ) ) ) ;
82+ let thisname = this_name ( & make , & traitd) ;
83+ let thisty = make. ty_path ( make. path_from_text ( & thisname. text ( ) ) ) ;
8384 let indent = traitd. indent_level ( ) ;
8485
85- let gendecl = make:: generic_param_list ( [ GenericParam :: TypeParam ( make:: type_param (
86+ let gendecl = make. generic_param_list ( [ GenericParam :: TypeParam ( make. type_param (
8687 thisname. clone ( ) ,
87- apply_sized ( has_sized ( & traitd, & ctx. sema ) , bounds) ,
88+ apply_sized ( & make , has_sized ( & traitd, & ctx. sema ) , bounds) ,
8889 ) ) ] ) ;
8990
9091 let trait_gen_args =
9192 traitd. generic_param_list ( ) . map ( |param_list| param_list. to_generic_args ( ) ) ;
9293
93- let impl_ = make:: impl_trait (
94+ let impl_ = make. impl_trait (
9495 cfg_attrs ( & traitd) ,
9596 is_unsafe,
9697 traitd. generic_param_list ( ) ,
9798 trait_gen_args,
9899 Some ( gendecl) ,
99100 None ,
100101 false ,
101- namety,
102- thisty. clone ( ) ,
102+ namety. into ( ) ,
103+ thisty. into ( ) ,
103104 trait_where_clause,
104105 None ,
105106 None ,
106- )
107- . clone_for_update ( ) ;
107+ ) ;
108108
109109 if let Some ( trait_assoc_list) = traitd. assoc_item_list ( ) {
110- let assoc_item_list = impl_. get_or_create_assoc_item_list ( ) ;
110+ let assoc_item_list =
111+ impl_. get_or_create_assoc_item_list_with_editor ( & mut editor, & make) ;
111112 for item in trait_assoc_list. assoc_items ( ) {
112113 let item = match item {
113114 ast:: AssocItem :: Fn ( method) if method. body ( ) . is_none ( ) => {
114- todo_fn ( & method, ctx. config ) . into ( )
115+ todo_fn ( & make , & method, ctx. config ) . into ( )
115116 }
116117 ast:: AssocItem :: Const ( _) | ast:: AssocItem :: TypeAlias ( _) => item,
117118 _ => continue ,
@@ -122,10 +123,10 @@ pub(crate) fn generate_blanket_trait_impl(
122123
123124 let impl_ = impl_. indent ( indent) ;
124125
125- edit . insert_all (
126+ editor . insert_all (
126127 Position :: after ( traitd. syntax ( ) ) ,
127128 vec ! [
128- make:: tokens :: whitespace( & format!( "\n \n {indent}" ) ) . into( ) ,
129+ make. whitespace( & format!( "\n \n {indent}" ) ) . into( ) ,
129130 impl_. syntax( ) . clone( ) . into( ) ,
130131 ] ,
131132 ) ;
@@ -136,7 +137,8 @@ pub(crate) fn generate_blanket_trait_impl(
136137 builder. add_tabstop_before ( cap, self_ty) ;
137138 }
138139
139- builder. add_file_edits ( ctx. vfs_file_id ( ) , edit) ;
140+ editor. add_mappings ( make. finish_with_mappings ( ) ) ;
141+ builder. add_file_edits ( ctx. vfs_file_id ( ) , editor) ;
140142 } ,
141143 ) ;
142144
@@ -212,22 +214,26 @@ fn where_clause_sized(where_clause: Option<ast::WhereClause>) -> Option<bool> {
212214 } )
213215}
214216
215- fn apply_sized ( has_sized : bool , bounds : Option < ast:: TypeBoundList > ) -> Option < ast:: TypeBoundList > {
217+ fn apply_sized (
218+ make : & SyntaxFactory ,
219+ has_sized : bool ,
220+ bounds : Option < ast:: TypeBoundList > ,
221+ ) -> Option < ast:: TypeBoundList > {
216222 if has_sized {
217223 return bounds;
218224 }
219225 let bounds = bounds
220226 . into_iter ( )
221227 . flat_map ( |bounds| bounds. bounds ( ) )
222- . chain ( [ make:: type_bound_text ( "?Sized" ) ] ) ;
223- make:: type_bound_list ( bounds)
228+ . chain ( [ make. type_bound_text ( "?Sized" ) ] ) ;
229+ make. type_bound_list ( bounds)
224230}
225231
226- fn exlucde_sized ( bounds : ast:: TypeBoundList ) -> Option < ast:: TypeBoundList > {
227- make:: type_bound_list ( bounds. bounds ( ) . filter ( |bound| !ty_bound_is ( bound, "Sized" ) ) )
232+ fn exclude_sized ( make : & SyntaxFactory , bounds : ast:: TypeBoundList ) -> Option < ast:: TypeBoundList > {
233+ make. type_bound_list ( bounds. bounds ( ) . filter ( |bound| !ty_bound_is ( bound, "Sized" ) ) )
228234}
229235
230- fn this_name ( traitd : & ast:: Trait ) -> ast:: Name {
236+ fn this_name ( make : & SyntaxFactory , traitd : & ast:: Trait ) -> ast:: Name {
231237 let has_iter = find_bound ( "Iterator" , traitd. type_bound_list ( ) ) . is_some ( ) ;
232238
233239 let params = traitd
@@ -245,7 +251,7 @@ fn this_name(traitd: &ast::Trait) -> ast::Name {
245251 let mut name_gen =
246252 suggest_name:: NameGenerator :: new_with_names ( params. iter ( ) . map ( String :: as_str) ) ;
247253
248- make:: name ( & name_gen. suggest_name ( if has_iter { "I" } else { "T" } ) )
254+ make. name ( & name_gen. suggest_name ( if has_iter { "I" } else { "T" } ) )
249255}
250256
251257fn find_bound ( s : & str , bounds : Option < ast:: TypeBoundList > ) -> Option < ast:: TypeBound > {
@@ -260,16 +266,16 @@ fn ty_bound_is(bound: &ast::TypeBound, s: &str) -> bool {
260266 . is_some_and( |name| name. text( ) == s) )
261267}
262268
263- fn todo_fn ( f : & ast:: Fn , config : & AssistConfig ) -> ast:: Fn {
264- let params = f. param_list ( ) . unwrap_or_else ( || make:: param_list ( None , None ) ) ;
265- make:: fn_ (
269+ fn todo_fn ( make : & SyntaxFactory , f : & ast:: Fn , config : & AssistConfig ) -> ast:: Fn {
270+ let params = f. param_list ( ) . unwrap_or_else ( || make. param_list ( None , None ) ) ;
271+ make. fn_ (
266272 cfg_attrs ( f) ,
267273 f. visibility ( ) ,
268- f. name ( ) . unwrap_or_else ( || make:: name ( "unnamed" ) ) ,
274+ f. name ( ) . unwrap_or_else ( || make. name ( "unnamed" ) ) ,
269275 f. generic_param_list ( ) ,
270276 f. where_clause ( ) ,
271277 params,
272- make:: block_expr ( None , Some ( crate :: utils:: expr_fill_default ( config) ) ) ,
278+ make. block_expr ( None , Some ( crate :: utils:: expr_fill_default ( config) ) ) ,
273279 f. ret_type ( ) ,
274280 f. async_token ( ) . is_some ( ) ,
275281 f. const_token ( ) . is_some ( ) ,
0 commit comments