mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-16 15:14:02 +00:00
Don't suggest enum variant if name_ref start with ASCII lowercase letter
This commit is contained in:
parent
7d716cbeb9
commit
0ed85beb15
1 changed files with 19 additions and 0 deletions
|
@ -41,6 +41,10 @@ pub(crate) fn generate_enum_variant(acc: &mut Assists, ctx: &AssistContext) -> O
|
||||||
}
|
}
|
||||||
|
|
||||||
let name_ref = path.segment()?.name_ref()?;
|
let name_ref = path.segment()?.name_ref()?;
|
||||||
|
if name_ref.text().as_str().chars().next()?.is_ascii_lowercase() {
|
||||||
|
// No need to generate anything if the name starts with a lowercase letter
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(hir::PathResolution::Def(hir::ModuleDef::Adt(hir::Adt::Enum(e)))) =
|
if let Some(hir::PathResolution::Def(hir::ModuleDef::Adt(hir::Adt::Enum(e)))) =
|
||||||
ctx.sema.resolve_path(&path.qualifier()?)
|
ctx.sema.resolve_path(&path.qualifier()?)
|
||||||
|
@ -146,6 +150,21 @@ fn main() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn not_applicable_for_lowercase() {
|
||||||
|
check_assist_not_applicable(
|
||||||
|
generate_enum_variant,
|
||||||
|
r"
|
||||||
|
enum Foo {
|
||||||
|
Bar,
|
||||||
|
}
|
||||||
|
fn main() {
|
||||||
|
Foo::new$0
|
||||||
|
}
|
||||||
|
",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn indentation_level_is_correct() {
|
fn indentation_level_is_correct() {
|
||||||
check_assist(
|
check_assist(
|
||||||
|
|
Loading…
Reference in a new issue