diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/SettingsOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/SettingsOpsImpl.scala new file mode 100644 index 000000000000..867478ab646b --- /dev/null +++ b/compiler/src/dotty/tools/dotc/tastyreflect/SettingsOpsImpl.scala @@ -0,0 +1,11 @@ +package dotty.tools.dotc.tastyreflect + +trait SettingsOpsImpl extends scala.tasty.reflect.SettingsOps with TastyCoreImpl { + + def settings(implicit ctx: Context): Settings = ctx.settings + + def SettingsDeco(settings: Settings): SettingsAPI = new SettingsAPI { + def color(implicit ctx: Context): Boolean = settings.color.value == "always" + } + +} diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/TastyCoreImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/TastyCoreImpl.scala index 3d56904cd6c2..529102ddd8e4 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/TastyCoreImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/TastyCoreImpl.scala @@ -9,6 +9,8 @@ trait TastyCoreImpl extends scala.tasty.reflect.TastyCore { type Context = core.Contexts.Context + type Settings = config.ScalaSettings + type TermOrTypeTree = tpd.Tree type Tree = tpd.Tree diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala index 3ceb2f4fb086..736f92093575 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala @@ -14,6 +14,7 @@ class TastyImpl(val rootContext: Contexts.Context) with PatternOpsImpl with PositionOpsImpl with PrintersImpl + with SettingsOpsImpl with SignatureOpsImpl with StandardDefinitions with SymbolOpsImpl diff --git a/library/src/scala/tasty/Tasty.scala b/library/src/scala/tasty/Tasty.scala index 6e33b1c4a189..c022535757fd 100644 --- a/library/src/scala/tasty/Tasty.scala +++ b/library/src/scala/tasty/Tasty.scala @@ -13,6 +13,7 @@ abstract class Tasty with PatternOps with PositionOps with Printers + with SettingsOps with SignatureOps with StandardDefinitions with SymbolOps diff --git a/library/src/scala/tasty/reflect/SettingsOps.scala b/library/src/scala/tasty/reflect/SettingsOps.scala new file mode 100644 index 000000000000..98ed30f8c381 --- /dev/null +++ b/library/src/scala/tasty/reflect/SettingsOps.scala @@ -0,0 +1,13 @@ +package scala.tasty.reflect + +trait SettingsOps extends TastyCore { + + /** Compiler settings */ + def settings(implicit ctx: Context): Settings + + trait SettingsAPI { + def color(implicit ctx: Context): Boolean + } + implicit def SettingsDeco(settings: Settings): SettingsAPI + +} diff --git a/library/src/scala/tasty/reflect/TastyCore.scala b/library/src/scala/tasty/reflect/TastyCore.scala index fd736335c936..e932c67fc929 100644 --- a/library/src/scala/tasty/reflect/TastyCore.scala +++ b/library/src/scala/tasty/reflect/TastyCore.scala @@ -114,6 +114,9 @@ trait TastyCore { /** Compilation context */ type Context + /** Settings */ + type Settings + // TODO: When bootstrapped, remove and use `Term | TypeTree` type directly in other files /** Workaround missing `|` types in Scala 2 to represent `Term | TypeTree` */ type TermOrTypeTree /* Term | TypeTree */ diff --git a/library/src/scala/tasty/util/ShowSourceCode.scala b/library/src/scala/tasty/util/ShowSourceCode.scala index c79e76814287..d723e2cbf9c2 100644 --- a/library/src/scala/tasty/util/ShowSourceCode.scala +++ b/library/src/scala/tasty/util/ShowSourceCode.scala @@ -6,6 +6,11 @@ import scala.annotation.switch class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty0) { import tasty.{rootContext => _, _} + private[this] val color: Boolean = { + import tasty.rootContext + tasty.settings.color + } + def showTree(tree: Tree)(implicit ctx: Context): String = (new Buffer).printTree(tree).result()