Skip to content

Commit

Permalink
Merge pull request #383 from tgodzik/update-dotty
Browse files Browse the repository at this point in the history
Add support for 0.27.0-RC1 and drop pprint for Dotty
  • Loading branch information
tgodzik authored Sep 9, 2020
2 parents 9a656bf + 9a10ccb commit f103ee4
Show file tree
Hide file tree
Showing 28 changed files with 3,258 additions and 110 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ jobs:
- "'++2.11.12 test'"
- "'++2.12.11 test' scripted"
- "'++2.13.2 test'"
- "'++0.26.0-RC1 test'"
- "'++0.26.0 test'"
- "'++0.27.0-RC1 test'"
steps:
- uses: actions/checkout@v1
- uses: olafurpg/setup-scala@v7
Expand Down
3 changes: 3 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ assumeStandardLibraryStripMargin = true

project.excludeFilters = [
"mdoc/src/main/scala-3"
"runtime/src/main/scala-3"
"runtime/src/main/scala-0.26"
"runtime/src/main/scala-0.27"
]
22 changes: 12 additions & 10 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import scala.collection.mutable
def scala212 = "2.12.11"
def scala211 = "2.11.12"
def scala213 = "2.13.2"
def scala3 = "0.26.0-RC1"
def scala3 = List("0.26.0", "0.27.0-RC1")

