diff options
author | Matt Hooper <[email protected]> | 2020-09-21 00:38:18 +0100 |
---|---|---|
committer | Matt Hooper <[email protected]> | 2020-09-21 00:38:18 +0100 |
commit | 4362297a0b25ba4b3993324755c2f57cd846bc8e (patch) | |
tree | 41d08a1a3d864d14eff0d5c9487ccd6155128881 /crates | |
parent | 82dc4af5dec0d8b4418ee5fda637fa0576884b84 (diff) |
Add edit utility for adding an associated item list to a impl def
Diffstat (limited to 'crates')
-rw-r--r-- | crates/syntax/src/ast/edit.rs | 16 |
1 files changed, 16 insertions, 0 deletions
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 | |||
93 | } | 93 | } |
94 | } | 94 | } |
95 | 95 | ||
96 | impl ast::Impl { | ||
97 | #[must_use] | ||
98 | pub fn with_items(&self, items: ast::AssocItemList) -> ast::Impl { | ||
99 | let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new(); | ||
100 | if let Some(old_items) = self.assoc_item_list() { | ||
101 | let to_replace: SyntaxElement = old_items.syntax().clone().into(); | ||
102 | to_insert.push(items.syntax().clone().into()); | ||
103 | self.replace_children(single_node(to_replace), to_insert) | ||
104 | } else { | ||
105 | to_insert.push(make::tokens::single_space().into()); | ||
106 | to_insert.push(items.syntax().clone().into()); | ||
107 | self.insert_children(InsertPosition::Last, to_insert) | ||
108 | } | ||
109 | } | ||
110 | } | ||
111 | |||
96 | impl ast::AssocItemList { | 112 | impl ast::AssocItemList { |
97 | #[must_use] | 113 | #[must_use] |
98 | pub fn append_items( | 114 | pub fn append_items( |