@@ -118,7 +118,7 @@ class ReplDriver(settings: Array[String],
118
118
private var rootCtx : Context = _
119
119
private var shouldStart : Boolean = _
120
120
private var compiler : ReplCompiler = _
121
- private var rendering : Rendering = _
121
+ protected var rendering : Rendering = _
122
122
123
123
// initialize the REPL session as part of the constructor so that once `run`
124
124
// is called, we're in business
@@ -138,7 +138,7 @@ class ReplDriver(settings: Array[String],
138
138
* observable outside of the CLI, for this reason, most helper methods are
139
139
* `protected final` to facilitate testing.
140
140
*/
141
- final def runUntilQuit (using initialState : State = initialState)(): State = {
141
+ def runUntilQuit (using initialState : State = initialState)(): State = {
142
142
val terminal = new JLineTerminal
143
143
144
144
out.println(
@@ -176,7 +176,12 @@ class ReplDriver(settings: Array[String],
176
176
interpret(ParseResult .complete(input))
177
177
}
178
178
179
- private def runBody (body : => State ): State = rendering.classLoader()(using rootCtx).asContext(withRedirectedOutput(body))
179
+ final def runQuietly (input : String )(using State ): State = runBody {
180
+ val parsed = ParseResult (input)
181
+ interpret(parsed, quiet = true )
182
+ }
183
+
184
+ protected def runBody (body : => State ): State = rendering.classLoader()(using rootCtx).asContext(withRedirectedOutput(body))
180
185
181
186
// TODO: i5069
182
187
final def bind (name : String , value : Any )(using state : State ): State = state
@@ -242,10 +247,10 @@ class ReplDriver(settings: Array[String],
242
247
.getOrElse(Nil )
243
248
end completions
244
249
245
- private def interpret (res : ParseResult )(using state : State ): State = {
250
+ protected def interpret (res : ParseResult , quiet : Boolean = false )(using state : State ): State = {
246
251
res match {
247
252
case parsed : Parsed if parsed.trees.nonEmpty =>
248
- compile(parsed, state)
253
+ compile(parsed, state, quiet )
249
254
250
255
case SyntaxErrors (_, errs, _) =>
251
256
displayErrors(errs)
@@ -263,7 +268,7 @@ class ReplDriver(settings: Array[String],
263
268
}
264
269
265
270
/** Compile `parsed` trees and evolve `state` in accordance */
266
- private def compile (parsed : Parsed , istate : State ): State = {
271
+ private def compile (parsed : Parsed , istate : State , quiet : Boolean = false ): State = {
267
272
def extractNewestWrapper (tree : untpd.Tree ): Name = tree match {
268
273
case PackageDef (_, (obj : untpd.ModuleDef ) :: Nil ) => obj.name.moduleClassName
269
274
case _ => nme.NO_NAME
@@ -314,9 +319,11 @@ class ReplDriver(settings: Array[String],
314
319
given Ordering [Diagnostic ] =
315
320
Ordering [(Int , Int , Int )].on(d => (d.pos.line, - d.level, d.pos.column))
316
321
317
- (definitions ++ warnings)
318
- .sorted
319
- .foreach(printDiagnostic)
322
+ if (! quiet) {
323
+ (definitions ++ warnings)
324
+ .sorted
325
+ .foreach(printDiagnostic)
326
+ }
320
327
321
328
updatedState
322
329
}
0 commit comments