Skip to content

Commit 5ea7c13

Browse files
committed
Add REPL init script setting
1 parent ec0a310 commit 5ea7c13

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Diff for: compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ trait CommonScalaSettings:
126126
val encoding: Setting[String] = StringSetting(RootSetting, "encoding", "encoding", "Specify character encoding used by source files.", Properties.sourceEncoding, aliases = List("--encoding"))
127127
val usejavacp: Setting[Boolean] = BooleanSetting(RootSetting, "usejavacp", "Utilize the java.class.path in classpath resolution.", aliases = List("--use-java-class-path"))
128128
val scalajs: Setting[Boolean] = BooleanSetting(RootSetting, "scalajs", "Compile in Scala.js mode (requires scalajs-library.jar on the classpath).", aliases = List("--scalajs"))
129+
val replInitScript: Setting[String] = StringSetting(RootSetting, "repl-init-script", "code", "The code will be run on REPL startup.", "")
129130
end CommonScalaSettings
130131

131132
/** -P "plugin" settings. Various tools might support plugins. */

Diff for: compiler/src/dotty/tools/repl/ReplDriver.scala

+6-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,12 @@ class ReplDriver(settings: Array[String],
116116
}
117117

118118
/** the initial, empty state of the REPL session */
119-
final def initialState: State = State(0, 0, Map.empty, Set.empty, false, rootCtx)
119+
final def initialState: State =
120+
val emptyState = State(0, 0, Map.empty, Set.empty, false, rootCtx)
121+
val initScript = rootCtx.settings.replInitScript.value(using rootCtx)
122+
initScript.trim() match
123+
case "" => emptyState
124+
case script => run(script)(using emptyState)
120125

121126
/** Reset state of repl to the initial state
122127
*

0 commit comments

Comments
 (0)