Skip to content

Commit

Permalink
chore: Add support for Scala 3.3.2-RC1
Browse files Browse the repository at this point in the history
We already publish separate module in the compiler that allows user to have right from the box support for Scala 3.3.2 and later, but not all PRs were yet backported, which means the experience for users could be worse under 3.3.1, which we would like to avoid.
  • Loading branch information
tgodzik committed Dec 19, 2023
1 parent 1e77550 commit e2a3715
Show file tree
Hide file tree
Showing 17 changed files with 77 additions and 8 deletions.
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def isScala2(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 2)
def isScala3(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 3)
def isScala3WithPresentationCompiler(v: String): Boolean =
(Version.parse(v), Version.parse(V.firstScala3PCVersion)) match {
case (Some(v), _) if V.supportedScalaVersions.contains(v.toString()) =>
false
case (Some(v), Some(firstScala3PCVersion)) => v >= firstScala3PCVersion
case _ => false
}
Expand Down
4 changes: 4 additions & 0 deletions mtags/src/main/scala-3.0/scala/meta/internal/pc/Compat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package scala.meta.internal.pc

object Compat:
val EvidenceParamName = dotty.tools.dotc.core.NameKinds.EvidenceParamName
4 changes: 4 additions & 0 deletions mtags/src/main/scala-3.1/scala/meta/internal/pc/Compat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package scala.meta.internal.pc

object Compat:
val EvidenceParamName = dotty.tools.dotc.core.NameKinds.EvidenceParamName
4 changes: 4 additions & 0 deletions mtags/src/main/scala-3.2/scala/meta/internal/pc/Compat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package scala.meta.internal.pc

object Compat:
val EvidenceParamName = dotty.tools.dotc.core.NameKinds.EvidenceParamName
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package scala.meta.internal.pc

object Compat:
val EvidenceParamName = dotty.tools.dotc.core.NameKinds.EvidenceParamName
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package scala.meta.internal.pc

object Compat:
val EvidenceParamName = dotty.tools.dotc.core.NameKinds.EvidenceParamName
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package scala.meta.internal.pc.printer

import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.printing.RefinedPrinter

abstract class RefinedDotcPrinter(_ctx: Context) extends RefinedPrinter(_ctx)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package scala.meta.internal.pc

object Compat:
val EvidenceParamName = dotty.tools.dotc.core.NameKinds.ContextBoundParamName
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package scala.meta.internal.pc.printer

import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.printing.RefinedPrinter
import dotty.tools.dotc.core.Types.*
import dotty.tools.dotc.core.Flags.*
import dotty.tools.dotc.printing.Texts.Text
import dotty.tools.dotc.core.StdNames.*

/* In 3.4.x some changes were made to printer,
but haven't managed to port all of them yet to the LTS */
abstract class RefinedDotcPrinter(_ctx: Context) extends RefinedPrinter(_ctx):

def toTextPrefix(tp: Type) =
tp match
case tp: NamedType => super.toTextPrefixOf(tp)
case tp => Text()

override def toText(tp: Type): Text =
tp match
case tp: TermRef
if !tp.denotationIsCurrent && !homogenizedView ||
tp.symbol.is(Module) || tp.symbol.name == nme.IMPORT =>
toTextPrefix(tp.prefix) ~ selectionString(tp) ~ ".type"
case tp: TermRef =>
toTextPrefix(tp.prefix) ~ selectionString(tp)
case tr: TypeRef =>
super.toText(tr)
case _ => super.toText(tp)
end RefinedDotcPrinter
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package scala.meta.internal.pc.completions

import scala.meta.internal.pc.Compat
import scala.meta.pc.PresentationCompilerConfig

import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.ast.tpd.*
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Flags.*
import dotty.tools.dotc.core.NameKinds.*
import dotty.tools.dotc.core.Symbols.NoSymbol
import dotty.tools.dotc.core.Types.ExprType
import dotty.tools.dotc.core.Types.MethodOrPoly
Expand Down Expand Up @@ -112,7 +112,7 @@ object ScaladocCompletions:
defdef.trailingParamss.flatten.collect {
case param
if !param.symbol.isOneOf(Synthetic) &&
!param.name.is(EvidenceParamName) &&
!param.name.is(Compat.EvidenceParamName) &&
param.symbol != extensionParam =>
param.name.show
}
Expand All @@ -121,7 +121,7 @@ object ScaladocCompletions:
case param
if !param.is(Synthetic) &&
!param.isTypeParam &&
!param.name.is(EvidenceParamName) =>
!param.name.is(Compat.EvidenceParamName) =>
param.name.show
}
case other =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import scala.meta.internal.jdk.CollectionConverters.*
import scala.meta.internal.metals.Report
import scala.meta.internal.metals.ReportContext
import scala.meta.internal.mtags.MtagsEnrichments.*
import scala.meta.internal.pc.Compat.EvidenceParamName
import scala.meta.internal.pc.IndexedContext
import scala.meta.internal.pc.Params
import scala.meta.internal.pc.printer.ShortenedNames.ShortName
Expand All @@ -18,7 +19,6 @@ import scala.meta.pc.SymbolSearch
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Flags
import dotty.tools.dotc.core.Flags.*
import dotty.tools.dotc.core.NameKinds.EvidenceParamName
import dotty.tools.dotc.core.NameOps.*
import dotty.tools.dotc.core.Names.Name
import dotty.tools.dotc.core.StdNames
Expand Down
2 changes: 1 addition & 1 deletion project/V.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object V {
val wrapperMetalsVersion = "3.4.0-RC1-bin-20231127-41e7d95-NIGHTLY"

// When you can add to removedScalaVersions in MtagsResolver.scala with the last released version
val scala3RC: Option[String] = None
val scala3RC: Option[String] = Some("3.3.2-RC1")
val sbtScala = "2.12.17"
val ammonite212Version = "2.12.18"
val ammonite213Version = "2.13.12"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ class CompletionOverrideSuite extends BaseCompletionSuite {
)

checkEdit(
"jlang",
"jlang".tag(IgnoreScalaVersion("3.3.2-RC1")),
"""|abstract class Mutable {
| def foo: java.lang.StringBuilder
|}
Expand Down
7 changes: 7 additions & 0 deletions tests/cross/src/test/scala/tests/pc/CompletionSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,13 @@ class CompletionSuite extends BaseCompletionSuite {
|higherKinds scala.languageFeature
|implicitConversions scala.languageFeature
|""".stripMargin,
">=3.3.2-RC1" ->
"""|dynamics languageFeature
|existentials languageFeature
|experimental languageFeature
|higherKinds languageFeature
|implicitConversions languageFeature
|""".stripMargin,
">=3.4.0-RC1-bin-20230921-3d539e6-NIGHTLY" ->
"""|dynamics scala.languageFeature
|existentials scala.languageFeature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ class InsertInferredTypeSuite extends BaseCodeActionSuite {
)

checkEdit(
"path",
"path".tag(IgnoreScalaVersion("3.3.2-RC1")),
"""|import java.nio.file.Paths
|object ExplicitResultTypesPrefix {
| class Path
Expand Down
2 changes: 1 addition & 1 deletion tests/mtest/src/main/scala/tests/BaseSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class BaseSuite extends munit.FunSuite with Assertions {
val FlakyWindows = new Tag("FlakyWindows")

val scala3PresentationCompilerVersion: String =
s">=${BuildInfoVersions.firstScala3PCVersion}"
s">=3.3.3"

Testing.enable()

Expand Down

0 comments on commit e2a3715

Please sign in to comment.