Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 419f641

Browse files
committed
add AttrsOwnerEdit::add_attr
1 parent c017233 commit 419f641

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

crates/syntax/src/ast/edit_in_place.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,28 @@ pub trait AttrsOwnerEdit: ast::HasAttrs {
213213
}
214214
}
215215
}
216+
217+
fn add_attr(&self, attr: ast::Attr) {
218+
add_attr(self.syntax(), attr);
219+
220+
fn add_attr(node: &SyntaxNode, attr: ast::Attr) {
221+
let indent = IndentLevel::from_node(node);
222+
attr.reindent_to(indent);
223+
224+
let after_attrs_and_comments = node
225+
.children_with_tokens()
226+
.find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR))
227+
.map_or(Position::first_child_of(node), |it| Position::before(it));
228+
229+
ted::insert_all(
230+
after_attrs_and_comments,
231+
vec![
232+
attr.syntax().clone().into(),
233+
make::tokens::whitespace(&format!("\n{indent}")).into(),
234+
],
235+
)
236+
}
237+
}
216238
}
217239

218240
impl<T: ast::HasAttrs> AttrsOwnerEdit for T {}

0 commit comments

Comments
 (0)