From e2a3715324ac44033a6f110b9de62b983c959d46 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Tue, 19 Dec 2023 12:53:05 +0100 Subject: [PATCH] chore: Add support for Scala 3.3.2-RC1 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. --- build.sbt | 2 ++ .../scala/meta/internal/pc/Compat.scala | 4 +++ .../scala/meta/internal/pc/Compat.scala | 4 +++ .../scala/meta/internal/pc/Compat.scala | 4 +++ .../scala/meta/internal/pc/Compat.scala | 4 +++ .../pc/printer/RefinedDotcPrinter.scala | 0 .../scala/meta/internal/pc/Compat.scala | 4 +++ .../pc/printer/RefinedDotcPrinter.scala | 6 ++++ .../scala/meta/internal/pc/Compat.scala | 4 +++ .../pc/printer/RefinedDotcPrinter.scala | 30 +++++++++++++++++++ .../pc/completions/ScaladocCompletions.scala | 6 ++-- .../internal/pc/printer/MetalsPrinter.scala | 2 +- project/V.scala | 2 +- .../tests/pc/CompletionOverrideSuite.scala | 2 +- .../test/scala/tests/pc/CompletionSuite.scala | 7 +++++ .../tests/pc/InsertInferredTypeSuite.scala | 2 +- .../src/main/scala/tests/BaseSuite.scala | 2 +- 17 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 mtags/src/main/scala-3.0/scala/meta/internal/pc/Compat.scala create mode 100644 mtags/src/main/scala-3.1/scala/meta/internal/pc/Compat.scala create mode 100644 mtags/src/main/scala-3.2/scala/meta/internal/pc/Compat.scala create mode 100644 mtags/src/main/scala-3.3.0/scala/meta/internal/pc/Compat.scala rename mtags/src/main/{scala-3.3 => scala-3.3.0}/scala/meta/internal/pc/printer/RefinedDotcPrinter.scala (100%) create mode 100644 mtags/src/main/scala-3.3.1/scala/meta/internal/pc/Compat.scala create mode 100644 mtags/src/main/scala-3.3.1/scala/meta/internal/pc/printer/RefinedDotcPrinter.scala create mode 100644 mtags/src/main/scala-3.3.2-RC1/scala/meta/internal/pc/Compat.scala create mode 100644 mtags/src/main/scala-3.3.2-RC1/scala/meta/internal/pc/printer/RefinedDotcPrinter.scala diff --git a/build.sbt b/build.sbt index 3495085bcc4..20261f222d8 100644 --- a/build.sbt +++ b/build.sbt @@ -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 } diff --git a/mtags/src/main/scala-3.0/scala/meta/internal/pc/Compat.scala b/mtags/src/main/scala-3.0/scala/meta/internal/pc/Compat.scala new file mode 100644 index 00000000000..b6a4d617c5f --- /dev/null +++ b/mtags/src/main/scala-3.0/scala/meta/internal/pc/Compat.scala @@ -0,0 +1,4 @@ +package scala.meta.internal.pc + +object Compat: + val EvidenceParamName = dotty.tools.dotc.core.NameKinds.EvidenceParamName diff --git a/mtags/src/main/scala-3.1/scala/meta/internal/pc/Compat.scala b/mtags/src/main/scala-3.1/scala/meta/internal/pc/Compat.scala new file mode 100644 index 00000000000..b6a4d617c5f --- /dev/null +++ b/mtags/src/main/scala-3.1/scala/meta/internal/pc/Compat.scala @@ -0,0 +1,4 @@ +package scala.meta.internal.pc + +object Compat: + val EvidenceParamName = dotty.tools.dotc.core.NameKinds.EvidenceParamName diff --git a/mtags/src/main/scala-3.2/scala/meta/internal/pc/Compat.scala b/mtags/src/main/scala-3.2/scala/meta/internal/pc/Compat.scala new file mode 100644 index 00000000000..b6a4d617c5f --- /dev/null +++ b/mtags/src/main/scala-3.2/scala/meta/internal/pc/Compat.scala @@ -0,0 +1,4 @@ +package scala.meta.internal.pc + +object Compat: + val EvidenceParamName = dotty.tools.dotc.core.NameKinds.EvidenceParamName diff --git a/mtags/src/main/scala-3.3.0/scala/meta/internal/pc/Compat.scala b/mtags/src/main/scala-3.3.0/scala/meta/internal/pc/Compat.scala new file mode 100644 index 00000000000..b6a4d617c5f --- /dev/null +++ b/mtags/src/main/scala-3.3.0/scala/meta/internal/pc/Compat.scala @@ -0,0 +1,4 @@ +package scala.meta.internal.pc + +object Compat: + val EvidenceParamName = dotty.tools.dotc.core.NameKinds.EvidenceParamName diff --git a/mtags/src/main/scala-3.3/scala/meta/internal/pc/printer/RefinedDotcPrinter.scala b/mtags/src/main/scala-3.3.0/scala/meta/internal/pc/printer/RefinedDotcPrinter.scala similarity index 100% rename from mtags/src/main/scala-3.3/scala/meta/internal/pc/printer/RefinedDotcPrinter.scala rename to mtags/src/main/scala-3.3.0/scala/meta/internal/pc/printer/RefinedDotcPrinter.scala diff --git a/mtags/src/main/scala-3.3.1/scala/meta/internal/pc/Compat.scala b/mtags/src/main/scala-3.3.1/scala/meta/internal/pc/Compat.scala new file mode 100644 index 00000000000..b6a4d617c5f --- /dev/null +++ b/mtags/src/main/scala-3.3.1/scala/meta/internal/pc/Compat.scala @@ -0,0 +1,4 @@ +package scala.meta.internal.pc + +object Compat: + val EvidenceParamName = dotty.tools.dotc.core.NameKinds.EvidenceParamName diff --git a/mtags/src/main/scala-3.3.1/scala/meta/internal/pc/printer/RefinedDotcPrinter.scala b/mtags/src/main/scala-3.3.1/scala/meta/internal/pc/printer/RefinedDotcPrinter.scala new file mode 100644 index 00000000000..21b5271f330 --- /dev/null +++ b/mtags/src/main/scala-3.3.1/scala/meta/internal/pc/printer/RefinedDotcPrinter.scala @@ -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) diff --git a/mtags/src/main/scala-3.3.2-RC1/scala/meta/internal/pc/Compat.scala b/mtags/src/main/scala-3.3.2-RC1/scala/meta/internal/pc/Compat.scala new file mode 100644 index 00000000000..1f87fbfe851 --- /dev/null +++ b/mtags/src/main/scala-3.3.2-RC1/scala/meta/internal/pc/Compat.scala @@ -0,0 +1,4 @@ +package scala.meta.internal.pc + +object Compat: + val EvidenceParamName = dotty.tools.dotc.core.NameKinds.ContextBoundParamName diff --git a/mtags/src/main/scala-3.3.2-RC1/scala/meta/internal/pc/printer/RefinedDotcPrinter.scala b/mtags/src/main/scala-3.3.2-RC1/scala/meta/internal/pc/printer/RefinedDotcPrinter.scala new file mode 100644 index 00000000000..fbd39a46ff5 --- /dev/null +++ b/mtags/src/main/scala-3.3.2-RC1/scala/meta/internal/pc/printer/RefinedDotcPrinter.scala @@ -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 diff --git a/mtags/src/main/scala-3/scala/meta/internal/pc/completions/ScaladocCompletions.scala b/mtags/src/main/scala-3/scala/meta/internal/pc/completions/ScaladocCompletions.scala index 4875d222ac9..04f0e064343 100644 --- a/mtags/src/main/scala-3/scala/meta/internal/pc/completions/ScaladocCompletions.scala +++ b/mtags/src/main/scala-3/scala/meta/internal/pc/completions/ScaladocCompletions.scala @@ -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 @@ -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 } @@ -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 => diff --git a/mtags/src/main/scala-3/scala/meta/internal/pc/printer/MetalsPrinter.scala b/mtags/src/main/scala-3/scala/meta/internal/pc/printer/MetalsPrinter.scala index a7e22f878ef..6e713b466d9 100644 --- a/mtags/src/main/scala-3/scala/meta/internal/pc/printer/MetalsPrinter.scala +++ b/mtags/src/main/scala-3/scala/meta/internal/pc/printer/MetalsPrinter.scala @@ -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 @@ -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 diff --git a/project/V.scala b/project/V.scala index 0b9575202e1..e7f672a2323 100644 --- a/project/V.scala +++ b/project/V.scala @@ -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" diff --git a/tests/cross/src/test/scala/tests/pc/CompletionOverrideSuite.scala b/tests/cross/src/test/scala/tests/pc/CompletionOverrideSuite.scala index 49d4a0ee850..81c3d9ba26d 100644 --- a/tests/cross/src/test/scala/tests/pc/CompletionOverrideSuite.scala +++ b/tests/cross/src/test/scala/tests/pc/CompletionOverrideSuite.scala @@ -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 |} diff --git a/tests/cross/src/test/scala/tests/pc/CompletionSuite.scala b/tests/cross/src/test/scala/tests/pc/CompletionSuite.scala index 2727939d0ad..2a5e6fbc458 100644 --- a/tests/cross/src/test/scala/tests/pc/CompletionSuite.scala +++ b/tests/cross/src/test/scala/tests/pc/CompletionSuite.scala @@ -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 diff --git a/tests/cross/src/test/scala/tests/pc/InsertInferredTypeSuite.scala b/tests/cross/src/test/scala/tests/pc/InsertInferredTypeSuite.scala index 8a8cbb2f883..cc6b615de81 100644 --- a/tests/cross/src/test/scala/tests/pc/InsertInferredTypeSuite.scala +++ b/tests/cross/src/test/scala/tests/pc/InsertInferredTypeSuite.scala @@ -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 diff --git a/tests/mtest/src/main/scala/tests/BaseSuite.scala b/tests/mtest/src/main/scala/tests/BaseSuite.scala index ba74663b83c..bfa69f8da51 100644 --- a/tests/mtest/src/main/scala/tests/BaseSuite.scala +++ b/tests/mtest/src/main/scala/tests/BaseSuite.scala @@ -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()