Skip to content

Commit

Permalink
fix: don't use color codes for pattern match code action
Browse files Browse the repository at this point in the history
[Cherry-picked b33e4f3]
  • Loading branch information
kasiaMarek authored and prolativ committed Nov 20, 2024
1 parent 27fe00e commit a724728
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions compiler/src/dotty/tools/dotc/reporting/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import printing.Formatting
import ErrorMessageID.*
import ast.Trees
import config.{Feature, ScalaVersion}
import transform.patmat.Space
import transform.patmat.SpaceEngine
import typer.ErrorReporting.{err, matchReductionAddendum, substitutableTypeSymbolsInScope}
import typer.ProtoTypes.{ViewProto, SelectionProto, FunProto}
import typer.Implicits.*
Expand Down Expand Up @@ -853,12 +855,13 @@ extends Message(LossyWideningConstantConversionID):
|Write `.to$targetType` instead."""
def explain(using Context) = ""

class PatternMatchExhaustivity(uncoveredCases: Seq[String], tree: untpd.Match)(using Context)
class PatternMatchExhaustivity(uncoveredCases: Seq[Space], tree: untpd.Match)(using Context)
extends Message(PatternMatchExhaustivityID) {
def kind = MessageKind.PatternMatchExhaustivity

private val hasMore = uncoveredCases.lengthCompare(6) > 0
val uncovered = uncoveredCases.take(6).mkString(", ")
val uncovered = uncoveredCases.take(6).map(SpaceEngine.display).mkString(", ")
private val casesWithoutColor = inContext(ctx.withoutColors)(uncoveredCases.map(SpaceEngine.display))

def msg(using Context) =
val addendum = if hasMore then "(More unmatched cases are elided)" else ""
Expand Down Expand Up @@ -886,12 +889,12 @@ extends Message(PatternMatchExhaustivityID) {
val pathes = List(
ActionPatch(
srcPos = endPos,
replacement = uncoveredCases.map(c => indent(s"case $c => ???", startColumn))
replacement = casesWithoutColor.map(c => indent(s"case $c => ???", startColumn))
.mkString("\n", "\n", "")
),
)
List(
CodeAction(title = s"Insert missing cases (${uncoveredCases.size})",
CodeAction(title = s"Insert missing cases (${casesWithoutColor.size})",
description = None,
patches = pathes
)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ object SpaceEngine {

if uncovered.nonEmpty then
val deduped = dedup(uncovered)
report.warning(PatternMatchExhaustivity(deduped.map(display), m), m.selector)
report.warning(PatternMatchExhaustivity(deduped, m), m.selector)
}

private def reachabilityCheckable(sel: Tree)(using Context): Boolean =
Expand Down

0 comments on commit a724728

Please sign in to comment.