Skip to content

Commit

Permalink
Bump pprint, fansi and fs2. Also, refactor them to be detected automa…
Browse files Browse the repository at this point in the history
…tically by steward
  • Loading branch information
tgodzik committed Jan 19, 2022
1 parent d702cfe commit 5208716
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 53 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ jobs:
matrix:
java: [adopt@1.8, adopt@1.11, 17]
command:
- "'++2.11.12 test'"
# Test legacy Scala versions, where reporting API changed
- "'++2.12.12 test'"
- "'++2.12.14 test'"
Expand Down
74 changes: 35 additions & 39 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import scala.collection.mutable

def scala212 = "2.12.15"
def scala211 = "2.11.12"
def scala213 = "2.13.7"
def scala3 = "3.1.0"
def scala2Versions = List(scala212, scala211, scala213)
def scala2Versions = List(scala212, scala213)
def allScalaVersions = scala2Versions :+ scala3

def scalajs = "1.7.1"
Expand All @@ -13,7 +12,6 @@ def scalajsDom = "2.0.0"

def isScala2(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 2)
def isScala212(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 2) && v.exists(_._2 == 12)
def isScala211(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 2) && v.exists(_._2 == 11)
def isScala3(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 3)

val isScala212 = Def.setting {
Expand Down Expand Up @@ -60,7 +58,6 @@ def crossSetting[A](
CrossVersion.partialVersion(scalaVersion) match {
case partialVersion if isScala2(partialVersion) => if2
case partialVersion if isScala3(partialVersion) => if3
case partialVersion if isScala211(partialVersion) => if2 ::: if211
case partialVersion if isScala212(partialVersion) => if2 ::: if212
case _ => Nil
}
Expand Down Expand Up @@ -116,21 +113,10 @@ val V = new {
val munit = "0.7.29"
val coursier = "1.0.6"
val scalacheck = "1.15.4"
}

lazy val pprintVersion = Def.setting {
if (scalaVersion.value.startsWith("2.11")) "0.5.4"
else "0.6.0"
}

lazy val fansiVersion = Def.setting {
if (scalaVersion.value.startsWith("2.11")) "0.2.6"
else "0.2.9"
}

lazy val fs2Version = Def.setting {
if (scalaVersion.value.startsWith("2.11")) "2.1.0"
else "2.5.5"
val pprint = "0.7.1"
val fansi = "0.3.0"
val fs2 = "3.2.4"
val metaconfig = "0.9.16"
}

lazy val interfaces = project
Expand Down Expand Up @@ -164,7 +150,7 @@ lazy val runtime = project
libraryDependencies ++= crossSetting(
scalaVersion.value,
if2 = List(
"com.lihaoyi" %% "pprint" % pprintVersion.value,
"com.lihaoyi" %% "pprint" % V.pprint,
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided,
"org.scala-lang" % "scala-compiler" % scalaVersion.value % Provided
),
Expand All @@ -176,18 +162,33 @@ lazy val runtime = project
.dependsOn(interfaces)

val excludePprint = ExclusionRule(organization = "com.lihaoyi")
val excludeCollection =
ExclusionRule(organization = "org.scala-lang.modules", name = "scala-collection-compat_2.13")

lazy val cli = project
.settings(
sharedSettings,
moduleName := "mdoc-cli",
scalaVersion := scala213,
crossScalaVersions := scala2Versions,
crossScalaVersions := allScalaVersions,
libraryDependencies ++= List(
"io.get-coursier" % "interface" % V.coursier,
"com.vladsch.flexmark" % "flexmark-all" % "0.62.2",
"org.scalameta" %% "scalameta" % V.scalameta,
"com.geirsson" %% "metaconfig-typesafe-config" % "0.9.10"
"com.lihaoyi" %% "pprint" % V.pprint,
"com.geirsson" %% "metaconfig-typesafe-config" % V.metaconfig
),
libraryDependencies ++= crossSetting(
scalaVersion.value,
if2 = List(
("org.scalameta" %% "scalameta" % V.scalameta)
.excludeAll(excludePprint)
),
if3 = List(
("org.scalameta" %% "scalameta" % V.scalameta)
.excludeAll(excludePprint)
.excludeAll(excludeCollection)
.cross(CrossVersion.for3Use2_13)
)
)
)

Expand Down Expand Up @@ -218,13 +219,13 @@ lazy val mdoc = project
"org.scala-lang" %% "scala3-compiler" % scalaVersion.value,
("org.scalameta" %% "scalameta" % V.scalameta)
.excludeAll(excludePprint)
.excludeAll(excludeCollection)
.cross(CrossVersion.for3Use2_13)
),
if2 = List(
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
"org.scalameta" %% "scalameta" % V.scalameta,
"com.geirsson" %% "metaconfig-typesafe-config" % "0.9.10",
"com.lihaoyi" %% "fansi" % fansiVersion.value
("org.scalameta" %% "scalameta" % V.scalameta)
.excludeAll(excludePprint)
)
),
libraryDependencies ++= List(
Expand All @@ -233,7 +234,10 @@ lazy val mdoc = project
// live reload
"io.undertow" % "undertow-core" % "2.2.14.Final",
"org.jboss.xnio" % "xnio-nio" % "3.8.5.Final",
"org.slf4j" % "slf4j-api" % "1.7.33"
"org.slf4j" % "slf4j-api" % "1.7.33",
"com.geirsson" %% "metaconfig-typesafe-config" % V.metaconfig,
"com.lihaoyi" %% "fansi" % V.fansi,
"com.lihaoyi" %% "pprint" % V.pprint
)
)
.dependsOn(runtime, cli)
Expand Down Expand Up @@ -320,11 +324,11 @@ lazy val unit = project
libraryDependencies ++= crossSetting(
scalaVersion.value,
if3 = List(
("co.fs2" %% "fs2-core" % fs2Version.value)
("co.fs2" %% "fs2-core" % V.fs2)
.cross(CrossVersion.for3Use2_13)
),
if2 = List(
"co.fs2" %% "fs2-core" % fs2Version.value
"co.fs2" %% "fs2-core" % V.fs2
)
),
buildInfoPackage := "tests.cli",
Expand Down Expand Up @@ -452,11 +456,7 @@ def localCrossPublish(versions: List[String]): Def.Initialize[Task[Unit]] =
.reduceLeft(_ dependsOn _)

