@@ -51,7 +51,7 @@ import scala.collection.JavaConverters._
51
51
case class State (objectIndex : Int ,
52
52
valIndex : Int ,
53
53
imports : List [untpd.Import ],
54
- run : Run )
54
+ context : Context )
55
55
56
56
/** Main REPL instance, orchestrating input, compilation and presentation */
57
57
class ReplDriver (settings : Array [String ],
@@ -72,7 +72,7 @@ class ReplDriver(settings: Array[String],
72
72
}
73
73
74
74
/** the initial, empty state of the REPL session */
75
- protected [this ] def initState = State (0 , 0 , Nil , compiler.newRun( rootCtx, 0 ) )
75
+ protected [this ] def initState = State (0 , 0 , Nil , rootCtx)
76
76
77
77
/** Reset state of repl to the initial state
78
78
*
@@ -118,7 +118,7 @@ class ReplDriver(settings: Array[String],
118
118
val comps = completions(line.cursor, line.line, state)
119
119
candidates.addAll(comps.asJava)
120
120
}
121
- implicit val ctx = state.run.runContext
121
+ implicit val ctx = state.context
122
122
try {
123
123
val line = terminal.readLine(completer)
124
124
ParseResult (line)
@@ -140,16 +140,16 @@ class ReplDriver(settings: Array[String],
140
140
}
141
141
142
142
final def run (input : String )(implicit state : State ): State = withRedirectedOutput {
143
- val parsed = ParseResult (input)(state.run.runContext )
143
+ val parsed = ParseResult (input)(state.context )
144
144
interpret(parsed)
145
145
}
146
146
147
147
private def withRedirectedOutput (op : => State ): State =
148
148
Console .withOut(out) { Console .withErr(out) { op } }
149
149
150
150
private def newRun (state : State ) = {
151
- val newRun = compiler.newRun(rootCtx.fresh.setReporter(newStoreReporter), state.objectIndex)
152
- state.copy(run = newRun )
151
+ val run = compiler.newRun(rootCtx.fresh.setReporter(newStoreReporter), state.objectIndex)
152
+ state.copy(context = run.runContext )
153
153
}
154
154
155
155
/** Extract possible completions at the index of `cursor` in `expr` */
@@ -173,7 +173,7 @@ class ReplDriver(settings: Array[String],
173
173
val file = new SourceFile (" <completions>" , expr)
174
174
val unit = new CompilationUnit (file)
175
175
unit.tpdTree = tree
176
- implicit val ctx = state.run.runContext .fresh.setCompilationUnit(unit)
176
+ implicit val ctx = state.context .fresh.setCompilationUnit(unit)
177
177
val srcPos = SourcePosition (file, Position (cursor))
178
178
val (_, completions) = Interactive .completions(srcPos)
179
179
completions.map(makeCandidate)
@@ -224,16 +224,16 @@ class ReplDriver(settings: Array[String],
224
224
val newImports = newState.imports ++ extractImports(parsed.trees)
225
225
val newStateWithImports = newState.copy(imports = newImports)
226
226
227
- // display warnings
228
- displayErrors(newState.run.runContext.flushBufferedMessages()) (newState)
227
+ val warnings = newState.context.reporter.removeBufferedMessages(newState.context)
228
+ displayErrors(warnings) (newState) // display warnings
229
229
displayDefinitions(unit.tpdTree, newestWrapper)(newStateWithImports)
230
230
}
231
231
)
232
232
}
233
233
234
234
/** Display definitions from `tree` */
235
235
private def displayDefinitions (tree : tpd.Tree , newestWrapper : Name )(implicit state : State ): State = {
236
- implicit val ctx = state.run.runContext
236
+ implicit val ctx = state.context
237
237
238
238
def resAndUnit (denot : Denotation ) = {
239
239
import scala .util .{Success , Try }
@@ -319,7 +319,7 @@ class ReplDriver(settings: Array[String],
319
319
initState
320
320
321
321
case Imports =>
322
- state.imports.foreach(i => out.println(SyntaxHighlighting (i.show(state.run.runContext ))))
322
+ state.imports.foreach(i => out.println(SyntaxHighlighting (i.show(state.context ))))
323
323
state
324
324
325
325
case Load (path) =>
@@ -356,7 +356,7 @@ class ReplDriver(settings: Array[String],
356
356
357
357
/** Output errors to `out` */
358
358
private def displayErrors (errs : Seq [MessageContainer ])(implicit state : State ): State = {
359
- errs.map(renderMessage(_)(state.run.runContext )).foreach(out.println)
359
+ errs.map(renderMessage(_)(state.context )).foreach(out.println)
360
360
state
361
361
}
362
362
}
0 commit comments