Skip to content

Commit

Permalink
Add REPL init script setting
Browse files Browse the repository at this point in the history
  • Loading branch information
noti0na1 committed Dec 13, 2024
1 parent 20e6f11 commit eee5988
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
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.", "")
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 @@ -114,7 +114,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, rootCtx)
final def initialState: State =
val emptyState = State(0, 0, Map.empty, Set.empty, 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

0 comments on commit eee5988

Please sign in to comment.