def localCrossPublishProjects(scalaV: String): Def.Initialize[Task[Unit]] = {
val projects =
if (scalaV.startsWith("3"))
List(runtime, mdoc, js).reverse
else
List(runtime, cli, mdoc, js).reverse
val projects = List(runtime, cli, mdoc, js).reverse
projects
.map(p => localCrossPublishProject(p, scalaV))
.reduceLeft(_ dependsOn _)
Expand All @@ -465,11 +465,7 @@ def localCrossPublishProjects(scalaV: String): Def.Initialize[Task[Unit]] = {
def localCrossPublishProject(ref: Project, scalaV: String): Def.Initialize[Task[Unit]] =
Def.task {
val versionValue = (ThisBuild / version).value
val projects =
if (scalaV.startsWith("3"))
List(runtime, mdoc, js)
else
List(runtime, cli, mdoc, js)
val projects = List(runtime, cli, mdoc, js)
val setttings =
(ThisBuild / version := versionValue) ::
projects.map(p => p / scalaVersion := scalaV)
Expand Down
20 changes: 16 additions & 4 deletions cli/src/main/scala/mdoc/internal/cli/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import mdoc.Reporter
import mdoc.internal.markdown.{GitHubIdGenerator, ReplVariablePrinter}
import mdoc.internal.cli.CliEnrichments._
import pprint.TPrint
import pprint.TPrintColors

class Section(val name: String) extends StaticAnnotation

Expand Down Expand Up @@ -300,13 +301,24 @@ object Settings { // extends MetaconfigScalametaImplicits with Decoders with Set
def write(set: Settings) = ConfEncoder[Settings].write(set)

implicit val absolutePathPrint: TPrint[AbsolutePath] =
TPrint.make[AbsolutePath](_ => "<path>")
new TPrint[AbsolutePath] {
def render(implicit tpc: TPrintColors): fansi.Str = fansi.Str("<path>")
}

implicit val pathMatcherPrint: TPrint[PathMatcher] =
TPrint.make[PathMatcher](_ => "<glob>")
new TPrint[PathMatcher] {
def render(implicit tpc: TPrintColors): fansi.Str = fansi.Str("<glob>")
}

implicit def optionPrint[T](implicit ev: pprint.TPrint[T]): TPrint[Option[T]] =
TPrint.make { implicit cfg => ev.render }
new TPrint[Option[T]] {
def render(implicit tpc: TPrintColors): fansi.Str = ev.render
}

implicit def iterablePrint[C[x] <: Iterable[x], T](implicit ev: pprint.TPrint[T]): TPrint[C[T]] =
TPrint.make { implicit cfg => s"[${ev.render} ...]" }
new TPrint[C[T]] {
def render(implicit tpc: TPrintColors): fansi.Str = s"[${ev.render} ...]"
}

implicit val pathMatcherDecoder: ConfDecoder[PathMatcher] =
ConfDecoder.stringConfDecoder.map(glob => FileSystems.getDefault.getPathMatcher("glob:" + glob))
Expand Down
5 changes: 2 additions & 3 deletions mdoc/src/main/scala/mdoc/internal/markdown/Processor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import scala.meta.dialects.{Scala213, Scala3}
import scala.util.control.NonFatal
import mdoc.internal.cli.Context
import mdoc.internal.document.MdocExceptions
import mdoc.internal.document.Printing
import mdoc.internal.markdown.Modifier._
import mdoc.internal.pos.PositionSyntax._
import pprint.TPrintColors
import scala.meta.io.RelativePath
import coursierapi.error.SimpleResolutionError
import coursierapi.error.CoursierError
Expand Down Expand Up @@ -198,7 +198,6 @@ class Processor(implicit ctx: Context) {
ctx.settings.variablePrinter,
markdownCompiler
)
implicit val pprintColor = TPrintColors.BlackWhite
mod match {
case Modifier.Post(modifier, info) =>
val variables = for {
Expand All @@ -209,7 +208,7 @@ class Processor(implicit ctx: Context) {
} yield {
new mdoc.Variable(
binder.name,
binder.tpe.render,
Printing.typeString(binder.tpe),
binder.value,
binder.pos.toMeta(section),
j,
Expand Down
5 changes: 3 additions & 2 deletions mdoc/src/main/scala/mdoc/internal/markdown/Renderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import mdoc.document.CrashResult.Crashed
import mdoc.document.RangePosition
import mdoc.internal.document.FailSection
import mdoc.internal.document.MdocExceptions
import mdoc.internal.document.Printing
import mdoc.internal.pos.PositionSyntax._
import mdoc.internal.pos.TokenEditDistance
import scala.meta._
Expand Down Expand Up @@ -157,7 +158,7 @@ object Renderer {
}
appendFreshMultiline(sb, compiled)
case _ =>
val obtained = pprint.PPrinter.BlackWhite.apply(binder).toString()
val obtained = Printing.stringValue(binder.value)
throw new IllegalArgumentException(
s"Expected FailSection. Obtained $obtained"
)
Expand All @@ -166,7 +167,7 @@ object Renderer {
val pos = binder.pos.toMeta(section)
val variable = new mdoc.Variable(
binder.name,
binder.tpe.render,
Printing.typeString(binder.tpe),
binder.value,
pos,
i,
Expand Down
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ libraryDependencies ++= List(
"org.jsoup" % "jsoup" % "1.12.1",
"org.scala-sbt" %% "scripted-plugin" % sbtVersion.value
)
unmanagedSourceDirectories.in(Compile) +=
baseDirectory.in(ThisBuild).value.getParentFile /
Compile / unmanagedSourceDirectories +=
(ThisBuild / baseDirectory).value.getParentFile /
"mdoc-sbt" / "src" / "main" / "scala"
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Compat.TPrint
object Printing {

def stringValue[T](value: T) = PPrinter.BlackWhite.apply(value)
def typeString[T](tprint: TPrint[T]) = tprint.render(TPrintColors.BlackWhite)
def typeString[T](tprint: TPrint[T]): String = tprint.render(TPrintColors.BlackWhite).render
def print[T](value: T, out: StringBuilder, width: Int, height: Int) = {
BlackWhite
.tokenize(value, width, height)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class ScalacOptionsSuite extends BaseCliSuite {
|final case class Test(value: Int)
|
|val test = Test(123)
|// test: Test = Test(123)
|// test: Test = Test(value = 123)
|
|test.value
|// res0: Int = 123
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/src/test/scala/tests/markdown/DefaultSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ class DefaultSuite extends BaseMarkdownSuite {
""".stripMargin,
compat = Map(
Compat.Scala213 ->
"""|```scala
|case class User(name: String, age: Int)
|User("John", 42)
|// res0: User = User(name = "John", age = 42)
|```
|""".stripMargin,
Compat.Scala3 ->
"""|```scala
|case class User(name: String, age: Int)
|User("John", 42)
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/src/test/scala/tests/markdown/SemanticsSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ class SemanticsSuite extends BaseMarkdownSuite {
|```
""".stripMargin,
compat = Map(
Compat.Scala3 ->
"""|```scala
|case class User(name: String)
|object User {
| implicit val ordering: Ordering[User] = Ordering.by(_.name)
|}
|List(User("Susan"), User("John")).sorted
|// res0: List[User] = List(User(name = "John"), User(name = "Susan"))
|```
|""".stripMargin,
Compat.Scala213 ->
"""|```scala
|case class User(name: String)
Expand Down

0 comments on commit 5208716

Please sign in to comment.