Skip to content

Decompiler Syntax Highlighting #5231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package dotty.tools.dotc.quoted

import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.Driver
import dotty.tools.dotc.core.Contexts.{Context, ContextBase}
import dotty.tools.dotc.core.Contexts.{Context, ContextBase, FreshContext}
import dotty.tools.dotc.tastyreflect.TastyImpl
import dotty.tools.io.{AbstractFile, Directory, PlainDirectory, VirtualDirectory}
import dotty.tools.repl.AbstractFileClassLoader
Expand All @@ -27,7 +27,7 @@ class QuoteDriver extends Driver {
}

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

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

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

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

private def setColor(ctx: FreshContext, settings: Toolbox.Settings): FreshContext =
ctx.setSetting(ctx.settings.color, if (settings.color) "always" else "never")

}

object QuoteDriver {
Expand Down
4 changes: 2 additions & 2 deletions library/src/scala/quoted/Toolbox.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object Toolbox {
}

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

object Settings {

Expand All @@ -50,7 +50,7 @@ object Toolbox {
outDir: Option[String] = None,
compilerArgs: List[String] = Nil
): Settings =
new Settings(outDir, showRawTree, compilerArgs)
new Settings(outDir, showRawTree, compilerArgs, color)
}

class ToolboxNotFoundException(msg: String, cause: ClassNotFoundException) extends Exception(msg, cause)
Expand Down
1 change: 0 additions & 1 deletion library/src/scala/tasty/util/ShowExtractors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class ShowExtractors[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty

def showTree(tree: Tree)(implicit ctx: Context): String =
new Buffer().visitTree(tree).result()

def showCaseDef(caseDef: CaseDef)(implicit ctx: Context): String =
new Buffer().visitCaseDef(caseDef).result()

Expand Down
Loading