Skip to content

Commit 7e5f0a2

Browse files
Merge pull request #5231 from tuvior/decompiler-colors
Decompiler Syntax Highlighting
2 parents 517754c + 8541396 commit 7e5f0a2

File tree

5 files changed

+115
-87
lines changed

5 files changed

+115
-87
lines changed

compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package dotty.tools.dotc.quoted
22

33
import dotty.tools.dotc.ast.tpd
44
import dotty.tools.dotc.Driver
5-
import dotty.tools.dotc.core.Contexts.{Context, ContextBase}
5+
import dotty.tools.dotc.core.Contexts.{Context, ContextBase, FreshContext}
66
import dotty.tools.dotc.tastyreflect.TastyImpl
77
import dotty.tools.io.{AbstractFile, Directory, PlainDirectory, VirtualDirectory}
88
import dotty.tools.repl.AbstractFileClassLoader
@@ -27,7 +27,7 @@ class QuoteDriver extends Driver {
2727
}
2828

2929
val (_, ctx0: Context) = setup(settings.compilerArgs.toArray :+ "dummy.scala", initCtx.fresh)
30-
val ctx = ctx0.fresh.setSetting(ctx0.settings.outputDir, outDir)
30+
val ctx = setColor(ctx0.fresh.setSetting(ctx0.settings.outputDir, outDir), settings)
3131

3232
val driver = new QuoteCompiler
3333
driver.newRun(ctx).compileExpr(expr)
@@ -50,7 +50,7 @@ class QuoteDriver extends Driver {
5050
}
5151

5252
def withTree[T](expr: Expr[_], f: (Tree, Context) => T, settings: Toolbox.Settings): T = {
53-
val (_, ctx: Context) = setup(settings.compilerArgs.toArray :+ "dummy.scala", initCtx.fresh)
53+
val ctx = setColor(setup(settings.compilerArgs.toArray :+ "dummy.scala", initCtx.fresh)._2.fresh, settings)
5454

5555
var output: Option[T] = None
5656
def registerTree(tree: tpd.Tree)(ctx: Context): Unit = {
@@ -79,6 +79,9 @@ class QuoteDriver extends Driver {
7979
ictx
8080
}
8181

82+
private def setColor(ctx: FreshContext, settings: Toolbox.Settings): FreshContext =
83+
ctx.setSetting(ctx.settings.color, if (settings.color) "always" else "never")
84+
8285
}
8386

8487
object QuoteDriver {

library/src/scala/quoted/Toolbox.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ object Toolbox {
3232
}
3333

3434
/** Setting of the Toolbox instance. */
35-
class Settings private (val outDir: Option[String], val showRawTree: Boolean, val compilerArgs: List[String])
35+
class Settings private (val outDir: Option[String], val showRawTree: Boolean, val compilerArgs: List[String], val color: Boolean)
3636

3737
object Settings {
3838

@@ -50,7 +50,7 @@ object Toolbox {
5050
outDir: Option[String] = None,
5151
compilerArgs: List[String] = Nil
5252
): Settings =
53-
new Settings(outDir, showRawTree, compilerArgs)
53+
new Settings(outDir, showRawTree, compilerArgs, color)
5454
}
5555

5656
class ToolboxNotFoundException(msg: String, cause: ClassNotFoundException) extends Exception(msg, cause)

library/src/scala/tasty/util/ShowExtractors.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ class ShowExtractors[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
77

88
def showTree(tree: Tree)(implicit ctx: Context): String =
99
new Buffer().visitTree(tree).result()
10-
1110
def showCaseDef(caseDef: CaseDef)(implicit ctx: Context): String =
1211
new Buffer().visitCaseDef(caseDef).result()
1312

0 commit comments

Comments
 (0)