Skip to content

Commit 97c63aa

Browse files
Merge pull request #5235 from dotty-staging/tasty-reflect-add-settings
Add TASTy reflect settings
2 parents 07f15aa + 8ff7f89 commit 97c63aa

File tree

7 files changed

+36
-0
lines changed

7 files changed

+36
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package dotty.tools.dotc.tastyreflect
2+
3+
trait SettingsOpsImpl extends scala.tasty.reflect.SettingsOps with TastyCoreImpl {
4+
5+
def settings(implicit ctx: Context): Settings = ctx.settings
6+
7+
def SettingsDeco(settings: Settings): SettingsAPI = new SettingsAPI {
8+
def color(implicit ctx: Context): Boolean = settings.color.value == "always"
9+
}
10+
11+
}

compiler/src/dotty/tools/dotc/tastyreflect/TastyCoreImpl.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ trait TastyCoreImpl extends scala.tasty.reflect.TastyCore {
99

1010
type Context = core.Contexts.Context
1111

12+
type Settings = config.ScalaSettings
13+
1214
type TermOrTypeTree = tpd.Tree
1315

1416
type Tree = tpd.Tree

compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class TastyImpl(val rootContext: Contexts.Context)
1414
with PatternOpsImpl
1515
with PositionOpsImpl
1616
with PrintersImpl
17+
with SettingsOpsImpl
1718
with SignatureOpsImpl
1819
with StandardDefinitions
1920
with SymbolOpsImpl

library/src/scala/tasty/Tasty.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ abstract class Tasty
1313
with PatternOps
1414
with PositionOps
1515
with Printers
16+
with SettingsOps
1617
with SignatureOps
1718
with StandardDefinitions
1819
with SymbolOps
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package scala.tasty.reflect
2+
3+
trait SettingsOps extends TastyCore {
4+
5+
/** Compiler settings */
6+
def settings(implicit ctx: Context): Settings
7+
8+
trait SettingsAPI {
9+
def color(implicit ctx: Context): Boolean
10+
}
11+
implicit def SettingsDeco(settings: Settings): SettingsAPI
12+
13+
}

library/src/scala/tasty/reflect/TastyCore.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ trait TastyCore {
114114
/** Compilation context */
115115
type Context
116116

117+
/** Settings */
118+
type Settings
119+
117120
// TODO: When bootstrapped, remove and use `Term | TypeTree` type directly in other files
118121
/** Workaround missing `|` types in Scala 2 to represent `Term | TypeTree` */
119122
type TermOrTypeTree /* Term | TypeTree */

library/src/scala/tasty/util/ShowSourceCode.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import scala.annotation.switch
66
class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty0) {
77
import tasty.{rootContext => _, _}
88

9+
private[this] val color: Boolean = {
10+
import tasty.rootContext
11+
tasty.settings.color
12+
}
13+
914
def showTree(tree: Tree)(implicit ctx: Context): String =
1015
(new Buffer).printTree(tree).result()
1116

0 commit comments

Comments
 (0)