Skip to content

Commit e8b973c

Browse files
committed
repl: Add compiler options to :reset
1 parent ca29bd8 commit e8b973c

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ object Settings {
8888
/** Reset the session to the initial state from when the repl program was
8989
* started
9090
*/
91-
case object Reset extends Command {
91+
case class Reset(arg: String) extends Command
92+
object Reset {
9293
val command: String = ":reset"
9394
}
9495

@@ -110,7 +111,7 @@ case object Help extends Command {
110111
|:type <expression> evaluate the type of the given expression
111112
|:doc <expression> print the documentation for the given expression
112113
|:imports show import history
113-
|:reset reset the repl to its initial state, forgetting all session entries
114+
|:reset [options] reset the repl to its initial state, forgetting all session entries
114115
|:settings <options> update compiler options, if possible
115116
""".stripMargin
116117
}
@@ -130,7 +131,7 @@ object ParseResult {
130131
Quit.command -> (_ => Quit),
131132
Quit.alias -> (_ => Quit),
132133
Help.command -> (_ => Help),
133-
Reset.command -> (_ => Reset),
134+
Reset.command -> (arg => Reset(arg)),
134135
Imports.command -> (_ => Imports),
135136
Load.command -> (arg => Load(arg)),
136137
TypeOf.command -> (arg => TypeOf(arg)),

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ class ReplDriver(settings: Array[String],
8282
}
8383

8484
/** Create a fresh and initialized context with IDE mode enabled */
85-
private def initialCtx = {
85+
private def initialCtx(settings: List[String]) = {
8686
val rootCtx = initCtx.fresh.addMode(Mode.ReadPositions | Mode.Interactive)
8787
rootCtx.setSetting(rootCtx.settings.YcookComments, true)
8888
rootCtx.setSetting(rootCtx.settings.YreadComments, true)
89-
setupRootCtx(rootCtx, settings)
89+
setupRootCtx(rootCtx, this.settings ++ settings)
9090
}
9191

9292
/** the initial, empty state of the REPL session */
@@ -98,8 +98,8 @@ class ReplDriver(settings: Array[String],
9898
* such, when the user enters `:reset` this method should be called to reset
9999
* everything properly
100100
*/
101-
protected def resetToInitial(): Unit = {
102-
rootCtx = initialCtx
101+
protected def resetToInitial(settings: List[String] = Nil): Unit = {
102+
rootCtx = initialCtx(settings)
103103
if (rootCtx.settings.outputDir.isDefault(using rootCtx))
104104
rootCtx = rootCtx.fresh
105105
.setSetting(rootCtx.settings.outputDir, new VirtualDirectory("<REPL compilation output>"))
@@ -377,8 +377,8 @@ class ReplDriver(settings: Array[String],
377377
out.println(Help.text)
378378
state
379379

380-
case Reset =>
381-
resetToInitial()
380+
case Reset(arg) =>
381+
resetToInitial(tokenize(arg))
382382
initialState
383383

384384
case Imports =>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
scala> def f(thread: Thread) = thread.stop()
2+
there were 1 deprecation warning(s); re-run with -deprecation for details
3+
def f(thread: Thread): Unit
4+
5+
scala>:reset -deprecation
6+
7+
scala> def f(thread: Thread) = thread.stop()
8+
1 warning found
9+
-- Deprecation Warning: --------------------------------------------------------
10+
1 | def f(thread: Thread) = thread.stop()
11+
| ^^^^^^^^^^^
12+
|method stop in class Thread is deprecated since : see corresponding Javadoc for more information.
13+
def f(thread: Thread): Unit
14+
15+
scala>

0 commit comments

Comments
 (0)