Skip to content

Allow SourceCodePrinter to show type without prefixes #9716

Closed
@tgodzik

Description

@tgodzik

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.Listinstead 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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions