diff --git a/mtags/src/main/scala-3/scala/meta/internal/pc/completions/MatchCaseCompletions.scala b/mtags/src/main/scala-3/scala/meta/internal/pc/completions/MatchCaseCompletions.scala index 0d701c94cc2..c4e568ba53a 100644 --- a/mtags/src/main/scala-3/scala/meta/internal/pc/completions/MatchCaseCompletions.scala +++ b/mtags/src/main/scala-3/scala/meta/internal/pc/completions/MatchCaseCompletions.scala @@ -86,34 +86,42 @@ object CaseKeywordCompletion: new Parents(argTypes, definitions) case _ => new Parents(NoType, definitions) - case sel => new Parents(sel.tpe, definitions) + case sel => + val selectorTpe = sel.tpe + new Parents(selectorTpe, definitions) val selectorSym = parents.selector.typeSymbol - // Special handle case when selector is a tuple or `FunctionN`. if definitions.isTupleClass(selectorSym) || definitions.isFunctionClass( selectorSym ) then + val selectorTpe = parents.selector.show + val tpeLabel = + if !selectorTpe.contains("x$1") then selectorTpe + else selector.symbol.info.show val label = - if patternOnly.isEmpty then s"case ${parents.selector.show} =>" - else parents.selector.show - List( - CompletionValue.CaseKeyword( - selectorSym, - label, - Some( - if patternOnly.isEmpty then - if config.isCompletionSnippetsEnabled() then "case ($0) =>" - else "case () =>" - else if config.isCompletionSnippetsEnabled() then "($0)" - else "()" - ), - Nil, - range = Some(completionPos.toEditRange), - command = config.parameterHintsCommand().asScala, + if patternOnly.isEmpty then s"case ${tpeLabel} =>" + else tpeLabel + if completionGenerator.fuzzyMatches(label) then + List( + CompletionValue.CaseKeyword( + selectorSym, + label, + Some( + if patternOnly.isEmpty then + if config.isCompletionSnippetsEnabled() then "case ($0) =>" + else "case () =>" + else if config.isCompletionSnippetsEnabled() then "($0)" + else "()" + ), + Nil, + range = Some(completionPos.toEditRange), + command = config.parameterHintsCommand().asScala, + ) ) - ) + else Nil + end if else val result = ListBuffer.empty[SymbolImport] val isVisited = mutable.Set.empty[Symbol] diff --git a/tests/cross/src/test/scala/tests/pc/CompletionCaseSuite.scala b/tests/cross/src/test/scala/tests/pc/CompletionCaseSuite.scala index be33b8027ea..fe534f804c6 100644 --- a/tests/cross/src/test/scala/tests/pc/CompletionCaseSuite.scala +++ b/tests/cross/src/test/scala/tests/pc/CompletionCaseSuite.scala @@ -693,4 +693,17 @@ class CompletionCaseSuite extends BaseCompletionSuite { |case Sports(time, intensity) => exhaustive-enum-tags3.Activity""".stripMargin, ) + check( + "for-comp", + """|object A { + | val a = for { + | foo <- List("a", "b", "c") + | abc = println("Print!") + | } yield bar@@ + | + |} + |""".stripMargin, + "", + ) + }