def scalajs = "1.1.1"
def scalajsBinaryVersion = "1"
Expand Down Expand Up @@ -65,7 +65,7 @@ def crossSetting[A](
inThisBuild(
List(
scalaVersion := scala212,
crossScalaVersions := List(scala212, scala211, scala213, scala3),
crossScalaVersions := List(scala212, scala211, scala213) ::: scala3,
organization := "org.scalameta",
licenses := Seq(
"Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")
Expand Down Expand Up @@ -109,8 +109,8 @@ lazy val sharedSettings = List(
)

val V = new {
val scalameta = "4.3.20"
val munit = "0.7.11"
val scalameta = "4.3.22"
val munit = "0.7.12"
val coursier = "0.0.25"
}

Expand All @@ -121,7 +121,7 @@ lazy val pprintVersion = Def.setting {

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

lazy val interfaces = project
Expand All @@ -143,11 +143,13 @@ lazy val runtime = project
.settings(
sharedSettings,
moduleName := "mdoc-runtime",
libraryDependencies += "com.lihaoyi" %% "pprint" % pprintVersion.value,
unmanagedSourceDirectories.in(Compile) ++= multiScalaDirectories("runtime").value,
libraryDependencies ++= crossSetting(
scalaVersion.value,
if2 = List(
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided
"com.lihaoyi" %% "pprint" % pprintVersion.value,
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided,
"org.scala-lang" % "scala-compiler" % scalaVersion.value % Provided
)
)
)
Expand Down Expand Up @@ -243,10 +245,10 @@ val jsdocs = project
.settings(
sharedSettings,
skip in publish := true,
crossScalaVersions --= scala3,
scalaJSLinkerConfig ~= {
_.withModuleKind(ModuleKind.CommonJSModule)
},
crossScalaVersions -= scala3,
libraryDependencies ++= List(
"org.scala-js" %%% "scalajs-dom" % scalajsDom
),
Expand Down Expand Up @@ -274,7 +276,7 @@ lazy val unit = project
.settings(
sharedSettings,
skip in publish := true,
crossScalaVersions -= scala3,
crossScalaVersions --= scala3,
addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.10.3"),
resolvers += Resolver.bintrayRepo("cibotech", "public"),
scala212LibraryDependencies(
Expand Down Expand Up @@ -339,7 +341,7 @@ lazy val js = project
.in(file("mdoc-js"))
.settings(
sharedSettings,
crossScalaVersions -= scala3,
crossScalaVersions --= scala3,
moduleName := "mdoc-js",
scala212LibraryDependencies(
List(
Expand Down
11 changes: 11 additions & 0 deletions mdoc/src/main/scala-2/mdoc/internal/io/ConsoleColors.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package mdoc.internal.io

import fansi.Attrs
import fansi.Color._

case class ConsoleColors(
green: Attrs = Green,
blue: Attrs = Blue,
yellow: Attrs = Yellow,
red: Attrs = Red
)
9 changes: 9 additions & 0 deletions mdoc/src/main/scala-3/mdoc/internal/io/ConsoleColors.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package mdoc.internal.io

case class ConsoleColors(
green: String => String = identity,
blue: String => String = identity,
yellow: String => String = identity,
red: String => String = identity
)

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import java.nio.file.Path

import dotty.tools.dotc.interfaces.SourcePosition
import dotty.tools.dotc.ast.untpd._
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.ast.Trees
import dotty.tools.dotc.core.Flags

Expand Down Expand Up @@ -57,6 +58,7 @@ class Instrumenter(
private def printAsScript(): Unit = {
sections.zipWithIndex.foreach {
case (section, i) =>
import section.ctx
printlnWithIndent("")
printlnWithIndent("$doc.startSection();")
section.stats.foreach { stat =>
Expand All @@ -79,7 +81,7 @@ class Instrumenter(
m: Modifier,
sb: PrintStream,
section: SectionInput
): Unit = {
)(using ctx: Context): Unit = {
val binders = stat match {
case Instrumenter.Binders(names) =>
names
Expand Down Expand Up @@ -140,13 +142,13 @@ object Instrumenter {
}

object Binders {
private def fromPat(trees: List[Tree]) = {
private def fromPat(trees: List[Tree])(using ctx: Context) = {
trees.map {
case id: Ident =>
id.name.toString -> id.sourcePos
}
}
def unapply(tree: Tree): Option[List[(String, SourcePosition)]] =
def unapply(tree: Tree)(using ctx: Context): Option[List[(String, SourcePosition)]] =
tree match {
case df: Trees.ValDef[_] if df.mods.is(Flags.Lazy) => Some(Nil)
case df: Trees.ValDef[_] =>
Expand Down
22 changes: 12 additions & 10 deletions mdoc/src/main/scala-3/mdoc/internal/markdown/SectionInput.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import scala.meta.Source
import scala.meta.inputs.Input
import scala.meta.Name
import mdoc.internal.pos.TokenEditDistance

import mdoc.internal.BuildInfo
import dotty.tools.dotc.interactive.InteractiveDriver

/* The class uses Scala 3 parser.
Expand All @@ -28,9 +28,9 @@ case class SectionInput(input : Input, mod : Modifier, context : MContext){
|}
|""".stripMargin
private val filename = "Section.scala"

driver.run(java.net.URI.create("file:///Section.scala"), SourceFile.virtual(filename, sourceCode))
val source = driver.currentCtx.run.units.head.untpdTree
given ctx as Context = driver.currentCtx
def stats : List[Tree] = {
source match {
case PackageDef(_, List(module @ _ : ModuleDef)) =>
Expand All @@ -42,14 +42,16 @@ case class SectionInput(input : Input, mod : Modifier, context : MContext){
def show(tree : Tree, currentIdent : Int) = {
val str = tree.sourcePos.start
val end = tree.sourcePos.end
// https://github.com/lampepfl/dotty/issues/9495
val prefix = tree match {
case ext: ExtMethods if ext.tparams.nonEmpty =>
"extension ["
case _: ExtMethods =>
"extension ("
case _ => ""
}
// workaround should be removed once support for 0.26.0 is dropped
val prefix = if (BuildInfo.scalaBinaryVersion == "0.26")
tree match {
case ext: ExtMethods if ext.tparams.nonEmpty =>
"extension ["
case _: ExtMethods =>
"extension ("
case _ => ""
}
else ""
val realIdent = " " * (currentIdent - wrapIdent.size)
prefix + sourceCode.substring(str, end).replace("\n", "\n" + realIdent)
}
Expand Down
9 changes: 3 additions & 6 deletions mdoc/src/main/scala/mdoc/internal/io/ConsoleReporter.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package mdoc.internal.io

import fansi.Attrs
import fansi.Color._
import java.io.PrintStream
import java.util.concurrent.atomic.AtomicBoolean
import scala.meta.Position
Expand All @@ -11,12 +9,11 @@ import coursierapi.Logger

class ConsoleReporter(
ps: PrintStream,
green: Attrs = Green,
blue: Attrs = Blue,
yellow: Attrs = Yellow,
red: Attrs = Red
colors: ConsoleColors = ConsoleColors()
) extends Reporter {

import colors._

def formatMessage(pos: Position, severity: String, message: String): String =
pos.formatMessage("", message)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ object MarkdownBuilder {
val pathString = path.toString
pathString.contains("scala-library") ||
pathString.contains("scala-reflect") ||
pathString.contains("sourcecode") ||
pathString.contains("fansi") ||
pathString.contains("pprint") ||
pathString.contains("mdoc-interfaces") ||
(pathString.contains("mdoc") && pathString.contains("runtime"))
(pathString.contains("mdoc") && pathString.contains("runtime")) ||
(pathString.contains("mdoc") && pathString.contains("printing"))
})
base ++ runtime
}
Expand All @@ -99,7 +99,8 @@ object MarkdownBuilder {
.iterator
.map(url => AbsolutePath(Paths.get(url.toURI)))
.filter(p => fn(p.toNIO))
Classpath(paths.toList)
.toList
Classpath(paths)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import mdoc.internal.markdown.SectionInput
import mdoc.internal.markdown.Modifier
import mdoc.internal.markdown.Instrumenter
import mdoc.internal.markdown.MarkdownBuilder
import mdoc.internal.document.Printing
import mdoc.document.Statement
import mdoc.document.RangePosition
import mdoc.internal.cli.Settings
import pprint.TPrintColors
import pprint.PPrinter.BlackWhite
import mdoc.internal.io.StoreReporter
import mdoc.{interfaces => i}
import java.{util => ju}
Expand Down Expand Up @@ -94,9 +93,7 @@ class WorksheetProvider(settings: Settings) {
.append(": ")
.append(binder.tpeString)
.append(" = ")
BlackWhite
.tokenize(binder.value, width = settings.screenWidth, height = settings.screenHeight)
.foreach(text => out.appendAll(text.getChars))
Printing.print(binder.value, out, settings.screenWidth, settings.screenHeight)
}
}
statement.out.linesIterator.foreach { line =>
Expand Down Expand Up @@ -140,16 +137,8 @@ class WorksheetProvider(settings: Settings) {
.append(": ")
.append(binder.tpeString)
.append(" = ")
val chunk = BlackWhite
.tokenize(binder.value, width = margin - out.length)
.map(_.getChars)
.filterNot(_.iterator.forall(_.isWhitespace))
.flatMap(_.iterator)
.filter {
case '\n' => false
case _ => true
}
out.appendAll(chunk)

Printing.printOneLine(binder.value, out, width = margin - out.length)
out.length > margin
}
}
Expand Down
Loading

0 comments on commit f103ee4

Please sign in to comment.