@@ -56,13 +56,37 @@ impl GenericParamsOwnerEdit for ast::Fn {
5656}
5757
5858impl ast:: Fn {
59- pub fn syntax_editor_get_or_create_generic_param_list (
59+ pub fn syntax_editor_add_generic_param (
6060 & self ,
6161 editor : & mut SyntaxEditor ,
62- ) -> ast:: GenericParamList {
62+ new_param : GenericParam ,
63+ ) {
6364 match self . generic_param_list ( ) {
64- Some ( it) => it,
65+ Some ( generic_param_list) => match generic_param_list. generic_params ( ) . last ( ) {
66+ Some ( _last_param) => {
67+ // There exists a generic param list and it's not empty
68+ let mut params = generic_param_list
69+ . generic_params ( )
70+ . map ( |param| param. clone ( ) )
71+ . collect :: < Vec < _ > > ( ) ;
72+ params. push ( new_param. into ( ) ) ;
73+ let new_param_list = make:: generic_param_list ( params) ;
74+ editor. replace (
75+ generic_param_list. syntax ( ) ,
76+ new_param_list. syntax ( ) . clone_for_update ( ) ,
77+ ) ;
78+ }
79+ None => {
80+ // There exists a generic param list but it's empty
81+ let position = crate :: syntax_editor:: Position :: after (
82+ generic_param_list. l_angle_token ( ) . unwrap ( ) ,
83+ ) ;
84+
85+ editor. insert ( position, new_param. syntax ( ) ) ;
86+ }
87+ } ,
6588 None => {
89+ // There was no generic param list
6690 let position = if let Some ( name) = self . name ( ) {
6791 crate :: syntax_editor:: Position :: after ( name. syntax )
6892 } else if let Some ( fn_token) = self . fn_token ( ) {
@@ -72,7 +96,9 @@ impl ast::Fn {
7296 } else {
7397 crate :: syntax_editor:: Position :: last_child_of ( self . syntax ( ) )
7498 } ;
75- syntax_editor_create_generic_param_list ( editor, position)
99+
100+ let new_param_list = make:: generic_param_list ( once ( new_param. clone ( ) ) ) ;
101+ editor. insert ( position, new_param_list. syntax ( ) . clone_for_update ( ) ) ;
76102 }
77103 }
78104 }
@@ -214,15 +240,6 @@ fn create_generic_param_list(position: Position) -> ast::GenericParamList {
214240 gpl
215241}
216242
217- fn syntax_editor_create_generic_param_list (
218- editor : & mut SyntaxEditor ,
219- position : crate :: syntax_editor:: Position ,
220- ) -> ast:: GenericParamList {
221- let gpl = make:: generic_param_list ( empty ( ) ) . clone_for_update ( ) ;
222- editor. insert ( position, gpl. syntax ( ) ) ;
223- gpl
224- }
225-
226243pub trait AttrsOwnerEdit : ast:: HasAttrs {
227244 fn remove_attrs_and_docs ( & self ) {
228245 remove_attrs_and_docs ( self . syntax ( ) ) ;
@@ -290,28 +307,6 @@ impl ast::GenericParamList {
290307 }
291308 }
292309
293- pub fn syntax_editor_add_generic_param (
294- & self ,
295- editor : & mut SyntaxEditor ,
296- new_param : ast:: GenericParam ,
297- ) {
298- match self . generic_params ( ) . last ( ) {
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 ( ) ) ;
306- }
307- None => {
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 ( ) ) ;
311- }
312- }
313- }
314-
315310 /// Removes the existing generic param
316311 pub fn remove_generic_param ( & self , generic_param : ast:: GenericParam ) {
317312 if let Some ( previous) = generic_param. syntax ( ) . prev_sibling ( ) {
0 commit comments