Skip to content

Commit 707a568

Browse files
Still suggest generating enum methods if the name ref starts with a lowercase letter
1 parent 0ed85be commit 707a568

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub(crate) fn generate_enum_variant(acc: &mut Assists, ctx: &AssistContext) -> O
4242

4343
let name_ref = path.segment()?.name_ref()?;
4444
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
45+
// Don't suggest generating variant if the name starts with a lowercase letter
4646
return None;
4747
}
4848

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

+30-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ fn gen_fn(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
7272
}
7373
Some(hir::PathResolution::Def(hir::ModuleDef::Adt(adt))) => {
7474
if let hir::Adt::Enum(_) = adt {
75-
return None;
75+
// Don't suggest generating function if the name starts with an uppercase letter
76+
if name_ref.text().chars().next()?.is_uppercase() {
77+
return None;
78+
}
7679
}
7780

7881
let current_module = ctx.sema.scope(call.syntax())?.module();
@@ -1755,4 +1758,30 @@ fn main() {
17551758
",
17561759
);
17571760
}
1761+
1762+
#[test]
1763+
fn applicable_for_enum_method() {
1764+
check_assist(
1765+
generate_function,
1766+
r"
1767+
enum Foo {}
1768+
fn main() {
1769+
Foo::new$0();
1770+
}
1771+
",
1772+
r"
1773+
enum Foo {}
1774+
fn main() {
1775+
Foo::new();
1776+
}
1777+
impl Foo {
1778+
1779+
1780+
fn new() ${0:-> _} {
1781+
todo!()
1782+
}
1783+
}
1784+
",
1785+
)
1786+
}
17581787
}

0 commit comments

Comments
 (0)