Skip to content

Commit bcb229e

Browse files
noti0na1tgodzik
authored andcommitted
Add REPL init script setting
1 parent a804950 commit bcb229e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ trait CommonScalaSettings:
134134
val encoding: Setting[String] = StringSetting("-encoding", "encoding", "Specify character encoding used by source files.", Properties.sourceEncoding, aliases = List("--encoding"))
135135
val usejavacp: Setting[Boolean] = BooleanSetting("-usejavacp", "Utilize the java.class.path in classpath resolution.", aliases = List("--use-java-class-path"))
136136
val scalajs: Setting[Boolean] = BooleanSetting("-scalajs", "Compile in Scala.js mode (requires scalajs-library.jar on the classpath).", aliases = List("--scalajs"))
137+
val replInitScript: Setting[String] = StringSetting("-repl-init-script", "code", "The code will be run on REPL startup.", "")
138+
137139
end CommonScalaSettings
138140

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

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ class ReplDriver(settings: Array[String],
102102
}
103103

104104
/** the initial, empty state of the REPL session */
105-
final def initialState: State = State(0, 0, Map.empty, Set.empty, false, rootCtx)
105+
final def initialState: State =
106+
val emptyState = State(0, 0, Map.empty, Set.empty, false, rootCtx)
107+
val initScript = rootCtx.settings.replInitScript.value(using rootCtx)
108+
initScript.trim() match
109+
case "" => emptyState
110+
case script => run(script)(using emptyState)
106111

107112
/** Reset state of repl to the initial state
108113
*

0 commit comments

Comments
 (0)