mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Generate enum variant assist
This also disables "generate function" when what we clearly want is to generate an enum variant. Co-authored-by: Maarten Flippo <maartenflippo@outlook.com>
This commit is contained in:
parent
1182387224
commit
2347da8c8d
4 changed files with 230 additions and 0 deletions
|
@ -71,6 +71,10 @@ fn gen_fn(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
|
|||
get_fn_target(ctx, &target_module, call.clone())?
|
||||
}
|
||||
Some(hir::PathResolution::Def(hir::ModuleDef::Adt(adt))) => {
|
||||
if let hir::Adt::Enum(_) = adt {
|
||||
return None;
|
||||
}
|
||||
|
||||
let current_module = ctx.sema.scope(call.syntax())?.module();
|
||||
let module = adt.module(ctx.sema.db);
|
||||
target_module = if current_module == module { None } else { Some(module) };
|
||||
|
@ -1738,4 +1742,17 @@ fn foo(value: usize) ${0:-> _} {
|
|||
",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_applicable_for_enum_variant() {
|
||||
check_assist_not_applicable(
|
||||
generate_function,
|
||||
r"
|
||||
enum Foo {}
|
||||
fn main() {
|
||||
Foo::Bar$0(true)
|
||||
}
|
||||
",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue