Align set_visibility with the rest of the set_ edit-in-place methods

This commit is contained in:
DropDemBits 2024-02-15 20:40:14 -05:00
parent 581d457e13
commit 115646d7d5
No known key found for this signature in database
GPG key ID: 7FE02A6C1EDFA075
2 changed files with 18 additions and 14 deletions

View file

@ -79,7 +79,7 @@ fn add_vis_to_referenced_module_def(acc: &mut Assists, ctx: &AssistContext<'_>)
edit.edit_file(target_file);
let vis_owner = edit.make_mut(vis_owner);
vis_owner.set_visibility(missing_visibility.clone_for_update());
vis_owner.set_visibility(Some(missing_visibility.clone_for_update()));
if let Some((cap, vis)) = ctx.config.snippet_cap.zip(vis_owner.visibility()) {
edit.add_tabstop_before(cap, vis);
@ -131,7 +131,7 @@ fn add_vis_to_referenced_record_field(acc: &mut Assists, ctx: &AssistContext<'_>
edit.edit_file(target_file);
let vis_owner = edit.make_mut(vis_owner);
vis_owner.set_visibility(missing_visibility.clone_for_update());
vis_owner.set_visibility(Some(missing_visibility.clone_for_update()));
if let Some((cap, vis)) = ctx.config.snippet_cap.zip(vis_owner.visibility()) {
edit.add_tabstop_before(cap, vis);

View file

@ -1007,7 +1007,8 @@ impl ast::IdentPat {
}
pub trait HasVisibilityEdit: ast::HasVisibility {
fn set_visibility(&self, visibility: ast::Visibility) {
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())
@ -1022,6 +1023,9 @@ pub trait HasVisibilityEdit: ast::HasVisibility {
ted::insert(ted::Position::before(vis_before), visibility.syntax());
}
}
} else if let Some(visibility) = self.visibility() {
ted::remove(visibility.syntax());
}
}
}