Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/syntax/src/syntax_editor/edits.rs')
-rw-r--r--crates/syntax/src/syntax_editor/edits.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/crates/syntax/src/syntax_editor/edits.rs b/crates/syntax/src/syntax_editor/edits.rs
index 840e769797..9090f7c9eb 100644
--- a/crates/syntax/src/syntax_editor/edits.rs
+++ b/crates/syntax/src/syntax_editor/edits.rs
@@ -153,6 +153,23 @@ impl ast::VariantList {
}
}
+impl ast::Fn {
+ pub fn replace_or_insert_body(&self, editor: &mut SyntaxEditor, body: ast::BlockExpr) {
+ if let Some(old_body) = self.body() {
+ editor.replace(old_body.syntax(), body.syntax());
+ } else {
+ let single_space = make::tokens::single_space();
+ let elements = vec![single_space.into(), body.syntax().clone().into()];
+
+ if let Some(semicolon) = self.semicolon_token() {
+ editor.replace_with_many(semicolon, elements);
+ } else {
+ editor.insert_all(Position::last_child_of(self.syntax()), elements);
+ }
+ }
+ }
+}
+
fn normalize_ws_between_braces(editor: &mut SyntaxEditor, node: &SyntaxNode) -> Option<()> {
let make = SyntaxFactory::without_mappings();
let l = node
@@ -184,6 +201,15 @@ pub trait Removable: AstNode {
fn remove(&self, editor: &mut SyntaxEditor);
}
+impl Removable for ast::TypeBoundList {
+ fn remove(&self, editor: &mut SyntaxEditor) {
+ match self.syntax().siblings_with_tokens(Direction::Prev).find(|it| it.kind() == T![:]) {
+ Some(colon) => editor.delete_all(colon..=self.syntax().clone().into()),
+ None => editor.delete(self.syntax()),
+ }
+ }
+}
+
impl Removable for ast::Use {
fn remove(&self, editor: &mut SyntaxEditor) {
let make = SyntaxFactory::without_mappings();