Skip to content

Commit 8c40fa3

Browse files
committed
Add HasVisibilityEdit::set_visibility
1 parent 27444ed commit 8c40fa3

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

crates/syntax/src/ast/edit_in_place.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,27 @@ fn normalize_ws_between_braces(node: &SyntaxNode) -> Option<()> {
748748
Some(())
749749
}
750750

751+
pub trait HasVisibilityEdit: ast::HasVisibility {
752+
fn set_visibility(&self, visbility: ast::Visibility) {
753+
match self.visibility() {
754+
Some(current_visibility) => {
755+
ted::replace(current_visibility.syntax(), visbility.syntax())
756+
}
757+
None => {
758+
let vis_before = self
759+
.syntax()
760+
.children_with_tokens()
761+
.find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR))
762+
.unwrap_or_else(|| self.syntax().first_child_or_token().unwrap());
763+
764+
ted::insert(ted::Position::before(vis_before), visbility.syntax());
765+
}
766+
}
767+
}
768+
}
769+
770+
impl<T: ast::HasVisibility> HasVisibilityEdit for T {}
771+
751772
pub trait Indent: AstNode + Clone + Sized {
752773
fn indent_level(&self) -> IndentLevel {
753774
IndentLevel::from_node(self.syntax())

0 commit comments

Comments
 (0)