From ff4d8e81bbc024636990dc54a0a724f0a6095d02 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Tue, 20 Apr 2021 08:50:55 +0200 Subject: [PATCH] Add support for Scala 3.0.0-RC3 --- .github/workflows/ci.yml | 2 +- bin/test-release.sh | 1 + build.sbt | 4 ++-- .../mdoc/internal/pprint/TypePrinter.scala | 24 +++++++++++++++++++ .../mdoc/internal/sourcecode/Macros.scala | 18 ++++++++++++++ 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 runtime/src/main/scala-3.0.0-RC3/mdoc/internal/pprint/TypePrinter.scala create mode 100644 runtime/src/main/scala-3.0.0-RC3/mdoc/internal/sourcecode/Macros.scala diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 237946a3e..0ad95a85a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,8 +32,8 @@ jobs: - "'++2.12.12 test'" - "'++2.12.13 test' scripted" - "'++2.13.5 test'" - - "'++3.0.0-RC1 test'" - "'++3.0.0-RC2 test'" + - "'++3.0.0-RC3 test'" steps: - uses: actions/checkout@v2 - uses: olafurpg/setup-scala@v10 diff --git a/bin/test-release.sh b/bin/test-release.sh index dbceffc2f..97d347ea0 100755 --- a/bin/test-release.sh +++ b/bin/test-release.sh @@ -14,6 +14,7 @@ coursier fetch \ org.scalameta:mdoc_3.0.0-M3:$version \ org.scalameta:mdoc_3.0.0-RC1:$version \ org.scalameta:mdoc_3.0.0-RC2:$version \ + org.scalameta:mdoc_3.0.0-RC3:$version \ org.scalameta:mdoc-js_2.11:$version \ org.scalameta:mdoc-js_2.12.12:$version \ org.scalameta:mdoc-js_2.12:$version \ diff --git a/build.sbt b/build.sbt index 4b37e03e7..90392a985 100644 --- a/build.sbt +++ b/build.sbt @@ -3,7 +3,7 @@ import scala.collection.mutable def scala212 = "2.12.13" def scala211 = "2.11.12" def scala213 = "2.13.5" -def scala3 = List("3.0.0-RC2", "3.0.0-RC1", "3.0.0-M3", "3.0.0-M2") +def scala3 = List("3.0.0-RC3", "3.0.0-RC2", "3.0.0-RC1", "3.0.0-M3", "3.0.0-M2") def scalajs = "1.5.0" def scalajsBinaryVersion = "1" @@ -111,7 +111,7 @@ lazy val sharedSettings = List( val V = new { val scalameta = "4.4.11" - val munit = "0.7.23" + val munit = "0.7.25" val coursier = "1.0.3" val scalacheck = "1.15.2" } diff --git a/runtime/src/main/scala-3.0.0-RC3/mdoc/internal/pprint/TypePrinter.scala b/runtime/src/main/scala-3.0.0-RC3/mdoc/internal/pprint/TypePrinter.scala new file mode 100644 index 000000000..13c2c7029 --- /dev/null +++ b/runtime/src/main/scala-3.0.0-RC3/mdoc/internal/pprint/TypePrinter.scala @@ -0,0 +1,24 @@ +package mdoc.internal.pprint + +import scala.language.implicitConversions +import scala.quoted._ +import scala.quoted.runtime.impl.printers.SyntaxHighlight + +trait TPrint[T]{ + def render: String +} + +object TPrint { + inline given default[T]: TPrint[T] = ${ TypePrinter.typeString[T] } +} + +object TypePrinter{ + + def typeString[T](using ctx: Quotes, tpe: Type[T]): Expr[TPrint[T]] = { + import ctx.reflect._ + + val valueType = TypeTree.of[T](using tpe).tpe.show(using Printer.TypeReprShortCode) + + '{ new TPrint[T]{ def render: String = ${ Expr(valueType) } } } + } +} diff --git a/runtime/src/main/scala-3.0.0-RC3/mdoc/internal/sourcecode/Macros.scala b/runtime/src/main/scala-3.0.0-RC3/mdoc/internal/sourcecode/Macros.scala new file mode 100644 index 000000000..e6d43fc8d --- /dev/null +++ b/runtime/src/main/scala-3.0.0-RC3/mdoc/internal/sourcecode/Macros.scala @@ -0,0 +1,18 @@ +package mdoc.internal.sourcecode + +import scala.language.implicitConversions +import scala.quoted._ + +trait StatementMacro { + inline implicit def generate[T](v: => T): SourceStatement[T] = ${ Macros.text('v) } + inline def apply[T](v: => T): SourceStatement[T] = ${ Macros.text('v) } +} + +object Macros{ + + def text[T: Type](v: Expr[T])(using ctx: Quotes): Expr[SourceStatement[T]] = { + import ctx.reflect.{_, given} + val txt = v.asTerm.pos.sourceCode.getOrElse("") + '{SourceStatement[T]($v, ${Expr(txt)})} + } +} \ No newline at end of file