Skip to content

Commit 512a0b3

Browse files
Merge pull request #3576 from dotty-staging/fix-printer-color-format
Fix printer color format
2 parents 2aa5950 + aa7c8eb commit 512a0b3

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
538538
def plain = this
539539

540540
protected def keywordStr(text: String): String = coloredStr(text, SyntaxHighlighting.KeywordColor)
541+
protected def valDefStr(text: String): String = coloredStr(text, SyntaxHighlighting.ValDefColor)
541542
protected def typeText(text: Text): Text = coloredText(text, SyntaxHighlighting.TypeColor)
542543
protected def literalText(text: Text): Text = coloredText(text, SyntaxHighlighting.LiteralColor)
543544
protected def stringText(text: Text): Text = coloredText(text, SyntaxHighlighting.StringColor)

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
269269
else if (suppressKw) PrintableFlags &~ Private
270270
else PrintableFlags
271271
if (homogenizedView && mods.flags.isTypeFlags) flagMask &~= Implicit // drop implicit from classes
272-
val flagsText = (mods.flags & flagMask).toString
272+
val flagsText = keywordStr((mods.flags & flagMask).toString)
273273
Text(mods.annotations.map(annotText), " ") ~~ flagsText ~~ (kw provided !suppressKw)
274274
}
275275

@@ -471,13 +471,13 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
471471
("(" ~ toTextGlobal(implicits, ", ") ~ ")" provided implicits.nonEmpty)
472472
case tree @ ValDef(name, tpt, _) =>
473473
dclTextOr {
474-
modText(tree.mods, keywordStr(if (tree.mods is Mutable) "var" else "val")) ~~
474+
modText(tree.mods, valDefStr(if (tree.mods is Mutable) "var" else "val")) ~~
475475
nameIdText(tree) ~ optAscription(tpt) ~
476476
withEnclosingDef(tree) { optText(tree.rhs)(" = " ~ _) }
477477
}
478478
case tree @ DefDef(name, tparams, vparamss, tpt, _) =>
479479
dclTextOr {
480-
val prefix = modText(tree.mods, keywordStr("def")) ~~ nameIdText(tree)
480+
val prefix = modText(tree.mods, valDefStr("def")) ~~ nameIdText(tree)
481481
withEnclosingDef(tree) {
482482
addVparamssText(prefix ~ tparamsText(tparams), vparamss) ~ optAscription(tpt) ~
483483
optText(tree.rhs)(" = " ~ _)
@@ -590,7 +590,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
590590
t ~ cxBoundToText(cxb)
591591
}
592592
case PatDef(mods, pats, tpt, rhs) =>
593-
modText(mods, keywordStr("val")) ~~ toText(pats, ", ") ~ optAscription(tpt) ~
593+
modText(mods, valDefStr("val")) ~~ toText(pats, ", ") ~ optAscription(tpt) ~
594594
optText(rhs)(" = " ~ _)
595595
case ParsedTry(expr, handler, finalizer) =>
596596
changePrec(GlobalPrec) {
@@ -703,7 +703,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
703703
else {
704704
var flags = sym.flagsUNSAFE
705705
if (flags is TypeParam) flags = flags &~ Protected
706-
Text((flags & PrintableFlags).flagStrings map stringToText, " ")
706+
Text((flags & PrintableFlags).flagStrings map (flag => stringToText(keywordStr(flag))), " ")
707707
}
708708

709709
override def toText(denot: Denotation): Text = denot match {

0 commit comments

Comments
 (0)