From 4362297a0b25ba4b3993324755c2f57cd846bc8e Mon Sep 17 00:00:00 2001 From: Matt Hooper Date: Mon, 21 Sep 2020 00:38:18 +0100 Subject: Add edit utility for adding an associated item list to a impl def --- crates/syntax/src/ast/edit.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/syntax/src/ast/edit.rs b/crates/syntax/src/ast/edit.rs index 45cf31f13..ceeb0fb4b 100644 --- a/crates/syntax/src/ast/edit.rs +++ b/crates/syntax/src/ast/edit.rs @@ -93,6 +93,22 @@ where } } +impl ast::Impl { + #[must_use] + pub fn with_items(&self, items: ast::AssocItemList) -> ast::Impl { + let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new(); + if let Some(old_items) = self.assoc_item_list() { + let to_replace: SyntaxElement = old_items.syntax().clone().into(); + to_insert.push(items.syntax().clone().into()); + self.replace_children(single_node(to_replace), to_insert) + } else { + to_insert.push(make::tokens::single_space().into()); + to_insert.push(items.syntax().clone().into()); + self.insert_children(InsertPosition::Last, to_insert) + } + } +} + impl ast::AssocItemList { #[must_use] pub fn append_items( -- cgit v1.2.3