Skip to content

Commit

Permalink
Put quiet into State of REPL
Browse files Browse the repository at this point in the history
... so that we can toggle it
  • Loading branch information
natsukagami committed Dec 19, 2024
1 parent 83fe5a7 commit b084a23
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions compiler/src/dotty/tools/repl/ReplDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ import scala.util.Using
* @param valIndex the index of next value binding for free expressions
* @param imports a map from object index to the list of user defined imports
* @param invalidObjectIndexes the set of object indexes that failed to initialize
* @param quiet whether we print evaluation results
* @param context the latest compiler context
*/
case class State(objectIndex: Int,
valIndex: Int,
imports: Map[Int, List[tpd.Import]],
invalidObjectIndexes: Set[Int],
quiet: Boolean,
context: Context):
def validObjectIndexes = (1 to objectIndex).filterNot(invalidObjectIndexes.contains(_))

Expand Down Expand Up @@ -114,7 +116,7 @@ class ReplDriver(settings: Array[String],
}

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

/** Reset state of repl to the initial state
*
Expand Down Expand Up @@ -217,11 +219,6 @@ class ReplDriver(settings: Array[String],
interpret(ParseResult.complete(input))
}

final def runQuietly(input: String)(using State): State = runBody {
val parsed = ParseResult(input)
interpret(parsed, quiet = true)
}

protected def runBody(body: => State): State = rendering.classLoader()(using rootCtx).asContext(withRedirectedOutput(body))

// TODO: i5069
Expand Down Expand Up @@ -290,10 +287,10 @@ class ReplDriver(settings: Array[String],
.getOrElse(Nil)
end completions

protected def interpret(res: ParseResult, quiet: Boolean = false)(using state: State): State = {
protected def interpret(res: ParseResult)(using state: State): State = {
res match {
case parsed: Parsed if parsed.trees.nonEmpty =>
compile(parsed, state, quiet)
compile(parsed, state)

case SyntaxErrors(_, errs, _) =>
displayErrors(errs)
Expand All @@ -311,7 +308,7 @@ class ReplDriver(settings: Array[String],
}

/** Compile `parsed` trees and evolve `state` in accordance */
private def compile(parsed: Parsed, istate: State, quiet: Boolean = false): State = {
private def compile(parsed: Parsed, istate: State): State = {
def extractNewestWrapper(tree: untpd.Tree): Name = tree match {
case PackageDef(_, (obj: untpd.ModuleDef) :: Nil) => obj.name.moduleClassName
case _ => nme.NO_NAME
Expand Down Expand Up @@ -362,7 +359,7 @@ class ReplDriver(settings: Array[String],
given Ordering[Diagnostic] =
Ordering[(Int, Int, Int)].on(d => (d.pos.line, -d.level, d.pos.column))

(if quiet then warnings else definitions ++ warnings)
(if istate.quiet then warnings else definitions ++ warnings)
.sorted
.foreach(printDiagnostic)

Expand Down

0 comments on commit b084a23

Please sign in to comment.