Skip to content

Commit 0ed85be

Browse files
Don't suggest enum variant if name_ref start with ASCII lowercase letter
1 parent 7d716cb commit 0ed85be

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

crates/ide-assists/src/handlers/generate_enum_variant.rs

+19
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ pub(crate) fn generate_enum_variant(acc: &mut Assists, ctx: &AssistContext) -> O
4141
}
4242

4343
let name_ref = path.segment()?.name_ref()?;
44+
if name_ref.text().as_str().chars().next()?.is_ascii_lowercase() {
45+
// No need to generate anything if the name starts with a lowercase letter
46+
return None;
47+
}
4448

4549
if let Some(hir::PathResolution::Def(hir::ModuleDef::Adt(hir::Adt::Enum(e)))) =
4650
ctx.sema.resolve_path(&path.qualifier()?)
@@ -146,6 +150,21 @@ fn main() {
146150
)
147151
}
148152

153+
#[test]
154+
fn not_applicable_for_lowercase() {
155+
check_assist_not_applicable(
156+
generate_enum_variant,
157+
r"
158+
enum Foo {
159+
Bar,
160+
}
161+
fn main() {
162+
Foo::new$0
163+
}
164+
",
165+
)
166+
}
167+
149168
#[test]
150169
fn indentation_level_is_correct() {
151170
check_assist(

0 commit comments

Comments
 (0)