@@ -59,12 +59,14 @@ import scala.util.Using
5959 * @param valIndex the index of next value binding for free expressions
6060 * @param imports a map from object index to the list of user defined imports
6161 * @param invalidObjectIndexes the set of object indexes that failed to initialize
62+ * @param quiet whether we print evaluation results
6263 * @param context the latest compiler context
6364 */
6465case class State (objectIndex : Int ,
6566 valIndex : Int ,
6667 imports : Map [Int , List [tpd.Import ]],
6768 invalidObjectIndexes : Set [Int ],
69+ quiet : Boolean ,
6870 context : Context ):
6971 def validObjectIndexes = (1 to objectIndex).filterNot(invalidObjectIndexes.contains(_))
7072
@@ -100,7 +102,7 @@ class ReplDriver(settings: Array[String],
100102 }
101103
102104 /** the initial, empty state of the REPL session */
103- final def initialState : State = State (0 , 0 , Map .empty, Set .empty, rootCtx)
105+ final def initialState : State = State (0 , 0 , Map .empty, Set .empty, false , rootCtx)
104106
105107 /** Reset state of repl to the initial state
106108 *
@@ -203,11 +205,6 @@ class ReplDriver(settings: Array[String],
203205 interpret(ParseResult .complete(input))
204206 }
205207
206- final def runQuietly (input : String )(using State ): State = runBody {
207- val parsed = ParseResult (input)
208- interpret(parsed, quiet = true )
209- }
210-
211208 protected def runBody (body : => State ): State = rendering.classLoader()(using rootCtx).asContext(withRedirectedOutput(body))
212209
213210 // TODO: i5069
@@ -291,10 +288,10 @@ class ReplDriver(settings: Array[String],
291288 .getOrElse(Nil )
292289 end completionsWithSignatures
293290
294- protected def interpret (res : ParseResult , quiet : Boolean = false )(using state : State ): State = {
291+ protected def interpret (res : ParseResult )(using state : State ): State = {
295292 res match {
296293 case parsed : Parsed if parsed.trees.nonEmpty =>
297- compile(parsed, state, quiet )
294+ compile(parsed, state)
298295
299296 case SyntaxErrors (_, errs, _) =>
300297 displayErrors(errs)
@@ -312,7 +309,7 @@ class ReplDriver(settings: Array[String],
312309 }
313310
314311 /** Compile `parsed` trees and evolve `state` in accordance */
315- private def compile (parsed : Parsed , istate : State , quiet : Boolean = false ): State = {
312+ private def compile (parsed : Parsed , istate : State ): State = {
316313 def extractNewestWrapper (tree : untpd.Tree ): Name = tree match {
317314 case PackageDef (_, (obj : untpd.ModuleDef ) :: Nil ) => obj.name.moduleClassName
318315 case _ => nme.NO_NAME
@@ -363,11 +360,9 @@ class ReplDriver(settings: Array[String],
363360 given Ordering [Diagnostic ] =
364361 Ordering [(Int , Int , Int )].on(d => (d.pos.line, - d.level, d.pos.column))
365362
366- if (! quiet) {
367- (definitions ++ warnings)
368- .sorted
369- .foreach(printDiagnostic)
370- }
363+ (if istate.quiet then warnings else definitions ++ warnings)
364+ .sorted
365+ .foreach(printDiagnostic)
371366
372367 updatedState
373368 }
@@ -543,6 +538,8 @@ class ReplDriver(settings: Array[String],
543538 rootCtx = setupRootCtx(tokenize(arg).toArray, rootCtx)
544539 state.copy(context = rootCtx)
545540
541+ case Silent => state.copy(quiet = ! state.quiet)
542+
546543 case Quit =>
547544 // end of the world!
548545 state
0 commit comments