@@ -293,22 +293,21 @@ impl ast::GenericParamList {
293293 pub fn syntax_editor_add_generic_param (
294294 & self ,
295295 editor : & mut SyntaxEditor ,
296- generic_param : ast:: GenericParam ,
296+ new_param : ast:: GenericParam ,
297297 ) {
298298 match self . generic_params ( ) . last ( ) {
299- Some ( last_param) => {
300- let position = crate :: syntax_editor:: Position :: after ( last_param. syntax ( ) ) ;
301- let elements = vec ! [
302- make:: token( T ![ , ] ) . into( ) ,
303- make:: tokens:: single_space( ) . into( ) ,
304- generic_param. syntax( ) . clone( ) . into( ) ,
305- ] ;
306- editor. insert_all ( position, elements) ;
299+ Some ( _) => {
300+ let mut params =
301+ self . generic_params ( ) . map ( |param| param. clone ( ) ) . collect :: < Vec < _ > > ( ) ;
302+ params. push ( new_param. into ( ) ) ;
303+ let new_param_list = make:: generic_param_list ( params) ;
304+
305+ editor. replace ( self . syntax ( ) , new_param_list. syntax ( ) ) ;
307306 }
308307 None => {
309- let after_l_angle =
310- crate :: syntax_editor :: Position :: after ( self . l_angle_token ( ) . unwrap ( ) ) ;
311- editor. insert ( after_l_angle , generic_param . syntax ( ) ) ;
308+ let position = crate :: syntax_editor :: Position :: after ( self . l_angle_token ( ) . unwrap ( ) ) ;
309+ let new_param_list = make :: generic_param_list ( once ( new_param . clone ( ) ) ) ;
310+ editor. insert ( position , new_param_list . syntax ( ) ) ;
312311 }
313312 }
314313 }
0 commit comments