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 WojciechMazur committed Aug 27, 2024
1 parent a1a7b12 commit 44bce71
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 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 @@ -856,12 +858,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 @@ -889,12 +892,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
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,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 Expand Up @@ -903,7 +903,7 @@ object SpaceEngine {
def checkMatch(m: Match)(using Context): Unit =
checkMatchExhaustivityOnly(m)
if reachabilityCheckable(m.selector) then checkReachability(m)

def checkMatchExhaustivityOnly(m: Match)(using Context): Unit =
if exhaustivityCheckable(m.selector) then checkExhaustivity(m)
}

0 comments on commit 44bce71

Please sign in to comment.