Skip to content

Commit fe0c3ab

Browse files
committed
Improve highlight of decl
1 parent 17dfbeb commit fe0c3ab

File tree

6 files changed

+11
-7
lines changed

6 files changed

+11
-7
lines changed

compiler/src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,12 @@ object Contexts {
444444
def useColors: Boolean =
445445
base.settings.color.value == "always"
446446

447+
def withColors: FreshContext =
448+
fresh.setSetting(ctx.settings.color, "always")
449+
450+
def withoutColors: FreshContext =
451+
fresh.setSetting(ctx.settings.color, "never")
452+
447453
/** Is the explicit nulls option set? */
448454
def explicitNulls: Boolean = base.settings.YexplicitNulls.value
449455

compiler/src/dotty/tools/dotc/inlines/Inlines.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,7 @@ object Inlines:
381381

382382
/** Expand call to scala.compiletime.codeOf */
383383
def codeOf(arg: Tree, pos: SrcPos)(using Context): Tree =
384-
val ctx1 = ctx.fresh.setSetting(ctx.settings.color, "never")
385-
Literal(Constant(arg.show(using ctx1))).withSpan(pos.span)
384+
Literal(Constant(arg.show(using ctx.withoutColors))).withSpan(pos.span)
386385
end Intrinsics
387386

388387
/** Produces an inlined version of `call` via its `inlined` method.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,7 @@ class MissingArgument(pname: Name, methString: String)(using Context)
15041504
class MissingArgumentList(method: String, sym: Symbol)(using Context)
15051505
extends TypeMsg(MissingArgumentListID) {
15061506
def msg(using Context) =
1507-
val symDcl = if sym.exists then "\n\n " + sym.showDcl else ""
1507+
val symDcl = if sym.exists then "\n\n " + hl(sym.showDcl(using ctx.withoutColors)) else ""
15081508
i"missing argument list for $method$symDcl"
15091509
def explain(using Context) = {
15101510
i"""Unapplied methods are only converted to functions when a function type is expected."""

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3080,7 +3080,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
30803080

30813081
lazy val ConstantCode: Printer[Constant] = new Printer[Constant]:
30823082
def show(const: Constant): String =
3083-
const.show(using ctx.fresh.setSetting(ctx.settings.color, "never"))
3083+
const.show(using ctx.withoutColors)
30843084

30853085
lazy val ConstantStructure: Printer[Constant] = new Printer[Constant]:
30863086
def show(const: Constant): String =

compiler/test/dotty/tools/dotc/printing/SyntaxHighlightingTests.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ class SyntaxHighlightingTests extends DottyTest {
1212
import SyntaxHighlighting._
1313

1414
private def test(source: String, expected: String): Unit = {
15-
val testCtx = ctx.fresh.setSetting(ctx.settings.color, "always")
16-
val highlighted = SyntaxHighlighting.highlight(source)(using testCtx)
15+
val highlighted = SyntaxHighlighting.highlight(source)(using ctx.withColors)
1716
.replace(NoColor, ">")
1817
.replace(CommentColor, "<C|")
1918
.replace(KeywordColor, "<K|")

compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ trait ErrorMessagesTest extends DottyTest {
1212
protected def newContext = {
1313
val rep = new StoreReporter(null)
1414
with UniqueMessagePositions with HideNonSensicalMessages
15-
initialCtx.setReporter(rep).setSetting(ctx.settings.color, "never")
15+
initialCtx.setReporter(rep).withoutColors
1616
}
1717

1818
class Report(messages: List[Message], ictx: Context) {

0 commit comments

Comments
 (0)