From c31b1c06e1e1ac68d4b4021b66943d2c499d0a7b Mon Sep 17 00:00:00 2001 From: Katarzyna Marek Date: Mon, 8 Jul 2024 13:50:44 +0200 Subject: [PATCH] fix: don't use color codes for pattern match code action [Cherry-picked b33e4f3d9354bbfa580ea77c27cbe109a9e3b04a] --- .../src/dotty/tools/dotc/reporting/messages.scala | 11 +++++++---- .../src/dotty/tools/dotc/transform/patmat/Space.scala | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/messages.scala b/compiler/src/dotty/tools/dotc/reporting/messages.scala index 393816714931..b8df9c466a2b 100644 --- a/compiler/src/dotty/tools/dotc/reporting/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/messages.scala @@ -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.* @@ -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 "" @@ -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 ) diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index cf038ef5c17d..1b9ef9b9eaa7 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -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 =