mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 06:23:25 +00:00
Still suggest generating enum methods if the name ref starts with a lowercase letter
This commit is contained in:
parent
0ed85beb15
commit
707a5683b1
2 changed files with 31 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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!()
|
||||
}
|
||||
}
|
||||
",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue