Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scalafix-core_3 (GSoC 2022) #1629

Merged
merged 25 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
24e0725
start compiler in scala 3 scalafix-core
mlachkar Jun 15, 2022
7688f47
format
rvacaru Jul 6, 2022
3d76f4b
(chore): fixed compilation errors via imports
rvacaru Jul 6, 2022
c8307b8
fixed quasiquotes q"???" and t"T", fixed TreePos typing issue by casting
rvacaru Jul 8, 2022
a0b0aeb
introduced scala3 scalafix util w/Compat class, fix TokenList partially
rvacaru Jul 8, 2022
46f4526
fixed imports after self pr review
rvacaru Jul 8, 2022
bc74315
cast trailing and leading returns to correct type
rvacaru Jul 8, 2022
e9e8354
(chore): )removed comments after clarification on Compat
rvacaru Jul 8, 2022
3f32fb4
removed 2.12 and 2.13 package.scala with generic objects for better e…
rvacaru Jul 12, 2022
508ba53
fixed compilation errors, todo only missing sourcode lib in core2_13
rvacaru Jul 13, 2022
58dc1f3
build.sbt libDependency changes to exclude 2_13 dependencies in core3
rvacaru Jul 14, 2022
bcee1c1
(chore): fix pr comments, readability, relative imports, unmanagedSou…
rvacaru Jul 15, 2022
3e3cb06
pr comment fixes: refactor PrettyType a la Compat, refactor sbt commo…
rvacaru Jul 15, 2022
6c4bf8f
rename of new compaSenticType classes/files
rvacaru Jul 15, 2022
5e9f5ba
Apply suggestions from code review
rvacaru Jul 21, 2022
b3730b2
reverse sbt build logic for semanticdb synthetics
rvacaru Jul 21, 2022
720bf53
add compat classes on semanticdb types for PrettyType
rvacaru Jul 21, 2022
2837190
fix revert of MetaconfigCompatMacros: remove manual work done previously
rvacaru Jul 21, 2022
296f8e4
refactored TokenList, by removing explicit typing Compat provided typ…
rvacaru Jul 21, 2022
fd6fc32
test using implicit call to convert Position to T for core3 copliati…
rvacaru Jul 21, 2022
8568ef4
scalafmt fixes
rvacaru Jul 21, 2022
e8c32a0
scalafixAll fixes
rvacaru Jul 21, 2022
416baae
fix versionPolicyIntention for scala3
rvacaru Jul 21, 2022
f40ee72
fix TokenList Compat types and scalafmt
rvacaru Jul 21, 2022
ab2f83d
fix tokenlist
rvacaru Jul 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
bjaglin marked this conversation as resolved.
Show resolved Hide resolved
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