add AttrsOwnerEdit::add_attr

This commit is contained in:
DropDemBits 2023-06-24 21:20:57 -04:00
parent c0172333c2
commit 419f641d49
No known key found for this signature in database
GPG Key ID: 7FE02A6C1EDFA075

View File

@ -213,6 +213,28 @@ fn remove_attrs_and_docs(node: &SyntaxNode) {
}
}
}
fn add_attr(&self, attr: ast::Attr) {
add_attr(self.syntax(), attr);
fn add_attr(node: &SyntaxNode, attr: ast::Attr) {
let indent = IndentLevel::from_node(node);
attr.reindent_to(indent);
let after_attrs_and_comments = node
.children_with_tokens()
.find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR))
.map_or(Position::first_child_of(node), |it| Position::before(it));
ted::insert_all(
after_attrs_and_comments,
vec![
attr.syntax().clone().into(),
make::tokens::whitespace(&format!("\n{indent}")).into(),
],
)
}
}
}
impl<T: ast::HasAttrs> AttrsOwnerEdit for T {}