diff --git a/crates/ide-assists/src/handlers/generate_enum_variant.rs b/crates/ide-assists/src/handlers/generate_enum_variant.rs index c68b587ad1..3b28a9639c 100644 --- a/crates/ide-assists/src/handlers/generate_enum_variant.rs +++ b/crates/ide-assists/src/handlers/generate_enum_variant.rs @@ -42,7 +42,7 @@ pub(crate) fn generate_enum_variant(acc: &mut Assists, ctx: &AssistContext) -> O 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 + // Don't suggest generating variant if the name starts with a lowercase letter return None; } diff --git a/crates/ide-assists/src/handlers/generate_function.rs b/crates/ide-assists/src/handlers/generate_function.rs index e3ef321d4b..7077dc9e5c 100644 --- a/crates/ide-assists/src/handlers/generate_function.rs +++ b/crates/ide-assists/src/handlers/generate_function.rs @@ -72,7 +72,10 @@ fn gen_fn(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { } Some(hir::PathResolution::Def(hir::ModuleDef::Adt(adt))) => { if let hir::Adt::Enum(_) = adt { - return None; + // Don't suggest generating function if the name starts with an uppercase letter + if name_ref.text().chars().next()?.is_uppercase() { + return None; + } } let current_module = ctx.sema.scope(call.syntax())?.module(); @@ -1755,4 +1758,30 @@ fn main() { ", ); } + + #[test] + fn applicable_for_enum_method() { + check_assist( + generate_function, + r" +enum Foo {} +fn main() { + Foo::new$0(); +} +", + r" +enum Foo {} +fn main() { + Foo::new(); +} +impl Foo { + + +fn new() ${0:-> _} { + todo!() +} +} +", + ) + } }