Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial Fix #21242: Add REPL init script setting #22206

Merged
merged 3 commits into from
Jan 9, 2025

Conversation

noti0na1
Copy link
Member

@noti0na1 noti0na1 commented Dec 13, 2024

Partial fix #21242

Test with flag at REPL startup:

> ./bin/scalaQ --repl-init-script 'println("Hello from init script!"); val i = 2 * 2'
[warning] MainGenericRunner class is deprecated since Scala 3.5.0, and Scala CLI features will not work.
[warning] Please be sure to update to the Scala CLI launcher to use the new features.
[warning] Check the Scala 3.5.0 release notes to troubleshoot your installation.
Hello from init script!
val i: Int = 4
Welcome to Scala 3.6.4-RC1-bin-SNAPSHOT-nonbootstrapped-git-5ea7c13 (17.0.12, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
                                                                                                                                            
scala> 

Test inside REPL:

sbt:scala3> repl
Welcome to Scala 3.6.4-RC1-bin-SNAPSHOT-nonbootstrapped-git-20e6f11 (17.0.12, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
                                                                                                                                            
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!
                                                                                                                                            
scala> 

scala-cli can use this flag to passing init code to REPL.

@noti0na1 noti0na1 changed the title Add REPL init script setting Fix #21242: Add REPL init script setting Dec 13, 2024
@tgodzik tgodzik added the release-notes Should be mentioned in the release notes label Dec 30, 2024
@noti0na1 noti0na1 marked this pull request as ready for review January 8, 2025 15:16
@noti0na1 noti0na1 requested review from Gedochao and dwijnand January 8, 2025 15:52
Copy link
Contributor

@Gedochao Gedochao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Note that in the current state, this PR covers for the first point in #21242 requirements, only- that is, a way to pass a code snippet or source file to the REPL main class to be executed at REPL startup.

We'll still need a follow-up, to cover for the second one: a way to skip the interactive mode and execute the script inside of the REPL, similar to what the -e flag does outside of the REPL.

Seems to me like we shouldn't close the issue with this just yet.

@noti0na1 noti0na1 changed the title Fix #21242: Add REPL init script setting Partial Fix #21242: Add REPL init script setting Jan 9, 2025
@noti0na1 noti0na1 merged commit 0677702 into scala:main Jan 9, 2025
29 checks passed
@noti0na1 noti0na1 deleted the fix-21242 branch January 9, 2025 14:10
@WojciechMazur WojciechMazur added this to the 3.6.4 milestone Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes Should be mentioned in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a setting/API to run a code snippet/script in the REPL on startup
5 participants