mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 05:53:45 +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
|
@ -79,7 +79,7 @@ fn add_vis_to_referenced_module_def(acc: &mut Assists, ctx: &AssistContext<'_>)
|
||||||
edit.edit_file(target_file);
|
edit.edit_file(target_file);
|
||||||
|
|
||||||
let vis_owner = edit.make_mut(vis_owner);
|
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()) {
|
if let Some((cap, vis)) = ctx.config.snippet_cap.zip(vis_owner.visibility()) {
|
||||||
edit.add_tabstop_before(cap, vis);
|
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);
|
edit.edit_file(target_file);
|
||||||
|
|
||||||
let vis_owner = edit.make_mut(vis_owner);
|
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()) {
|
if let Some((cap, vis)) = ctx.config.snippet_cap.zip(vis_owner.visibility()) {
|
||||||
edit.add_tabstop_before(cap, vis);
|
edit.add_tabstop_before(cap, vis);
|
||||||
|
|
|
@ -1007,20 +1007,24 @@ impl ast::IdentPat {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait HasVisibilityEdit: ast::HasVisibility {
|
pub trait HasVisibilityEdit: ast::HasVisibility {
|
||||||
fn set_visibility(&self, visibility: ast::Visibility) {
|
fn set_visibility(&self, visibility: Option<ast::Visibility>) {
|
||||||
match self.visibility() {
|
if let Some(visibility) = visibility {
|
||||||
Some(current_visibility) => {
|
match self.visibility() {
|
||||||
ted::replace(current_visibility.syntax(), visibility.syntax())
|
Some(current_visibility) => {
|
||||||
}
|
ted::replace(current_visibility.syntax(), visibility.syntax())
|
||||||
None => {
|
}
|
||||||
let vis_before = self
|
None => {
|
||||||
.syntax()
|
let vis_before = self
|
||||||
.children_with_tokens()
|
.syntax()
|
||||||
.find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR))
|
.children_with_tokens()
|
||||||
.unwrap_or_else(|| self.syntax().first_child_or_token().unwrap());
|
.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…
Reference in a new issue