Skip to content

Commit 1c6aac4

Browse files
committed
Add syntax highlighting and page width
1 parent de0ab71 commit 1c6aac4

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed
Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package dotty.tools.dotc.decompiler
1+
package dotty.tools.dotc
2+
package decompiler
23

34
import dotty.tools.dotc.core.Contexts._
45
import dotty.tools.dotc.core.Phases.Phase
@@ -11,15 +12,20 @@ class DecompilationPrinter extends Phase {
1112

1213
override def phaseName: String = "decompilationPrinter"
1314

14-
override def run(implicit ctx: Context): Unit = println(output)
15-
16-
private def output(implicit ctx: Context): String = {
15+
override def run(implicit ctx: Context): Unit = {
1716
val unit = ctx.compilationUnit
18-
s"""${"=" * 80}
19-
|$unit
20-
|${"-" * 80}
21-
|${unit.tpdTree.show}
22-
|${"-" * 80}
23-
""".stripMargin
17+
18+
val pageWidth = ctx.settings.pageWidth.value
19+
20+
val doubleLine = "=" * pageWidth
21+
val line = "-" * pageWidth
22+
23+
println(doubleLine)
24+
println(unit.source)
25+
println(line)
26+
27+
val code = unit.tpdTree.show
28+
println(if (ctx.useColors) printing.SyntaxHighlighting(code) else code)
29+
println(line)
2430
}
2531
}

0 commit comments

Comments
 (0)