Don't show assist if all arms are present
@@ -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()),
