mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Align set_visibility
with the rest of the set_
edit-in-place methods
This commit is contained in:
parent
581d457e13
commit
115646d7d5
2 changed files with 18 additions and 14 deletions
|
@ -1007,20 +1007,24 @@ impl ast::IdentPat {
|
|||
}
|
||||
|
||||
pub trait HasVisibilityEdit: ast::HasVisibility {
|
||||
fn set_visibility(&self, visibility: ast::Visibility) {
|
||||
match self.visibility() {
|
||||
Some(current_visibility) => {
|
||||
ted::replace(current_visibility.syntax(), visibility.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());
|
||||
fn set_visibility(&self, visibility: Option<ast::Visibility>) {
|
||||
if let Some(visibility) = visibility {
|
||||
match self.visibility() {
|
||||
Some(current_visibility) => {
|
||||
ted::replace(current_visibility.syntax(), visibility.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), visibility.syntax());
|
||||
ted::insert(ted::Position::before(vis_before), visibility.syntax());
|
||||
}
|
||||
}
|
||||
} else if let Some(visibility) = self.visibility() {
|
||||
ted::remove(visibility.syntax());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue