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

refactor: Migrate Metals server to Scala 3 #5543

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 4 additions & 8 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
rules = [
OrganizeImports,
ExplicitResultTypes,
RemoveUnused
OrganizeImports
]

ExplicitResultTypes.rewriteStructuralTypesToNamedSubclass = false

RemoveUnused.imports = false

OrganizeImports.groupedImports = Explode
OrganizeImports.expandRelative = true
OrganizeImports.removeUnused = true
OrganizeImports.removeUnused = false
OrganizeImports.groups = [
"re:javax?\\."
"scala."
"scala.meta."
"*"
]

OrganizeImports.targetDialect = StandardLayout
19 changes: 19 additions & 0 deletions .scalafix2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
rules = [
OrganizeImports,
ExplicitResultTypes,
RemoveUnused
]

ExplicitResultTypes.rewriteStructuralTypesToNamedSubclass = false

RemoveUnused.imports = false

OrganizeImports.groupedImports = Explode
OrganizeImports.expandRelative = true
OrganizeImports.removeUnused = true
OrganizeImports.groups = [
"re:javax?\\."
"scala."
"scala.meta."
"*"
]
14 changes: 0 additions & 14 deletions .scalafix3.conf

This file was deleted.

3 changes: 2 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version = "3.8.3"
runner.dialect = scala213source3
runner.dialect = scala3
project.git = true
align.preset = none
align.stripMargin = true
Expand Down Expand Up @@ -37,6 +37,7 @@ fileOverride {
},
"glob:**/mtags*/**" {
trailingCommas = never
runner.dialect = scala213
}
"glob:**/tests/cross/src/**" {
trailingCommas = never
Expand Down
92 changes: 66 additions & 26 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ def crossSetting[A](
logo := Welcome.logo
usefulTasks := Welcome.tasks

ThisBuild / scalafixScalaBinaryVersion := scalaBinaryVersion.value
ThisBuild / scalafixScalaBinaryVersion := "2.13"

inThisBuild(
List(
version ~= { dynVer =>
if (isCI) dynVer
else localSnapshotVersion // only for local publishing
},
scalaVersion := V.scala213,
crossScalaVersions := List(V.scala213),
scalaVersion := V.scala3,
crossScalaVersions := List(V.scala3),
organization := "org.scalameta",
licenses := Seq(
"Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")
Expand Down Expand Up @@ -128,7 +128,7 @@ commands ++= Seq(
runMtagsPublishLocal(st, v, localSnapshotVersion)
}
"interfaces/publishLocal" ::
s"++${V.scala213} metals/publishLocal" ::
s"++${V.scala3} metals/publishLocal" ::
"mtags-java/publishLocal" ::
publishMtags
},
Expand Down Expand Up @@ -218,6 +218,27 @@ val sharedSettings = sharedJavacOptions ++ sharedScalacOptions ++ List(
)
),
),
excludeDependencies ++= crossSetting(
scalaVersion.value,
if3 = {
// Exclude cross published version dependencies leading to conflicts in Scala 3 vs 2.13
// When using Scala 3 exclude Scala 2.13 standard native libraries,
// when using Scala 2.13 exclude Scala 3 standard native libraries
// Use full name, Maven style published artifacts cannot use artifact/cross version for exclusion rules
List(
ExclusionRule()
.withOrganization("org.scala-lang.modules")
.withName(
"scala-collection-compat_2.13"
),
ExclusionRule()
.withOrganization("org.scala-lang.modules")
.withName(
"scala-xml_2.13"
),
)
},
),
scalacOptions ++= lintingOptions(scalaVersion.value),
)

Expand Down Expand Up @@ -299,6 +320,10 @@ def withExcludes(moduleId: ModuleID) =
"com.lihaoyi",
"sourcecode_2.13",
) // avoid 2.13 and 3 on the classpath since it comes in via pprint
.exclude(
"org.scala-lang.modules",
"scala-parallel-collections_2.13",
) // avoid 2.13 and 3 on the classpath since it comes in via pprint

