Skip to content

Commit

Permalink
Merge pull request #2330 from tgodzik/update-scala3
Browse files Browse the repository at this point in the history
Add support for Scala 3.0.0-M3
  • Loading branch information
tgodzik authored Dec 19, 2020
2 parents 18f1b0d + 2368510 commit fe09b97
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 43 deletions.
23 changes: 15 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ lazy val V = new {
val scalameta = "4.4.2"
val semanticdb = scalameta
val bsp = "2.0.0-M13"
val bloop = "1.4.5-28-e52cd3ad"
val scala3 = "3.0.0-M2"
val bloop = "1.4.6-15-209c2a5c"
val scala3 = "3.0.0-M3"
val bloopNightly = bloop
val sbtBloop = bloop
val gradleBloop = bloop
val mavenBloop = bloop
val mdoc = "2.2.13"
val mdoc = "2.2.14"
val scalafmt = "2.7.4"
val munit = "0.7.19"
val munit = "0.7.20"
val scalafix = "0.9.24"
val lsp4jV = "0.10.0"
// List of supported Scala versions in SemanticDB. Needs to be manually updated
Expand All @@ -217,8 +217,9 @@ lazy val V = new {
def scala2Versions = nonDeprecatedScala2Versions ++ deprecatedScala2Versions

// Scala 3
def nonDeprecatedScala3Versions = Seq(scala3, "3.0.0-M1", "0.27.0-RC1")
def deprecatedScala3Versions = Seq("0.26.0")
def nonDeprecatedScala3Versions =
Seq(scala3, "3.0.0-M2", "3.0.0-M1", "0.27.0-RC1")
def deprecatedScala3Versions = Seq()
def scala3Versions = nonDeprecatedScala3Versions ++ deprecatedScala3Versions

def supportedScalaVersions = scala2Versions ++ scala3Versions
Expand Down Expand Up @@ -305,7 +306,7 @@ val mtagsSettings = List(
baseDirectory.in(ThisBuild).value / "mtags",
scalaVersion.value
),
// @note needed to deal with issues in https://github.com/scalameta/metals/pull/2157
// @note needed to deal with issues with dottyDoc
sources in (Compile, doc) := Seq.empty,
libraryDependencies ++= crossSetting(
scalaVersion.value,
Expand Down Expand Up @@ -581,7 +582,13 @@ lazy val mtest = project
testSettings,
sharedSettings,
libraryDependencies ++= List(
"org.scalameta" %% "munit" % V.munit,
// munit had to drop support for 3.0.0-M1 and 0.27.0-RC1
if (
scalaVersion.value == "0.27.0-RC1" || scalaVersion.value == "3.0.0-M1"
)
"org.scalameta" %% "munit" % "0.7.19"
else
"org.scalameta" %% "munit" % V.munit,
"io.get-coursier" % "interface" % V.coursierInterfaces
),
buildInfoPackage := "tests",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,9 @@ object MetalsEnrichments

def isSemanticdbEnabled(scalaVersion: String): Boolean = {
if (ScalaVersions.isScala3Version(scalaVersion)) {
item.getOptions.asScala.exists { opt => opt == "-Ysemanticdb" }
item.getOptions.asScala.exists { opt =>
opt == "-Ysemanticdb" || opt == "-Xsemanticdb"
}
} else {
item.getOptions.asScala.exists { opt =>
opt.startsWith("-Xplugin:") && opt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import scala.meta.internal.semver.SemVer

object ScalaVersions {

val scala3Milestones: Set[String] = Set("3.0.0-M1", "3.0.0-M2")
def isScala3Milestone(version: String): Boolean =
version.startsWith("3.0.0-M") || version.startsWith("3.0.0-RC")

/**
* Non-Lightbend compilers often use a suffix, such as `-bin-typelevel-4`
Expand Down Expand Up @@ -78,7 +79,7 @@ object ScalaVersions {
) == mtags.BuildInfo.scalaCompilerVersion

def scalaBinaryVersionFromFullVersion(scalaVersion: String): String = {
if (scala3Milestones(scalaVersion))
if (isScala3Milestone(scalaVersion))
scalaVersion
else
scalaVersion.split('.').take(2).mkString(".")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class Scala3CompilerWrapper(driver: InteractiveDriver)
override def compiler(): InteractiveDriver = driver

override def resetReporter(): Unit = {
given ctx as Context = driver.currentCtx
ctx.reporter.removeBufferedMessages
val ctx = driver.currentCtx
ctx.reporter.removeBufferedMessages(using ctx)
}

override def reporterAccess: ReporterAccess[StoreReporter] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ case class ScalaPresentationCompiler(
val sourceFile = CompilerInterfaces.toSource(params.uri, params.text)
driver.run(uri, sourceFile)

given ctx as Context = driver.currentCtx
val ctx = driver.currentCtx
val pos = sourcePosition(driver, params, uri)
val items = driver.compilationUnits.get(uri) match {
case Some(unit) =>
Expand All @@ -128,7 +128,7 @@ case class ScalaPresentationCompiler(
}
new CompletionList(
/*isIncomplete = */ false,
items.map(completionItem).asJava
items.map(completionItem(_)(using ctx)).asJava
)
}
}
Expand All @@ -139,17 +139,17 @@ case class ScalaPresentationCompiler(
params.token
) { access =>
val driver = access.compiler()
given ctx as Context = driver.currentCtx
val ctx = driver.currentCtx
val uri = params.uri
val sourceFile = CompilerInterfaces.toSource(params.uri, params.text)
driver.run(uri, sourceFile)
val pos = sourcePosition(driver, params, uri)
val path = Interactive.pathTo(driver.openedTrees(uri), pos)
val path = Interactive.pathTo(driver.openedTrees(uri), pos)(using ctx)
val definitions = Interactive.findDefinitions(path, pos, driver).toList

DefinitionResultImpl(
"",
definitions.flatMap(d => location(d.namePos)).asJava
definitions.flatMap(d => location(d.namePos(using ctx))).asJava
)

}
Expand Down Expand Up @@ -253,22 +253,22 @@ case class ScalaPresentationCompiler(
val sourceFile = CompilerInterfaces.toSource(params.uri, params.text)
driver.run(uri, sourceFile)

given ctx as Context = driver.currentCtx
val ctx = driver.currentCtx
val pos = sourcePosition(driver, params, uri)
val trees = driver.openedTrees(uri)
val path = Interactive.pathTo(trees, pos)
val tp = Interactive.enclosingType(trees, pos)
val tpw = tp.widenTermRefExpr
val path = Interactive.pathTo(trees, pos)(using ctx)
val tp = Interactive.enclosingType(trees, pos)(using ctx)
val tpw = tp.widenTermRefExpr(using ctx)

if (tp.isError || tpw == NoType || tpw.isError)
if (tp.isError(using ctx) || tpw == NoType || tpw.isError(using ctx))
ju.Optional.empty()
else {
Interactive.enclosingSourceSymbols(path, pos) match {
Interactive.enclosingSourceSymbols(path, pos)(using ctx) match {
case Nil =>
ju.Optional.empty()
case symbols =>
val printer = SymbolPrinter()
val docComments = symbols.flatMap(ParsedComment.docOf)
val printer = SymbolPrinter()(using ctx)
val docComments = symbols.flatMap(ParsedComment.docOf(_)(using ctx))
val keywordName = symbols.headOption.map { symbol =>
printer.fullDefinition(
symbol,
Expand All @@ -279,7 +279,7 @@ case class ScalaPresentationCompiler(
tpw match {
// https://github.com/lampepfl/dotty/issues/8891
case _: ImportType =>
printer.typeString(symbol.typeRef)
printer.typeString(symbol.paramRef(using ctx))
case _ =>
printer.typeString(tpw)
}
Expand All @@ -288,7 +288,7 @@ case class ScalaPresentationCompiler(
keywordName,
typeString,
docComments
)
)(using ctx)
ju.Optional.of(new Hover(content))
}
}
Expand All @@ -315,19 +315,19 @@ case class ScalaPresentationCompiler(
val sourceFile = CompilerInterfaces.toSource(params.uri, params.text)
driver.run(uri, sourceFile)

given ctx as Context = driver.currentCtx
val ctx = driver.currentCtx

val pos = sourcePosition(driver, params, uri)
val trees = driver.openedTrees(uri)

// @tgodzik tpd.TypeApply doesn't seem to be handled here
val path =
Interactive.pathTo(trees, pos).dropWhile(!_.isInstanceOf[tpd.Apply])
Interactive.pathTo(trees, pos)(using ctx).dropWhile(!_.isInstanceOf[tpd.Apply])

val (paramN, callableN, alternatives) =
Signatures.callInfo(path, pos.span)
Signatures.callInfo(path, pos.span)(using ctx)

val signatureInfos = alternatives.flatMap(Signatures.toSignature)
val signatureInfos = alternatives.flatMap(Signatures.toSignature(_)(using ctx))
new SignatureHelp(
signatureInfos.map(signatureToSignatureInformation).asJava,
callableN,
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.4.2
sbt.version=1.4.5
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.5")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.2.13")
addSbtPlugin("org.scalameta" % "sbt-munit" % "0.7.19")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0")
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.4.6")
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.5.1")
addSbtPlugin("com.github.reibitto" % "sbt-welcome" % "0.2.1")

libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value
Expand Down
11 changes: 9 additions & 2 deletions sbt-metals/src/main/scala/scala/meta/metals/MetalsPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,15 @@ object MetalsPlugin extends AutoPlugin {
} else {
val sdbOptions = semanticdbOptions.value
(old.toVector ++ sdbOptions ++
(if (ScalaInstance.isDotty(versionOfScala)) Some("-Ysemanticdb")
else None)).distinct
(if (ScalaInstance.isDotty(versionOfScala)) {
if (
versionOfScala == "3.0.0-M1" || versionOfScala == "3.0.0-M2" || versionOfScala
.startsWith("0.")
)
Some("-Ysemanticdb")
else
Some("-Xsemanticdb")
} else None)).distinct
}
},
semanticdbEnabled := {
Expand Down
7 changes: 4 additions & 3 deletions tests/cross/src/main/scala/tests/pc/BaseHoverSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import scala.meta.internal.metals.CompilerOffsetParams
import scala.meta.internal.mtags.MtagsEnrichments._

import munit.Location
import munit.TestOptions
import tests.BasePCSuite
import tests.RangeReplace
import tests.TestHovers
Expand All @@ -17,16 +18,16 @@ abstract class BaseHoverSuite
with RangeReplace {

def check(
name: String,
testOpt: TestOptions,
original: String,
expected: String,
includeRange: Boolean = false,
automaticPackage: Boolean = true,
compat: Map[String, String] = Map.empty
)(implicit loc: Location): Unit = {
test(name) {
test(testOpt) {
val filename = "Hover.scala"
val pkg = scala.meta.Term.Name(name).syntax
val pkg = scala.meta.Term.Name(testOpt.name).syntax
val noRange = original
.replace("<<", "")
.replace(">>", "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ class CancelCompletionSuite extends BaseCompletionSuite {
"3.0.0-M2" ->
"""|assert(assertion: Boolean @InlineParam): Unit
|""".stripMargin,
"3.0.0-M3" ->
"""|assert(assertion: Boolean @InlineParam): Unit
|""".stripMargin,
"3.0" ->
"""|assert(assertion: Boolean @InlineParam): Unit
|assertFail(message: => Any): Nothing
Expand Down
5 changes: 4 additions & 1 deletion tests/cross/src/test/scala/tests/pc/CompletionSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,10 @@ class CompletionSuite extends BaseCompletionSuite {
| class Inner
|}
|""".stripMargin,
""
"",
compat = Map(
"3.0.0-M3" -> "Inner: a.Outer.Inner$"
)
)

check(
Expand Down
3 changes: 1 addition & 2 deletions tests/mtest/src/main/scala/tests/BaseSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ class BaseSuite extends munit.FunSuite with Assertions {
.orElse {
compat.collect {
// fallback to 3.0 for 0. pre-release versions
case (ver, code)
if scalaVersion.startsWith("0.") && ver.startsWith("3.") =>
case (ver, code) if scalaVersion.startsWith("0.") && ver == "3.0" =>
code
}.headOption
}
Expand Down
2 changes: 1 addition & 1 deletion tests/slow/src/test/scala/tests/sbt/SbtBloopLspSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ class SbtBloopLspSuite
"build.sbt",
"sc@@alaVersion := \"2.12.11\"",
".metals/readonly/sbt/Keys.scala",
expectedLine = 189
expectedLine = 190
)
} yield ()
}
Expand Down

0 comments on commit fe09b97

Please sign in to comment.