Closed
Description
While working with worksheets it turned out to be more useful to just use the show method on Type using it from macros like:
trait TPrint[T]{
def render: String
}
object TPrint {
inline given default[T] as TPrint[T] = ${ TypePrinter.typeString[T] }
}
object TypePrinter{
def typeString[T](using ctx: QuoteContext, tpe: Type[T]): Expr[TPrint[T]] = {
import ctx.tasty._
val typePrinter = new SourceTypePrinter(ctx.tasty)(SyntaxHighlight.plain)
'{ new TPrint[T]{ def render: String = ${ Expr(tpe.unseal.tpe.show) } } }
}
}
Unfortunately by default it prints the whole type with the prefix, so we would get scala.collection.immuntable.List
instead of just List
.
I was thinking of just adding an additional option to drop the prefixes there, which should not be much effort. Alternatively, we could reuse the PlainPrinter. However, while I feel confident I could work on adding an additional option I feel like consolidating the printers might be something I will not have the time to work on.
Any opinions? CC @odersky @bishabosha