Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Command config:
- `stdin` - If the text should be provided via stdin (default: `true`)
- `cwd` - Current working directory to use when launching this command (default: dprint's cwd or the root `cwd` setting if set)
- `cacheKeyFiles` - A list of paths (relative to `cwd`) to files used to automatically compute a `cacheKey`. This allows automatic invalidation of dprint's incremental cache when any of these files are changed.
- `setupCommand` - Command to run a single time before this command formats its first file. It runs to completion before any formatting starts, which is useful for one-time setup that would otherwise race when formatting in parallel (ex. installing a toolchain). It is only run when a file actually matches this command, runs in the command's `cwd`, is subject to the same `timeout`, and is not run if formatting is cancelled. It does not support command templates.
- `setupCommand` - Command to run a single time before this command formats its first file. It runs to completion before any formatting starts, which is useful for one-time setup that would otherwise race when formatting in parallel (ex. installing a toolchain). It is only run when a file actually matches this command, runs in the command's `cwd`, is not subject to the `timeout`, and is not run if formatting is cancelled. It does not support command templates.

Command templates (ex. see the prettier example above):

Expand Down
12 changes: 2 additions & 10 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub async fn format_bytes(
// run the command's setup once before formatting with it for the first time
if let Some(setup_command) = &command.setup_command {
match setup_state
.run_once(&command.cwd, setup_command, &config, &token)
.run_once(&command.cwd, setup_command, &token)
.await?
{
SetupRun::Completed => {}
Expand Down Expand Up @@ -368,7 +368,6 @@ impl SetupState {
&self,
cwd: &Path,
setup_command: &SetupCommand,
config: &Configuration,
token: &Arc<dyn CancellationToken>,
) -> Result<SetupRun> {
// the cwd is part of the key because the same command run in different
Expand All @@ -387,7 +386,7 @@ impl SetupState {
// the others wait for it to finish; a failure is not cached so it can be
// retried by the next file rather than poisoning all formatting
match cell
.get_or_try_init(|| run_setup_command(cwd, setup_command, config, token))
.get_or_try_init(|| run_setup_command(cwd, setup_command, token))
.await
{
Ok(()) => Ok(SetupRun::Completed),
Expand All @@ -400,7 +399,6 @@ impl SetupState {
async fn run_setup_command(
cwd: &Path,
setup_command: &SetupCommand,
config: &Configuration,
token: &Arc<dyn CancellationToken>,
) -> Result<(), SetupInitError> {
let mut child = ChildKillOnDrop(
Expand Down Expand Up @@ -442,12 +440,6 @@ async fn run_setup_command(

tokio::select! {
_ = token.wait_cancellation() => Err(SetupInitError::Cancelled),
_ = tokio::time::sleep(Duration::from_secs(config.timeout as u64)) => {
Err(SetupInitError::Failed(anyhow!(
"Setup command has not returned a result within {} seconds.",
config.timeout,
)))
}
result = result_future => match result {
Ok(exit_status) if exit_status.success() => Ok(()),
Ok(exit_status) => Err(SetupInitError::Failed(anyhow!(
Expand Down
Loading