Skip to content

[1.x] Pass reload action for watchOnTermination callback #7838

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

Merged
merged 1 commit into from
Oct 28, 2024

Conversation

Friendseeker
Copy link
Member

@Friendseeker Friendseeker commented Oct 28, 2024

Issue

In watch mode, when a Reload action is triggered, sbt do not pass the Reload action to watchOnTermination callback (instead falls back to CancelWatch action)

Since onTerminationImpl (default implementation of watchOnTermination) does filtering based on type of action passed in, not passing Reload action cause unnecessary filtering resulting in #7017.

/**
* Default handler to transform the state when the watch terminates. When the [[Watch.Action]]
* is [[Reload]], the handler will prepend the original command (prefixed by ~) to the
* [[State.remainingCommands]] and then invoke the [[StateOps.reload]] method. When the
* [[Watch.Action]] is [[HandleError]], the handler returns the result of [[StateOps.fail]].
* When the [[Watch.Action]] is [[Watch.Run]], we add the commands specified by
* [[Watch.Run.commands]] to the stat's remaining commands. Otherwise the original state is
* returned.
*/
private def onTerminationImpl(
watchPrefixes: String*
): (Action, String, Int, State) => State = { (action, command, count, state) =>
val prefix = watchPrefixes.head
val rc = state.remainingCommands
.filterNot(c => watchPrefixes.exists(c.commandLine.trim.startsWith))
action match {
case Run(commands) => state.copy(remainingCommands = commands ++ rc)
case Reload =>
state.copy(remainingCommands = "reload".toExec :: s"$prefix $count $command".toExec :: rc)
case _: HandleError => state.copy(remainingCommands = rc).fail
case _ => state.copy(remainingCommands = rc)
}

Fix

#6870 introduces failAction as a mechanism to store & pass action to watchOnTermination callback. This PR employs same mechanism to pass watch action.

Closes #7017

@Friendseeker Friendseeker requested a review from eed3si9n October 28, 2024 06:05
Copy link
Member

@eed3si9n eed3si9n left a comment

Choose a reason for hiding this comment

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

Thanks!

@eed3si9n eed3si9n merged commit 64f0acf into sbt:1.10.x Oct 28, 2024
10 checks passed
@eed3si9n eed3si9n added this to the 1.10.4 milestone Oct 28, 2024
@Friendseeker Friendseeker deleted the sbt-7017 branch October 28, 2024 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reload during ~ quits sbt
2 participants