mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-02 12:59:12 +00:00
Merge pull request #20682 from A4-Tacks/fix-change-vis-applicable-on-variant
Some checks are pending
metrics / build_metrics (push) Waiting to run
metrics / other_metrics (diesel-1.4.8) (push) Blocked by required conditions
metrics / other_metrics (hyper-0.14.18) (push) Blocked by required conditions
metrics / other_metrics (ripgrep-13.0.0) (push) Blocked by required conditions
metrics / other_metrics (self) (push) Blocked by required conditions
metrics / other_metrics (webrender-2022) (push) Blocked by required conditions
metrics / generate_final_metrics (push) Blocked by required conditions
rustdoc / rustdoc (push) Waiting to run
Some checks are pending
metrics / build_metrics (push) Waiting to run
metrics / other_metrics (diesel-1.4.8) (push) Blocked by required conditions
metrics / other_metrics (hyper-0.14.18) (push) Blocked by required conditions
metrics / other_metrics (ripgrep-13.0.0) (push) Blocked by required conditions
metrics / other_metrics (self) (push) Blocked by required conditions
metrics / other_metrics (webrender-2022) (push) Blocked by required conditions
metrics / generate_final_metrics (push) Blocked by required conditions
rustdoc / rustdoc (push) Waiting to run
Fix applicable on variant field for change_visibility
This commit is contained in:
commit
2268a56350
1 changed files with 14 additions and 0 deletions
|
|
@ -65,11 +65,13 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
|
||||||
if field.visibility().is_some() {
|
if field.visibility().is_some() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
check_is_not_variant(&field)?;
|
||||||
(vis_offset(field.syntax()), field_name.syntax().text_range())
|
(vis_offset(field.syntax()), field_name.syntax().text_range())
|
||||||
} else if let Some(field) = ctx.find_node_at_offset::<ast::TupleField>() {
|
} else if let Some(field) = ctx.find_node_at_offset::<ast::TupleField>() {
|
||||||
if field.visibility().is_some() {
|
if field.visibility().is_some() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
check_is_not_variant(&field)?;
|
||||||
(vis_offset(field.syntax()), field.syntax().text_range())
|
(vis_offset(field.syntax()), field.syntax().text_range())
|
||||||
} else {
|
} else {
|
||||||
return None;
|
return None;
|
||||||
|
|
@ -134,6 +136,11 @@ fn change_vis(acc: &mut Assists, vis: ast::Visibility) -> Option<()> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn check_is_not_variant(field: &impl AstNode) -> Option<()> {
|
||||||
|
let kind = field.syntax().parent()?.parent()?.kind();
|
||||||
|
(kind != SyntaxKind::VARIANT).then_some(())
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target};
|
use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target};
|
||||||
|
|
@ -239,6 +246,13 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn not_applicable_for_enum_variant_fields() {
|
||||||
|
check_assist_not_applicable(change_visibility, r"pub enum Foo { Foo1($0i32) }");
|
||||||
|
|
||||||
|
check_assist_not_applicable(change_visibility, r"pub enum Foo { Foo1 { $0n: i32 } }");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn change_visibility_target() {
|
fn change_visibility_target() {
|
||||||
check_assist_target(change_visibility, "$0fn foo() {}", "fn");
|
check_assist_target(change_visibility, "$0fn foo() {}", "fn");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue