mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
Add HasVisibilityEdit::set_visibility
This commit is contained in:
parent
27444eda56
commit
8c40fa33df
1 changed files with 21 additions and 0 deletions
|
@ -748,6 +748,27 @@ fn normalize_ws_between_braces(node: &SyntaxNode) -> Option<()> {
|
||||||
Some(())
|
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 {
|
pub trait Indent: AstNode + Clone + Sized {
|
||||||
fn indent_level(&self) -> IndentLevel {
|
fn indent_level(&self) -> IndentLevel {
|
||||||
IndentLevel::from_node(self.syntax())
|
IndentLevel::from_node(self.syntax())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue