Skip to content

Commit ca29bd8

Browse files
committed
repl: Dedup setup & warning between initialCtx & :settings
1 parent b3ab102 commit ca29bd8

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

compiler/src/dotty/tools/repl/ReplDriver.scala

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,26 @@ class ReplDriver(settings: Array[String],
6969
*/
7070
override def sourcesRequired: Boolean = false
7171

72-
/** Create a fresh and initialized context with IDE mode enabled */
73-
private def initialCtx = {
74-
val rootCtx = initCtx.fresh.addMode(Mode.ReadPositions | Mode.Interactive)
75-
rootCtx.setSetting(rootCtx.settings.YcookComments, true)
76-
rootCtx.setSetting(rootCtx.settings.YreadComments, true)
72+
private def setupRootCtx(settings: Array[String], rootCtx: Context) = {
7773
setup(settings, rootCtx) match
7874
case Some((files, ictx)) =>
7975
shouldStart = true
76+
if files.nonEmpty then inContext(ictx)(out.println(i"Ignoring spurious arguments: $files%, %"))
8077
ictx.base.initialize()(using ictx)
8178
ictx
8279
case None =>
8380
shouldStart = false
8481
rootCtx
8582
}
8683

84+
/** Create a fresh and initialized context with IDE mode enabled */
85+
private def initialCtx = {
86+
val rootCtx = initCtx.fresh.addMode(Mode.ReadPositions | Mode.Interactive)
87+
rootCtx.setSetting(rootCtx.settings.YcookComments, true)
88+
rootCtx.setSetting(rootCtx.settings.YreadComments, true)
89+
setupRootCtx(rootCtx, settings)
90+
}
91+
8792
/** the initial, empty state of the REPL session */
8893
final def initialState: State = State(0, 0, Map.empty, rootCtx)
8994

@@ -423,14 +428,7 @@ class ReplDriver(settings: Array[String],
423428
out.println(s"${s.name} = ${if s.value == "" then "\"\"" else s.value}")
424429
state
425430
case _ =>
426-
setup(tokenize(arg).toArray, rootCtx) match
427-
case Some((files, ictx)) =>
428-
inContext(ictx) {
429-
if files.nonEmpty then out.println(i"Ignoring spurious arguments: $files%, %")
430-
ictx.base.initialize()(using ictx)
431-
rootCtx = ictx
432-
}
433-
case _ =>
431+
rootCtx = setupRootCtx(tokenize(arg).toArray, rootCtx)
434432
state.copy(context = rootCtx)
435433

436434
case Quit =>

0 commit comments

Comments
 (0)