Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/syntax/src/ast/edit_in_place.rs')
| -rw-r--r-- | crates/syntax/src/ast/edit_in_place.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/crates/syntax/src/ast/edit_in_place.rs b/crates/syntax/src/ast/edit_in_place.rs index 2b152a45c9..61580a5cae 100644 --- a/crates/syntax/src/ast/edit_in_place.rs +++ b/crates/syntax/src/ast/edit_in_place.rs @@ -55,6 +55,29 @@ impl GenericParamsOwnerEdit for ast::Fn { } } +impl ast::Fn { + pub fn syntax_editor_get_or_create_generic_param_list( + &self, + editor: &mut SyntaxEditor, + ) -> ast::GenericParamList { + match self.generic_param_list() { + Some(it) => it, + None => { + let position = if let Some(name) = self.name() { + crate::syntax_editor::Position::after(name.syntax) + } else if let Some(fn_token) = self.fn_token() { + crate::syntax_editor::Position::after(fn_token) + } else if let Some(param_list) = self.param_list() { + crate::syntax_editor::Position::before(param_list.syntax) + } else { + crate::syntax_editor::Position::last_child_of(self.syntax()) + }; + syntax_editor_create_generic_param_list(editor, position) + } + } + } +} + impl GenericParamsOwnerEdit for ast::Impl { fn get_or_create_generic_param_list(&self) -> ast::GenericParamList { match self.generic_param_list() { @@ -191,6 +214,15 @@ fn create_generic_param_list(position: Position) -> ast::GenericParamList { gpl } +fn syntax_editor_create_generic_param_list( + editor: &mut SyntaxEditor, + position: crate::syntax_editor::Position, +) -> ast::GenericParamList { + let gpl = make::generic_param_list(empty()).clone_for_update(); + editor.insert(position, gpl.syntax()); + gpl +} + pub trait AttrsOwnerEdit: ast::HasAttrs { fn remove_attrs_and_docs(&self) { remove_attrs_and_docs(self.syntax()); |