Skip to content

Commit

Permalink
Scalafix-core compiled in Scala 3 (#1629)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvacaru authored Jul 22, 2022
1 parent 3e0049f commit d6645da
Show file tree
Hide file tree
Showing 28 changed files with 98 additions and 26 deletions.
32 changes: 16 additions & 16 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ inThisBuild(
List(
onLoadMessage := s"Welcome to scalafix ${version.value}",
fork := true,
scalacOptions ++= List("-P:semanticdb:synthetics:on"),
semanticdbEnabled := true,
semanticdbVersion := scalametaV,
scalafixScalaBinaryVersion := "2.13",
Expand Down Expand Up @@ -64,18 +63,28 @@ lazy val core = projectMatrix
.settings(
moduleName := "scalafix-core",
buildInfoSettingsForCore,
libraryDependencies ++= List(
scalameta,
googleDiff,
collectionCompat
),
libraryDependencies += googleDiff,
libraryDependencies ++= {
if (isScala3.value) {
List(
scalameta
.exclude("com.lihaoyi", "sourcecode_2.13")
.exclude("org.scala-lang.modules", "scala-collection-compat_2.13")
)
} else {
List(
scalameta,
collectionCompat
)
}
},
libraryDependencies += {
if (isScala211.value) metaconfigFor211
else metaconfig
}
)
.defaultAxes(VirtualAxis.jvm)
.jvmPlatform(buildScalaVersions, Seq(), p => p)
.jvmPlatform(buildScalaVersions :+ scala3, Seq(), p => p)
.enablePlugins(BuildInfoPlugin)

lazy val rules = projectMatrix
Expand Down Expand Up @@ -144,9 +153,6 @@ lazy val testsShared = projectMatrix
.in(file("scalafix-tests/shared"))
.settings(
noPublishAndNoMima,
scalacOptions --= (if (isScala3.value)
Seq("-P:semanticdb:synthetics:on")
else Nil),
coverageEnabled := false
)
.defaultAxes(VirtualAxis.jvm)
Expand All @@ -157,9 +163,6 @@ lazy val testsInput = projectMatrix
.in(file("scalafix-tests/input"))
.settings(
noPublishAndNoMima,
scalacOptions --= (if (isScala3.value)
Seq("-P:semanticdb:synthetics:on")
else Nil),
scalacOptions ~= (_.filterNot(_ == "-Yno-adapted-args")),
scalacOptions ++= warnAdaptedArgs.value, // For NoAutoTupling
scalacOptions ++= warnUnusedImports.value, // For RemoveUnused
Expand All @@ -176,9 +179,6 @@ lazy val testsOutput = projectMatrix
.in(file("scalafix-tests/output"))
.settings(
noPublishAndNoMima,
scalacOptions --= (if (scalaVersion.value.startsWith("3"))
Seq("-P:semanticdb:synthetics:on")
else Nil),
scalacOptions --= warnUnusedImports.value,
libraryDependencies ++= testsDependencies.value,
coverageEnabled := false
Expand Down
4 changes: 3 additions & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ object Dependencies {
val nailgunServer = "com.martiansoftware" % "nailgun-server" % nailgunV
val scalaXml = "org.scala-lang.modules" %% "scala-xml" % scalaXmlV
val scalaXml211 = "org.scala-lang.modules" %% "scala-xml" % scalaXml211V
val scalameta = "org.scalameta" %% "scalameta" % scalametaV
// https://github.com/scalameta/scalameta/issues/2485
val scalameta = ("org.scalameta" %% "scalameta" % scalametaV)
.cross(CrossVersion.for3Use2_13)
val scalametaTeskit = "org.scalameta" %% "testkit" % scalametaV
val scalatest = "org.scalatest" %% "scalatest" % scalatestV
val semanticdbScalacCore = "org.scalameta" % "semanticdb-scalac-core" % scalametaV cross CrossVersion.full
Expand Down
19 changes: 17 additions & 2 deletions project/ScalafixBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys {
)
)

lazy val semanticdbSyntheticsCompilerOption = Def.setting(
if (!isScala3.value)
Seq("-P:semanticdb:synthetics:on")
else Nil
)

lazy val versionPolicyIntentionSetting = Def.setting(
if (!isScala3.value)
Compatibility.BinaryCompatible
else
Compatibility.None
)

lazy val buildInfoSettingsForCore: Seq[Def.Setting[_]] = Seq(
buildInfoKeys := Seq[BuildInfoKey](
name,
Expand Down Expand Up @@ -130,6 +143,7 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys {
},
commands += Command.command("ci-3") { s =>
"unit2_12Target3/test" ::
"core3/compile" ::
s
},
commands += Command.command("ci-213") { s =>
Expand Down Expand Up @@ -172,12 +186,13 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys {
versionPolicyIgnored += "com.lihaoyi" %% "pprint",
versionPolicyIgnoredInternalDependencyVersions :=
Some("^\\d+\\.\\d+\\.\\d+\\+\\d+".r),
versionScheme := Some("early-semver"),
versionPolicyIntention := Compatibility.BinaryCompatible
versionScheme := Some("early-semver")
)

override def projectSettings: Seq[Def.Setting[_]] = List(
versionPolicyIntention := versionPolicyIntentionSetting.value,
scalacOptions ++= compilerOptions.value,
scalacOptions ++= semanticdbSyntheticsCompilerOption.value,
Compile / console / scalacOptions :=
compilerOptions.value :+ "-Yrepl-class-based",
Compile / doc / scalacOptions ++= scaladocOptions,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package scalafix.util

import scala.meta.internal.semanticdb.Scope
import scala.meta.internal.semanticdb.Type

object CompatSemanticdbType {
type SemanticdbType = Type
type SemanticdbScope = Scope
}
7 changes: 7 additions & 0 deletions scalafix-core/src/main/scala-3/scalafix/util/Compat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package scalafix.util

object Compat {
type View[T] = collection.View[T]
type SeqView[T] = collection.SeqView[T]

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package scalafix.util

import scala.meta.internal.semanticdb.XtensionSemanticdbType
import scala.meta.internal.semanticdb.XtensionSemanticdbScope

object CompatSemanticdbType {
type SemanticdbType = XtensionSemanticdbType
type SemanticdbScope = XtensionSemanticdbScope
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scala.meta.internal

import scala.meta._
import scala.meta.internal.inputs.XtensionInputSyntaxStructure
import scala.meta.internal.semanticdb.Scala.Descriptor
import scala.meta.internal.semanticdb.Scala.DescriptorParser
import scala.meta.internal.trees.Origin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package scalafix.internal.config

import scala.{meta => m}

import scala.meta.internal.inputs.XtensionInputSyntaxStructure

import metaconfig.Conf
import metaconfig.ConfDecoder
import metaconfig.ConfError
Expand Down Expand Up @@ -58,7 +60,9 @@ object MetaconfigOps {
def getField[T: ConfDecoder](e: sourcecode.Text[T]): Configured[T] =
conf.getOrElse(e.source)(e.value)
}
implicit class XtensionConfiguredCompanionScalafix(`_`: Configured.type) {
implicit class XtensionConfiguredCompanionScalafix(
configured: Configured.type
) {
def fromEither[T](either: Either[String, T]): Configured[T] =
either.fold(ConfError.message(_).notOk, Configured.ok)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import scala.collection.mutable.StringBuilder

import scala.meta.Position
import scala.meta.inputs.Input
import scala.meta.internal.inputs.XtensionInputSyntaxStructure

import scalafix.internal.util.IntervalSet

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import scala.collection.mutable

import scala.meta._

import scalafix.XtensionOptionPatch
import scalafix.XtensionSeqPatch
import scalafix.internal.util.SymbolOps
import scalafix.patch.Patch
import scalafix.patch.Patch.internal._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import scala.util.control.TailCalls._

import scala.meta._

import scalafix.XtensionSeqPatch
import scalafix.internal.diff.DiffUtils
import scalafix.internal.util.Failure
import scalafix.internal.util.SuppressOps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package scalafix.internal.rule

import scala.meta._
import scala.meta.contrib.AssociatedComments
import scala.meta.internal.inputs.XtensionInputSyntaxStructure
import scala.meta.tokens.Tokens

import org.scalameta.FileLine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package scalafix.internal.util

import scala.meta._
import scala.meta.internal.ScalametaInternals
import scala.meta.internal.inputs.XtensionInputSyntaxStructure
import scala.meta.internal.{semanticdb => s}

object PositionSyntax {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scalafix.internal.util

import scala.meta.Lit
import scala.meta.XtensionSyntax

import org.typelevel.paiges.Doc
import scalafix.internal.v1.Types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import scala.meta.internal.semanticdb.SymbolInformation.{Property => p}
import scala.meta.internal.symtab.SymbolTable
import scala.meta.internal.{semanticdb => s}

import scalafix.util.CompatSemanticdbType._
import scalapb.GeneratedMessage

case class PrettyResult[T <: Tree](tree: T, imports: List[String])
Expand Down Expand Up @@ -172,7 +173,7 @@ class PrettyType private (
Nil,
Pat.Var(Term.Name(info.displayName)) :: Nil,
None,
q"???"
Term.Name("???")
)
case k.FIELD =>
if (info.is(p.FINAL)) {
Expand All @@ -192,7 +193,11 @@ class PrettyType private (
toTermRef(info)
case _ =>
info.signature match {
case s.MethodSignature(Some(tparams), paramss, returnType) =>
case s.MethodSignature(
Some(tparams),
paramss: Seq[SemanticdbScope],
returnType
) =>
val ret = unwrapRepeatedType(returnType)
if (info.isVal) {
Decl.Val(
Expand Down Expand Up @@ -343,7 +348,7 @@ class PrettyType private (
case _ =>
fail(info)
}
case s.TypeSignature(Some(typeParameters), lo, hi) =>
case s.TypeSignature(Some(typeParameters), lo: SemanticdbType, hi) =>
if (lo.nonEmpty && lo == hi) {
Defn.Type(
toMods(info),
Expand Down Expand Up @@ -621,7 +626,7 @@ class PrettyType private (
Type.With(accum, toType(next))
}
case s.UniversalType(Some(typeParameters), underlying) =>
val universalName = t"T"
val universalName = Type.Name("T")
withHardlinks(typeParameters.hardlinks) { () =>
Type.Project(
Type.Refine(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import scala.meta.inputs.Position
import scala.meta.tokens.Token
import scala.meta.tokens.Tokens

import scalafix.XtensionSeqPatch
import scalafix.patch.Patch

object SuppressOps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import scala.meta.inputs.Input
import scala.meta.inputs.Position
import scala.meta.internal.ScalametaInternals
import scala.meta.internal.semanticdb.Scala._
import scala.meta.internal.semanticdb.XtensionSemanticdbScope
import scala.meta.internal.{semanticdb => s}

import scalafix.v0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scalafix.internal.v0
import metaconfig.Conf
import metaconfig.Configured
import scalafix.XtensionSeqPatch
import scalafix.patch.Patch
import scalafix.rule.RuleCtx
import scalafix.util.SemanticdbIndex
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package scalafix.internal.v1

import scala.meta.internal.semanticdb.XtensionSemanticdbScope
import scala.meta.internal.{semanticdb => s}

import scalafix.v1._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ object TreePos {
case Importer(_, i :: Nil) => symbolImpl(i)
case t: Init => symbolImpl(t.tpe)
case t: Mod.Annot => symbolImpl(t.init)
case _ => tree.pos
case _ => $conforms(tree.pos)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ package object v1 {
}
}

implicit class XtensionTextDocumentsCompanionFix(`_`: s.TextDocuments.type) {
implicit class XtensionTextDocumentsCompanionFix(
sdocType: s.TextDocuments.type
) {
def parseFromFile(file: AbsolutePath): s.TextDocuments = {
val in = Files.newInputStream(file.toNIO)
val sdocs =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scalafix.util

import scala.meta.classifiers.Classifier
import scala.meta.classifiers.XtensionClassifiable
import scala.meta.tokens.Token
import scala.meta.tokens.Token._

Expand Down
1 change: 1 addition & 0 deletions scalafix-core/src/main/scala/scalafix/util/TokenList.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package scalafix.util

import scala.meta.XtensionClassifiable
import scala.meta.tokens.Token
import scala.meta.tokens.Tokens

Expand Down
1 change: 1 addition & 0 deletions scalafix-core/src/main/scala/scalafix/util/TokenOps.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package scalafix.util

import scala.meta.XtensionSyntax
import scala.meta.tokens.Token

object TokenOps {
Expand Down
1 change: 1 addition & 0 deletions scalafix-core/src/main/scala/scalafix/v0/Database.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package scalafix.v0

import scala.meta.internal.inputs.XtensionInputSyntaxStructure
import scala.meta.internal.io.PathIO

final case class Database(documents: Seq[Document]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package scalafix.v1

import scala.meta._
import scala.meta.contrib.AssociatedComments
import scala.meta.internal.inputs.XtensionInputSyntaxStructure
import scala.meta.internal.symtab.SymbolTable
import scala.meta.internal.{semanticdb => s}
import scala.meta.io.RelativePath
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scalafix.v1

import scala.meta.internal.metap.PrinterSymtab
import scala.meta.internal.semanticdb.XtensionSemanticdbSymbolInformation
import scala.meta.internal.{semanticdb => s}
import scala.meta.metap.Format

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import scala.meta.Source
import scala.meta.Tokens
import scala.meta.Tree
import scala.meta.contrib.AssociatedComments
import scala.meta.internal.inputs.XtensionInputSyntaxStructure
import scala.meta.parsers.Parsed

import scalafix.internal.config.ScalaVersion
Expand Down

0 comments on commit d6645da

Please sign in to comment.