Skip to content

Commit 67bd88c

Browse files
authored
support scala 3.3.6 LTS (mpollmeier#212)
1 parent da98a00 commit 67bd88c

File tree

5 files changed

+35
-17
lines changed

5 files changed

+35
-17
lines changed

build.sbt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ name := "scala-repl-pp-root"
22
ThisBuild/organization := "com.michaelpollmeier"
33
publish/skip := true
44

5-
lazy val scalaVersions = Seq("3.5.2", "3.6.4", "3.7.0")
5+
val scalaLTSVersion = "3.3.6"
6+
val scalaVersions = Seq(scalaLTSVersion, "3.6.4", "3.7.0")
67
ThisBuild/scalaVersion := scalaVersions.max
78
lazy val Slf4jVersion = "2.0.16"
89

@@ -27,8 +28,9 @@ lazy val core_364 = Build
2728
.enablePlugins(JavaAppPackaging)
2829
.settings(coreSettings)
2930

30-
lazy val core_352 = Build
31-
.newProject("core", "3.5.2", "scala-repl-pp")
31+
// Scala LTS version, only replace with next LTS release
32+
lazy val core_336 = Build
33+
.newProject("core", "3.3.6", "scala-repl-pp")
3234
.dependsOn(shadedLibs)
3335
.enablePlugins(JavaAppPackaging)
3436
.settings(coreSettings)
@@ -64,9 +66,9 @@ lazy val server_364 = Build
6466
.enablePlugins(JavaAppPackaging)
6567
.settings(serverSettings)
6668

67-
lazy val server_352 = Build
68-
.newProject("server", "3.5.2", "scala-repl-pp-server")
69-
.dependsOn(core_352)
69+
lazy val server_336 = Build
70+
.newProject("server", "3.3.6", "scala-repl-pp-server")
71+
.dependsOn(core_336)
7072
.enablePlugins(JavaAppPackaging)
7173
.settings(serverSettings)
7274

core/src/main/scala-3.5.2/replpp/DottyRandomStuff.scala renamed to core/src/main/scala-3.3.6/replpp/DottyRandomStuff.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,27 @@ import dotty.tools.repl.*
88
private[replpp] object DottyRandomStuff {
99

1010
/** Create empty outer store reporter
11-
* copied from https://github.com/lampepfl/dotty/blob/3.3.0-RC5/compiler/src/dotty/tools/repl/package.scala#L6 */
11+
* copied from https://github.com/lampepfl/dotty/blob/3.3.6/compiler/src/dotty/tools/repl/package.scala#L6 */
1212
def newStoreReporter: StoreReporter = {
1313
new StoreReporter(null) with UniqueMessagePositions with HideNonSensicalMessages
1414
}
1515

16-
/** Based on https://github.com/scala/scala3/blob/3.5.2/compiler/src/dotty/tools/repl/ParseResult.scala#L130
16+
/** Based on https://github.com/scala/scala3/blob/3.3.6/compiler/src/dotty/tools/repl/ParseResult.scala#L135
1717
* change: removed [private] classifier so we can access it...
1818
* alternatively we could use reflection...
1919
*/
2020
object ParseResult {
2121
val commands: List[(String, String => ParseResult)] = List(
2222
Quit.command -> (_ => Quit),
2323
Quit.alias -> (_ => Quit),
24-
Help.command -> (_ => Help),
25-
Reset.command -> (arg => Reset(arg)),
26-
Imports.command -> (_ => Imports),
24+
Help.command -> (_ => Help),
25+
Reset.command -> (arg => Reset(arg)),
26+
Imports.command -> (_ => Imports),
2727
Load.command -> (arg => Load(arg)),
2828
TypeOf.command -> (arg => TypeOf(arg)),
2929
DocOf.command -> (arg => DocOf(arg)),
3030
Settings.command -> (arg => Settings(arg)),
31+
Silent.command -> (_ => Silent),
3132
)
3233
}
3334
}

core/src/main/scala-3.5.2/replpp/DottyReplDriver.scala renamed to core/src/main/scala-3.3.6/replpp/DottyReplDriver.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import scala.language.implicitConversions
4444
import scala.util.control.NonFatal
4545
import scala.util.Using
4646

47-
/** Based on https://github.com/lampepfl/dotty/blob/3.4.2/compiler/src/dotty/tools/repl/ReplDriver.scala
47+
/** Based on https://github.com/lampepfl/dotty/blob/3.3.6/compiler/src/dotty/tools/repl/ReplDriver.scala
4848
* Main REPL instance, orchestrating input, compilation and presentation
4949
* */
5050
class DottyReplDriver(settings: Array[String],
@@ -61,8 +61,8 @@ class DottyReplDriver(settings: Array[String],
6161
/** Create a fresh and initialized context with IDE mode enabled */
6262
private def initialCtx(settings: List[String]): Context = {
6363
val rootCtx = initCtx.fresh.addMode(Mode.ReadPositions | Mode.Interactive)
64-
rootCtx.setSetting(rootCtx.settings.XcookComments, true)
65-
rootCtx.setSetting(rootCtx.settings.XreadComments, true)
64+
rootCtx.setSetting(rootCtx.settings.YcookComments, true)
65+
rootCtx.setSetting(rootCtx.settings.YreadComments, true)
6666
setupRootCtx(this.settings ++ settings, rootCtx)
6767
}
6868

@@ -81,7 +81,7 @@ class DottyReplDriver(settings: Array[String],
8181

8282
/** the initial, empty state of the REPL session */
8383
final def initialState: State =
84-
State(0, 0, Map.empty, Set.empty, rootCtx)
84+
State(0, 0, Map.empty, Set.empty, false, rootCtx)
8585

8686
/** Reset state of repl to the initial state
8787
*
@@ -507,6 +507,8 @@ class DottyReplDriver(settings: Array[String],
507507
rootCtx = setupRootCtx(tokenize(arg).toArray, rootCtx)
508508
state.copy(context = rootCtx)
509509

510+
case Silent => state.copy(quiet = !state.quiet)
511+
510512
case Quit =>
511513
// end of the world!
512514
// MP: slight variation from original DottyReplDriver to support exiting via the Quit command
@@ -524,7 +526,6 @@ class DottyReplDriver(settings: Array[String],
524526
private object ReplConsoleReporter extends ConsoleReporter.AbstractConsoleReporter {
525527
override def posFileStr(pos: SourcePosition) = "" // omit file paths
526528
override def printMessage(msg: String): Unit = out.println(msg)
527-
override def echoMessage(msg: String): Unit = printMessage(msg)
528529
override def flush()(using Context): Unit = out.flush()
529530
}
530531

core/src/main/scala/replpp/util/SimpleDriver.scala

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package replpp.util
22

33
import dotty.tools.dotc.Driver
4+
import dotty.tools.dotc.config.Settings
45
import dotty.tools.dotc.core.Contexts
56
import dotty.tools.dotc.core.Contexts.Context
67
import dotty.tools.dotc.reporting.{Diagnostic, Reporter}
@@ -52,12 +53,25 @@ class SimpleDriver(linesBeforeRunBeforeCode: Int = 0, linesBeforeScript: Int = 0
5253
}
5354

5455
ctx.setSetting(rootCtx.settings.outputDir, new PlainDirectory(Directory(outDir)))
55-
.setSetting(rootCtx.settings.XnoEnrichErrorMessages, !verbose)
5656
.setSetting(rootCtx.settings.help, verbose)
5757
.setSetting(rootCtx.settings.XshowPhases, verbose)
5858
.setSetting(rootCtx.settings.Vhelp, verbose)
5959
.setSetting(rootCtx.settings.Vprofile, verbose)
6060
.setSetting(rootCtx.settings.explain, verbose)
61+
62+
// Scala 3.3.6 has `YnoEnrichErrorMessages` rather than `XnoEnrichErrorMessages`
63+
// So as long as we still support 3.3.6 (i.e. until the next LTS release) we need the
64+
// following section.
65+
val noEnrichErrorMessagesRegex = "-[XY]no-enrich-error-messages".r
66+
rootCtx.settings.allSettings
67+
.find(setting => noEnrichErrorMessagesRegex.matches(setting.name))
68+
.foreach { noEnrichErrorMessagesSetting =>
69+
// println(s"setting $noEnrichErrorMessagesSetting to ${!verbose}")
70+
ctx.setSetting(noEnrichErrorMessagesSetting.asInstanceOf[Settings.Setting[Boolean]], !verbose)
71+
}
72+
// Once that's not required any longer, replace the above with this:
73+
// ctx.setSetting(rootCtx.settings.XnoEnrichErrorMessages, !verbose)
74+
ctx
6175
}
6276

6377
if (doCompile(newCompiler, toCompile).hasErrors) {

0 commit comments

Comments
 (0)