Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ trait CommonScalaSettings:
val encoding: Setting[String] = StringSetting(RootSetting, "encoding", "encoding", "Specify character encoding used by source files.", Properties.sourceEncoding, aliases = List("--encoding"))
val usejavacp: Setting[Boolean] = BooleanSetting(RootSetting, "usejavacp", "Utilize the java.class.path in classpath resolution.", aliases = List("--use-java-class-path"))
val scalajs: Setting[Boolean] = BooleanSetting(RootSetting, "scalajs", "Compile in Scala.js mode (requires scalajs-library.jar on the classpath).", aliases = List("--scalajs"))
val replInitScript: Setting[String] = StringSetting(RootSetting, "repl-init-script", "code", "The code will be run on REPL startup.", "", aliases = List("--repl-init-script"))
end CommonScalaSettings

/** -P "plugin" settings. Various tools might support plugins. */
Expand Down
7 changes: 6 additions & 1 deletion compiler/src/dotty/tools/repl/ReplDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ class ReplDriver(settings: Array[String],
}

/** the initial, empty state of the REPL session */
final def initialState: State = State(0, 0, Map.empty, Set.empty, false, rootCtx)
final def initialState: State =
val emptyState = State(0, 0, Map.empty, Set.empty, false, rootCtx)
val initScript = rootCtx.settings.replInitScript.value(using rootCtx)
initScript.trim() match
case "" => emptyState
case script => run(script)(using emptyState)

/** Reset state of repl to the initial state
*
Expand Down
5 changes: 5 additions & 0 deletions compiler/test-resources/repl/init-script-flag
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
scala>:reset --repl-init-script:'println("Hello from init script!")'
Resetting REPL state with the following settings:
--repl-init-script:println("Hello from init script!")

Hello from init script!
Loading