mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 07:44:10 +00:00
Add HasVisibilityEdit::set_visibility
This commit is contained in:
parent
27444eda56
commit
8c40fa33df
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user