Add HasVisibilityEdit::set_visibility

This commit is contained in:
DropDemBits 2023-07-09 20:50:20 -04:00
parent 27444eda56
commit 8c40fa33df
No known key found for this signature in database
GPG Key ID: 7FE02A6C1EDFA075

View File

@ -748,6 +748,27 @@ fn normalize_ws_between_braces(node: &SyntaxNode) -> Option<()> {
Some(())
}
pub trait HasVisibilityEdit: ast::HasVisibility {
fn set_visibility(&self, visbility: ast::Visibility) {
match self.visibility() {
Some(current_visibility) => {
ted::replace(current_visibility.syntax(), visbility.syntax())
}
None => {
let vis_before = self
.syntax()
.children_with_tokens()
.find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR))
.unwrap_or_else(|| self.syntax().first_child_or_token().unwrap());
ted::insert(ted::Position::before(vis_before), visbility.syntax());
}
}
}
}
impl<T: ast::HasVisibility> HasVisibilityEdit for T {}
pub trait Indent: AstNode + Clone + Sized {
fn indent_level(&self) -> IndentLevel {
IndentLevel::from_node(self.syntax())