Skip to content

Commit

Permalink
scala-compiler dependency moved to core module
Browse files Browse the repository at this point in the history
override formattedDiff and use thick splitter

implement long diff format

fix all testing error for the new long diff format

improve gitattribute & renormalise

zio 1.x upgrade to the latest

upgrade gradle
  • Loading branch information
tribbloid committed Feb 1, 2024
1 parent 718c1a3 commit 9a6b311
Show file tree
Hide file tree
Showing 24 changed files with 453 additions and 232 deletions.
4 changes: 3 additions & 1 deletion .gitattribute
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
*.xml text eol=lf
*.py text eol=lf
*.R text eol=lf

# from apache spark

*.sh text eol=lf
* text eol=lf
22 changes: 9 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ plugins {
`maven-publish`
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"

id("com.github.ben-manes.versions") version "0.50.0"
id("com.github.ben-manes.versions") version "0.51.0"

id("io.github.cosmicsilence.scalafix") version "0.1.14"
id("io.github.cosmicsilence.scalafix") version "0.2.0"
}

val sonatypeApiUser = providers.gradleProperty("sonatypeApiUser")
Expand Down Expand Up @@ -77,7 +77,6 @@ allprojects {
version = vs.projectV

repositories {
mavenLocal()
mavenCentral()
// jcenter()
maven("https://dl.bintray.com/kotlin/kotlin-dev")
Expand Down Expand Up @@ -131,16 +130,15 @@ allprojects {

dependencies {

// see https://github.com/gradle/gradle/issues/13067
fun bothImpl(constraintNotation: Any) {
implementation(constraintNotation)
testFixturesImplementation(constraintNotation)
}

constraints {}

bothImpl("${vs.scalaGroup}:scala-compiler:${vs.scalaV}")
bothImpl("${vs.scalaGroup}:scala-library:${vs.scalaV}")
// see https://github.com/gradle/gradle/issues/13067
// fun bothImpl(constraintNotation: Any) {
// implementation(constraintNotation)
// testFixturesImplementation(constraintNotation)
// }

implementation("${vs.scalaGroup}:scala-library:${vs.scalaV}")

val scalaTestV = "3.2.11"
testFixturesApi("org.scalatest:scalatest_${vs.scalaBinaryV}:${scalaTestV}")
Expand Down Expand Up @@ -314,8 +312,6 @@ subprojects {
artifactId = moduleID
version = project.version.toString()

println("=== $version ===")

pom {
licenses {
license {
Expand Down
10 changes: 9 additions & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ val vs: Versions = versions()

dependencies {

// see https://github.com/gradle/gradle/issues/13067
fun bothImpl(constraintNotation: Any) {
implementation(constraintNotation)
testFixturesImplementation(constraintNotation)
}

bothImpl("${vs.scalaGroup}:scala-compiler:${vs.scalaV}")

// testImplementation("${vs.scalaGroup}:scala-library:${vs.scalaV}")
testFixturesApi("com.chuusai:shapeless_${vs.scalaBinaryV}:2.3.7")

testFixturesApi("dev.zio:zio_${vs.scalaBinaryV}:1.0.4")
testFixturesApi("dev.zio:zio_${vs.scalaBinaryV}:1.0.18")

testFixturesApi("org.slf4j:slf4j-api:2.0.9")
testRuntimeOnly("org.slf4j:slf4j-simple:2.0.9")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ object SplainFormattingExtension {
import scala.reflect.internal.TypeDebugging.AnsiColor._

val ELLIPSIS: String = "".blue

val | = ""
val vertical_| = "━━━━━━━━:"
}

trait SplainFormattingExtension extends typechecker.splain.SplainFormatting with SplainFormattersExtension {
Expand Down Expand Up @@ -476,15 +479,15 @@ trait SplainFormattingExtension extends typechecker.splain.SplainFormatting with
override protected def formattedHeader_Body(break: Boolean): (String, Seq[TypeRepr]) = {

lazy val infixText = infixOpt match {
case None => "|"
case None => |
case Some(ii) => " " + showFormattedLImpl(ii, break).flat + " "
}

val indented = msg
.split("\n")
.filter(_ != ";")

s"(comparing <found>$infixText<required>)" -> indented.map(v => FlatType(v))
s"(comparing <found>$infixText<required>)" -> indented.toSeq.map(v => FlatType(v))
}
}

Expand Down Expand Up @@ -672,7 +675,14 @@ trait SplainFormattingExtension extends typechecker.splain.SplainFormatting with
}
}

override def showFormattedLImpl(ft: Formatted, break: Boolean): TypeRepr = {
case class ShowFormattedHelper(break: Boolean) {

import scala.reflect.internal.TypeDebugging.AnsiColor._

def _decideBreak(flat: FlatType, broken: BrokenType): TypeRepr = {

if (break) decideBreak(flat, broken) else flat
}

def appendLastLine(lines: List[String], suffix: String): List[String] = {
lines match {
Expand All @@ -682,6 +692,67 @@ trait SplainFormattingExtension extends typechecker.splain.SplainFormatting with
}
}

def withVerticalDelimiter(v: TypeRepr): String = {
v.lines
.map { ll =>
| + ll
}
.mkString("\n")
}

def showDiff(left: Formatted, right: Formatted): TypeRepr = {

val (ll, rr) = (left, right) match {
case (Qualified(lpath, lname), Qualified(rpath, rname)) if lname == rname =>
val prefix = lpath.reverseIterator.zip(rpath.reverseIterator).takeWhile { case (l, r) => l == r }.size + 1
FlatType(s"${qualifiedName(lpath.takeRight(prefix), lname).red}") ->
FlatType(s"${qualifiedName(rpath.takeRight(prefix), rname).green}")

case (left, right) =>
_showFormattedL(left) ->
_showFormattedL(right)
}

lazy val flat =
FlatType(s"${ll.flat}${|}${rr.flat}")

lazy val broken: BrokenType = {

val Seq(_ll, _rr) = Seq(ll, rr).map { v =>
v.indent.indent.indent.indent.indent.joinLines.trim
}

val result =
s"""
|found : ${_ll}
|${vertical_|}
|required: ${_rr}""".stripMargin.trim

BrokenType(result.split("\n").toList)
}

val result = _decideBreak(flat, broken)
result
}

case class Tree(
header: String,
body: Seq[TypeRepr]
) {

lazy val flat: String = {

if (body.isEmpty) header
else s"$header { ${body.map(v => v.flat).mkString(";")} }"
}

lazy val broken: Seq[String] = {
val result = indentTree(List((header, body.flatMap(_.lines).toList, 0)), 1)

result
}
}

/**
* If the args of an applied type constructor are multiline, create separate lines for the constructor name and the
* closing bracket; else return a single line.
Expand All @@ -702,7 +773,27 @@ trait SplainFormattingExtension extends typechecker.splain.SplainFormatting with

def broken = BrokenType(appendLastLine(base.lines, brackets._1) ::: indent(brokenArgs) ::: List(brackets._2))

if (break) decideBreak(flat, broken) else flat
_decideBreak(flat, broken)
}

// TODO: let Based use this?
def showTree(
base: String,
body: Seq[TypeRepr],
brackets: (String, String) = "" -> ""
): TypeRepr = {

def flat = FlatType {

if (body.isEmpty) base
else s"$base ${brackets._1}${body.map(v => v.flat).mkString(";")}${brackets._2}"
}

def broken = BrokenType {
indentTree(List((base, body.flatMap(_.lines).toList, 0)), 1)
}

_decideBreak(flat, broken)
}

def showCompound(
Expand All @@ -712,75 +803,100 @@ trait SplainFormattingExtension extends typechecker.splain.SplainFormatting with
val infixWithSpace = s" $infixText "

def flat = FlatType(types.map(_.flat).mkString(infixWithSpace))

def broken = BrokenType(
types.map(_.lines).reduceLeft((z, a) => appendLastLine(z, infixWithSpace) ::: a)
)

if (break) decideBreak(flat, broken) else flat
_decideBreak(flat, broken)
}

def _showFormattedL(v: Formatted) = showFormattedL(v, break)
def _showFormattedL(v: Formatted): TypeRepr = showFormattedL(v, break)

val raw = ft match {
case Simple(name) => FlatType(name.name)
case Qualified(path, name) => showFormattedQualified(path, name)
case Applied(cons, args) => showEnclosed(_showFormattedL(cons), args.map(_showFormattedL))
case tpe @ Infix(_, _, _, top) =>
wrapParensRepr(
if (break) breakInfix(flattenInfix(tpe)) else FlatType(flattenInfix(tpe).map(showFormatted).mkString(" ")),
top
)
case UnitForm => FlatType("Unit")
case FunctionForm(args, ret, top) =>
FlatType(wrapParens(s"${showFuncParams(args.map(showFormatted))} => ${showFormatted(ret)}", top))
case TupleForm(elems) =>
val formattedElems = elems.map(_showFormattedL)

if (elems.size == 1) {
FlatType(showTuple(formattedElems.map(_.flat))) // TODO: the name showTuple is obsolete
} else {
showEnclosed(FlatType(""), formattedElems, brackets = "(" -> ")")
}
def showTuple(elems: List[Formatted]): TypeRepr = {
val formattedElems = elems.map(_showFormattedL)

case RefinedForm(elems, decls) =>
val compound = showCompound(elems.map(_showFormattedL))

val refined =
if (decls.isEmpty)
compound
else if (truncateDecls(decls))
showEnclosed(compound, List(FlatType("...")), brackets = " {" -> "}", splitter = ";")
else
showEnclosed(compound, decls.map(_showFormattedL), brackets = " {" -> "}", splitter = ";")
elems match {
case List(_) =>
showEnclosed(FlatType("Tuple1"), formattedElems)
case _ =>
showEnclosed(FlatType(""), formattedElems, brackets = "(" -> ")")
}
}

refined
def apply(ft: Formatted): TypeRepr = {

val raw = ft match {
case Simple(name) => FlatType(name.name)
case Qualified(path, name) => showFormattedQualified(path, name)
case Applied(cons, args) => showEnclosed(_showFormattedL(cons), args.map(_showFormattedL))
case tpe @ Infix(_, _, _, top) =>
wrapParensRepr(
if (break) breakInfix(flattenInfix(tpe)) else FlatType(flattenInfix(tpe).map(showFormatted).mkString(" ")),
top
)
case UnitForm => FlatType("Unit")
case FunctionForm(args, ret, top) =>
FlatType(wrapParens(s"${showFuncParams(args.map(showFormatted))} => ${showFormatted(ret)}", top))
case TupleForm(elems) =>
showTuple(elems)

case RefinedForm(elems, decls) =>
val compound = showCompound(elems.map(_showFormattedL))

val refined =
if (decls.isEmpty)
compound
else if (truncateDecls(decls))
showEnclosed(compound, List(FlatType("...")), brackets = " {" -> "}", splitter = ";")
else
showEnclosed(compound, decls.map(_showFormattedL), brackets = " {" -> "}", splitter = ";")

refined

case Diff(left, right) => showDiff(left, right)
case Decl(sym, rhs) =>
showTree(
s"type ${showFormatted(sym)} =",
Seq(_showFormattedL(rhs))
)

case DeclDiff(sym, left, right) =>
val diff = showDiff(left, right)
showTree(
s"type ${showFormatted(sym)} =",
Seq(diff)
)

case ByName(tpe) => FlatType(s"(=> ${showFormatted(tpe)})")
}

case Diff(left, right) => FlatType(formattedDiff(left, right))
case Decl(sym, rhs) => FlatType(s"type ${showFormatted(sym)} = ${showFormatted(rhs)}")
case DeclDiff(sym, left, right) => FlatType(s"type ${showFormatted(sym)} = ${formattedDiff(left, right)}")
case ByName(tpe) => FlatType(s"(=> ${showFormatted(tpe)})")
}
val index = FormattedIndex(ft)
val basedOn = Based.getAll(index)

val index = FormattedIndex(ft)
val basedOn = Based.getAll(index)
val result = {

val result = {
basedOn match {
case Nil =>
raw
case _ =>
def flat = FlatType(raw.flat + " " + basedOn.map(_.flat).mkString(" "))

basedOn match {
case Nil =>
raw
case _ =>
def flat = FlatType(raw.flat + " " + basedOn.map(_.flat).mkString(" "))
def broken = BrokenType(raw.lines ++ basedOn.flatMap(_.broken))
def broken = BrokenType(raw.lines ++ basedOn.flatMap(_.broken))

raw match {
case _: BrokenType => broken
case _ if !break => flat
case _ => decideBreak(flat, broken)
}
raw match {
case _: BrokenType => broken
case _ => _decideBreak(flat, broken)
}
}
}

result
}

result
}

override def showFormattedLImpl(ft: Formatted, break: Boolean): TypeRepr = {
ShowFormattedHelper(break)(ft)
}
}
Loading

0 comments on commit 9a6b311

Please sign in to comment.