def scala3SemanticdbDependency: ModuleID = withExcludes(
("org.scalameta" % s"semanticdb-shared_${V.scala213}" % V.scalameta)
Expand All @@ -309,6 +334,10 @@ def scala3ScalametaDependency: ModuleID = withExcludes(
.cross(CrossVersion.for3Use2_13)
)

def scala3MetapDependency: ModuleID = withExcludes(
"org.scalameta" % s"semanticdb-metap_${V.scala213}" % V.scalameta
)

val mtagsSettings = List(
crossScalaVersions := V.supportedScalaVersions,
crossTarget := target.value / s"scala-${scalaVersion.value}",
Expand Down Expand Up @@ -370,22 +399,22 @@ val mtagsSettings = List(
},
)

lazy val mtags3 = project
lazy val mtags2 = project
.in(file(".mtags"))
.settings(
Compile / unmanagedSourceDirectories := Seq(),
sharedSettings,
mtagsSettings,
Compile / unmanagedSourceDirectories += (ThisBuild / baseDirectory).value / "mtags" / "src" / "main" / "scala",
Compile / unmanagedSourceDirectories += (ThisBuild / baseDirectory).value / "mtags-shared" / "src" / "main" / "scala",
Compile / unmanagedSourceDirectories += (ThisBuild / baseDirectory).value / "mtags-shared" / "src" / "main" / "scala-3",
moduleName := "mtags3",
scalaVersion := V.scala3,
target := (ThisBuild / baseDirectory).value / "mtags" / "target" / "target3",
Compile / unmanagedSourceDirectories += (ThisBuild / baseDirectory).value / "mtags-shared" / "src" / "main" / "scala-2.13",
moduleName := "mtags2",
scalaVersion := V.scala213,
target := (ThisBuild / baseDirectory).value / "mtags" / "target" / "target2",
publish / skip := true,
libraryDependencies += V.guava,
scalafixConfig := Some(
(ThisBuild / baseDirectory).value / ".scalafix3.conf"
(ThisBuild / baseDirectory).value / ".scalafix2.conf"
),
)
.dependsOn(interfaces)
Expand Down Expand Up @@ -433,44 +462,51 @@ lazy val metals = project
// for BSP
"org.scala-sbt.ipcsocket" % "ipcsocket" % "1.6.2",
"ch.epfl.scala" % "bsp4j" % V.bsp,
"ch.epfl.scala" %% "bloop-rifle" % V.bloop,
("ch.epfl.scala" %% "bloop-rifle" % V.bloop)
.cross(CrossVersion.for3Use2_13),
// for LSP
V.lsp4j,
// for DAP
V.dap4j,
"ch.epfl.scala" %% "scala-debug-adapter" % V.debugAdapter,
withExcludes(
("ch.epfl.scala" %% "scala-debug-adapter" % V.debugAdapter)
.cross(CrossVersion.for3Use2_13)
),
// for finding paths of global log/cache directories
"dev.dirs" % "directories" % "26",
// ==================
// Scala dependencies
// ==================
"org.scalameta" % "mdoc-interfaces" % V.mdoc,
"org.scalameta" %% "scalafmt-dynamic" % V.scalafmt,
("org.scalameta" %% "scalafmt-dynamic" % V.scalafmt)
.cross(CrossVersion.for3Use2_13),
"com.googlecode.java-diff-utils" % "diffutils" % "1.3.0",
"ch.epfl.scala" % "scalafix-interfaces" % V.scalafix,
// For reading classpaths.
// for fetching ch.epfl.scala:bloop-frontend and other library dependencies
"io.get-coursier" % "interface" % V.coursierInterfaces,
// for comparing versions && fetching from sbt maven repository
"io.get-coursier" %% "coursier" % V.coursier,
"io.get-coursier" %% "coursier-sbt-maven-repository" % V.coursier,
("io.get-coursier" %% "versions" % "0.3.2")
.cross(CrossVersion.for3Use2_13),
("io.get-coursier" %% "coursier-sbt-maven-repository" % V.coursier)
.cross(CrossVersion.for3Use2_13),
("io.get-coursier" %% "coursier" % V.coursier)
.cross(CrossVersion.for3Use2_13),
// for logging
"com.outr" %% "scribe" % V.scribe,
"com.outr" %% "scribe-file" % V.scribe,
"com.outr" %% "scribe-slf4j2" % V.scribe, // needed for flyway database migrations
// for JSON formatted doctor
"com.lihaoyi" %% "ujson" % "4.0.0",
"com.lihaoyi" %% "ujson" % "3.3.1",
// For fetching projects' templates
"com.lihaoyi" %% "requests" % "0.9.0",
// for producing SemanticDB from Scala source files, to be sure we want the same version of scalameta
"org.scalameta" %% "scalameta" % V.semanticdb(scalaVersion.value),
"org.scalameta" %% "semanticdb-metap" % V.semanticdb(
scalaVersion.value
) cross CrossVersion.full,
"org.scalameta" % "semanticdb-shared" % V.semanticdb(
scalaVersion.value
) cross CrossVersion.full,
scala3ScalametaDependency,
scala3MetapDependency,
scala3SemanticdbDependency,
// For starting Ammonite
"io.github.alexarchambault.ammonite" %% "ammonite-runner" % "0.4.0",
("io.github.alexarchambault.ammonite" %% "ammonite-runner" % "0.4.0")
.cross(CrossVersion.for3Use2_13),
"org.scala-lang.modules" %% "scala-xml" % "2.3.0",
"org.scala-lang.modules" %% "scala-parallel-collections" % "1.0.4",
("org.virtuslab.scala-cli" % "scala-cli-bsp" % V.scalaCli)
Expand Down Expand Up @@ -540,6 +576,7 @@ lazy val input = project
.in(file("tests/input"))
.settings(
sharedSettings,
scalaVersion := V.scala213,
scalacOptions -= "-Xsource:3",
publish / skip := true,
libraryDependencies ++= List(
Expand Down Expand Up @@ -716,6 +753,7 @@ lazy val metalsDependencies = project
.in(file("target/.dependencies"))
.settings(
publish / skip := true,
scalaVersion := V.scala213,
// silent the intransitive dependency warning
publishMavenStyle := false,
libraryDependencies ++= List(
Expand Down Expand Up @@ -745,8 +783,10 @@ lazy val unit = project
sharedSettings,
Test / javaOptions += "-Xmx2G",
libraryDependencies ++= List(
"io.get-coursier" %% "coursier" % V.coursier, // for jars
"ch.epfl.scala" %% "bloop-config" % V.bloopConfig,
("io.get-coursier" %% "coursier" % V.coursier)
.cross(CrossVersion.for3Use2_13), // for jars
("ch.epfl.scala" %% "bloop-config" % V.bloopConfig)
.cross(CrossVersion.for3Use2_13),
"org.scalameta" %% "munit" % V.munit,
),
buildInfoPackage := "tests",
Expand Down
Loading
Loading