Skip to content

Commit b33e4f3

Browse files
committed
fix: don't use color codes for pattern match code action
1 parent 2d0e373 commit b33e4f3

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

compiler/src/dotty/tools/dotc/reporting/messages.scala

+7-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import printing.Formatting
1515
import ErrorMessageID.*
1616
import ast.Trees
1717
import config.{Feature, ScalaVersion}
18+
import transform.patmat.Space
19+
import transform.patmat.SpaceEngine
1820
import typer.ErrorReporting.{err, matchReductionAddendum, substitutableTypeSymbolsInScope}
1921
import typer.ProtoTypes.{ViewProto, SelectionProto, FunProto}
2022
import typer.Implicits.*
@@ -856,12 +858,13 @@ extends Message(LossyWideningConstantConversionID):
856858
|Write `.to$targetType` instead."""
857859
def explain(using Context) = ""
858860

859-
class PatternMatchExhaustivity(uncoveredCases: Seq[String], tree: untpd.Match)(using Context)
861+
class PatternMatchExhaustivity(uncoveredCases: Seq[Space], tree: untpd.Match)(using Context)
860862
extends Message(PatternMatchExhaustivityID) {
861863
def kind = MessageKind.PatternMatchExhaustivity
862864

863865
private val hasMore = uncoveredCases.lengthCompare(6) > 0
864-
val uncovered = uncoveredCases.take(6).mkString(", ")
866+
val uncovered = uncoveredCases.take(6).map(SpaceEngine.display).mkString(", ")
867+
private val casesWithoutColor = inContext(ctx.withoutColors)(uncoveredCases.map(SpaceEngine.display))
865868

866869
def msg(using Context) =
867870
val addendum = if hasMore then "(More unmatched cases are elided)" else ""
@@ -889,12 +892,12 @@ extends Message(PatternMatchExhaustivityID) {
889892
val pathes = List(
890893
ActionPatch(
891894
srcPos = endPos,
892-
replacement = uncoveredCases.map(c => indent(s"case $c => ???", startColumn))
895+
replacement = casesWithoutColor.map(c => indent(s"case $c => ???", startColumn))
893896
.mkString("\n", "\n", "")
894897
),
895898
)
896899
List(
897-
CodeAction(title = s"Insert missing cases (${uncoveredCases.size})",
900+
CodeAction(title = s"Insert missing cases (${casesWithoutColor.size})",
898901
description = None,
899902
patches = pathes
900903
)

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ object SpaceEngine {
840840

841841
if uncovered.nonEmpty then
842842
val deduped = dedup(uncovered)
843-
report.warning(PatternMatchExhaustivity(deduped.map(display), m), m.selector)
843+
report.warning(PatternMatchExhaustivity(deduped, m), m.selector)
844844
}
845845

846846
private def reachabilityCheckable(sel: Tree)(using Context): Boolean =
@@ -903,7 +903,7 @@ object SpaceEngine {
903903
def checkMatch(m: Match)(using Context): Unit =
904904
checkMatchExhaustivityOnly(m)
905905
if reachabilityCheckable(m.selector) then checkReachability(m)
906-
906+
907907
def checkMatchExhaustivityOnly(m: Match)(using Context): Unit =
908908
if exhaustivityCheckable(m.selector) then checkExhaustivity(m)
909909
}

0 commit comments

Comments
 (0)