Unnamed repository; edit this file 'description' to name the repository.
add get_or_create_assoc_item_list editor variant
bit-aloo 6 weeks ago
parent 32ab058 · commit 8e7bc26
-rw-r--r--crates/syntax/src/syntax_editor/edits.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/crates/syntax/src/syntax_editor/edits.rs b/crates/syntax/src/syntax_editor/edits.rs
index 8c842be49d..d741adb6e3 100644
--- a/crates/syntax/src/syntax_editor/edits.rs
+++ b/crates/syntax/src/syntax_editor/edits.rs
@@ -229,6 +229,25 @@ impl ast::AssocItemList {
}
}
+impl ast::Impl {
+ pub fn get_or_create_assoc_item_list_with_editor(
+ &self,
+ editor: &mut SyntaxEditor,
+ make: &SyntaxFactory,
+ ) -> ast::AssocItemList {
+ if let Some(list) = self.assoc_item_list() {
+ list
+ } else {
+ let list = make.assoc_item_list_empty();
+ editor.insert_all(
+ Position::last_child_of(self.syntax()),
+ vec![make.whitespace(" ").into(), list.syntax().clone().into()],
+ );
+ list
+ }
+ }
+}
+
impl ast::VariantList {
pub fn add_variant(&self, editor: &mut SyntaxEditor, variant: &ast::Variant) {
let make = SyntaxFactory::without_mappings();