diff --git a/crates/syntax/src/ast/edit_in_place.rs b/crates/syntax/src/ast/edit_in_place.rs index 61580a5cae..9a5c122e27 100644 --- a/crates/syntax/src/ast/edit_in_place.rs +++ b/crates/syntax/src/ast/edit_in_place.rs @@ -293,22 +293,21 @@ impl ast::GenericParamList { pub fn syntax_editor_add_generic_param( &self, editor: &mut SyntaxEditor, - generic_param: ast::GenericParam, + new_param: ast::GenericParam, ) { match self.generic_params().last() { - Some(last_param) => { - let position = crate::syntax_editor::Position::after(last_param.syntax()); - let elements = vec![ - make::token(T![,]).into(), - make::tokens::single_space().into(), - generic_param.syntax().clone().into(), - ]; - editor.insert_all(position, elements); + Some(_) => { + let mut params = + self.generic_params().map(|param| param.clone()).collect::>(); + params.push(new_param.into()); + let new_param_list = make::generic_param_list(params); + + editor.replace(self.syntax(), new_param_list.syntax()); } None => { - let after_l_angle = - crate::syntax_editor::Position::after(self.l_angle_token().unwrap()); - editor.insert(after_l_angle, generic_param.syntax()); + let position = crate::syntax_editor::Position::after(self.l_angle_token().unwrap()); + let new_param_list = make::generic_param_list(once(new_param.clone())); + editor.insert(position, new_param_list.syntax()); } } }