Skip to content

Commit b8110a6

Browse files
Syntax highlighting symbols in RefinedPrinter
1 parent fc3ffb6 commit b8110a6

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
116116
super.toTextPrefix(tp)
117117
}
118118

119+
override protected def toTextParents(parents: List[Type]): Text =
120+
Text(parents.map(toTextLocal).map(typeText), keywordStr(" with "))
121+
119122
override protected def refinementNameString(tp: RefinedType): String =
120123
if (tp.parent.isInstanceOf[WildcardType] || tp.refinedName == nme.WILDCARD)
121124
super.refinementNameString(tp)
@@ -825,14 +828,21 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
825828
case info: ImportType => return s"import $info.expr.show"
826829
case _ =>
827830
}
828-
if (sym.is(ModuleClass)) {
829-
val name =
830-
if (sym.isPackageObject && sym.name.stripModuleClassSuffix == tpnme.PACKAGE) sym.owner.name
831-
else sym.name.stripModuleClassSuffix
832-
kindString(sym) ~~ (nameString(name) + idString(sym))
833-
}
834-
else
835-
super.toText(sym)
831+
def name =
832+
if (sym.is(ModuleClass) && sym.isPackageObject && sym.name.stripModuleClassSuffix == tpnme.PACKAGE)
833+
nameString(sym.owner.name)
834+
else if (sym.is(ModuleClass))
835+
nameString(sym.name.stripModuleClassSuffix)
836+
else if (hasMeaninglessName(sym))
837+
simpleNameString(sym.owner)
838+
else
839+
nameString(sym)
840+
(keywordText(kindString(sym)) ~~ {
841+
if (sym.isAnonymousClass)
842+
toTextParents(sym.info.parents) ~~ "{...}"
843+
else
844+
typeText(name)
845+
}).close
836846
}
837847

838848
/** String representation of symbol's kind. */

0 commit comments

Comments
 (0)