mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 01:17:27 +00:00
Don't show assist if all arms are present
This commit is contained in:
parent
6087c01460
commit
5f8f8a38a2
1 changed files with 35 additions and 31 deletions
|
@ -50,8 +50,6 @@ pub(crate) fn fill_match_arms(ctx: AssistCtx) -> Option<Assist> {
|
|||
return None;
|
||||
}
|
||||
|
||||
let db = ctx.db;
|
||||
ctx.add_assist(AssistId("fill_match_arms"), "Fill match arms", |edit| {
|
||||
let mut arms: Vec<MatchArm> = match_arm_list.arms().collect();
|
||||
if arms.len() == 1 {
|
||||
if let Some(Pat::PlaceholderPat(..)) = arms[0].pat() {
|
||||
|
@ -60,7 +58,8 @@ pub(crate) fn fill_match_arms(ctx: AssistCtx) -> Option<Assist> {
|
|||
}
|
||||
|
||||
let mut has_partial_match = false;
|
||||
let variants: Vec<MatchArm> = variants
|
||||
let db = ctx.db;
|
||||
let missing_arms: Vec<MatchArm> = variants
|
||||
.into_iter()
|
||||
.filter_map(|variant| build_pat(db, module, variant))
|
||||
.filter(|variant_pat| {
|
||||
|
@ -88,7 +87,12 @@ pub(crate) fn fill_match_arms(ctx: AssistCtx) -> Option<Assist> {
|
|||
.map(|pat| make::match_arm(iter::once(pat), make::expr_unit()))
|
||||
.collect();
|
||||
|
||||
arms.extend(variants);
|
||||
if missing_arms.is_empty() && !has_partial_match {
|
||||
return None;
|
||||
}
|
||||
|
||||
ctx.add_assist(AssistId("fill_match_arms"), "Fill match arms", |edit| {
|
||||
arms.extend(missing_arms);
|
||||
if has_partial_match {
|
||||
arms.push(make::match_arm(
|
||||
iter::once(make::placeholder_pat().into()),
|
||||
|
|
Loading…
Reference in a new issue