@@ -44,7 +44,7 @@ import scala.language.implicitConversions
44
44
import scala .util .control .NonFatal
45
45
import scala .util .Using
46
46
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.6.4 /compiler/src/dotty/tools/repl/ReplDriver.scala
48
48
* Main REPL instance, orchestrating input, compilation and presentation
49
49
* */
50
50
class DottyReplDriver (settings : Array [String ],
@@ -66,8 +66,21 @@ class DottyReplDriver(settings: Array[String],
66
66
setupRootCtx(this .settings ++ settings, rootCtx)
67
67
}
68
68
69
+ private val incompatibleOptions : Seq [String ] = Seq (
70
+ initCtx.settings.YbestEffort .name,
71
+ initCtx.settings.YwithBestEffortTasty .name
72
+ )
73
+
69
74
private def setupRootCtx (settings : Array [String ], rootCtx : Context ): Context = {
70
- setup(settings, rootCtx) match
75
+ val incompatible = settings.intersect(incompatibleOptions)
76
+ val filteredSettings =
77
+ if ! incompatible.isEmpty then
78
+ inContext(rootCtx) {
79
+ out.println(i " Options incompatible with repl will be ignored: ${incompatible.mkString(" , " )}" )
80
+ }
81
+ settings.filter(! incompatible.contains(_))
82
+ else settings
83
+ setup(filteredSettings, rootCtx) match
71
84
case Some ((files, ictx)) => inContext(ictx) {
72
85
shouldStart = true
73
86
if files.nonEmpty then out.println(i " Ignoring spurious arguments: $files%, % " )
@@ -81,7 +94,11 @@ class DottyReplDriver(settings: Array[String],
81
94
82
95
/** the initial, empty state of the REPL session */
83
96
final def initialState : State =
84
- State (0 , 0 , Map .empty, Set .empty, rootCtx)
97
+ val emptyState = State (0 , 0 , Map .empty, Set .empty, false , rootCtx)
98
+ val initScript = rootCtx.settings.replInitScript.value(using rootCtx)
99
+ initScript.trim() match
100
+ case " " => emptyState
101
+ case script => run(script)(using emptyState)
85
102
86
103
/** Reset state of repl to the initial state
87
104
*
@@ -184,11 +201,6 @@ class DottyReplDriver(settings: Array[String],
184
201
interpret(ParseResult .complete(input))
185
202
}
186
203
187
- final def runQuietly (input : String )(using State ): State = runBody {
188
- val parsed = ParseResult (input)
189
- interpret(parsed, quiet = true )
190
- }
191
-
192
204
protected def runBody (body : => State ): State = rendering.classLoader()(using rootCtx).asContext(withRedirectedOutput(body))
193
205
194
206
// TODO: i5069
@@ -256,10 +268,10 @@ class DottyReplDriver(settings: Array[String],
256
268
.getOrElse(Nil )
257
269
end completions
258
270
259
- protected def interpret (res : ParseResult , quiet : Boolean = false )(using state : State ): State = {
271
+ protected def interpret (res : ParseResult )(using state : State ): State = {
260
272
res match {
261
273
case parsed : Parsed if parsed.trees.nonEmpty =>
262
- compile(parsed, state, quiet )
274
+ compile(parsed, state)
263
275
264
276
case SyntaxErrors (_, errs, _) =>
265
277
displayErrors(errs)
@@ -277,7 +289,7 @@ class DottyReplDriver(settings: Array[String],
277
289
}
278
290
279
291
/** Compile `parsed` trees and evolve `state` in accordance */
280
- private def compile (parsed : Parsed , istate : State , quiet : Boolean = false ): State = {
292
+ private def compile (parsed : Parsed , istate : State ): State = {
281
293
def extractNewestWrapper (tree : untpd.Tree ): Name = tree match {
282
294
case PackageDef (_, (obj : untpd.ModuleDef ) :: Nil ) => obj.name.moduleClassName
283
295
case _ => nme.NO_NAME
@@ -328,11 +340,9 @@ class DottyReplDriver(settings: Array[String],
328
340
given Ordering [Diagnostic ] =
329
341
Ordering [(Int , Int , Int )].on(d => (d.pos.line, - d.level, d.pos.column))
330
342
331
- if (! quiet) {
332
- (definitions ++ warnings)
333
- .sorted
334
- .foreach(printDiagnostic)
335
- }
343
+ (if istate.quiet then warnings else definitions ++ warnings)
344
+ .sorted
345
+ .foreach(printDiagnostic)
336
346
337
347
updatedState
338
348
}
@@ -507,6 +517,8 @@ class DottyReplDriver(settings: Array[String],
507
517
rootCtx = setupRootCtx(tokenize(arg).toArray, rootCtx)
508
518
state.copy(context = rootCtx)
509
519
520
+ case Silent => state.copy(quiet = ! state.quiet)
521
+
510
522
case Quit =>
511
523
// end of the world!
512
524
// MP: slight variation from original DottyReplDriver to support exiting via the Quit command
0 commit comments