diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 1c1edece1a313..fc77f7a18938a 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -5037,6 +5037,16 @@ fn shell_impl(shell: &[String], cmd: &str, input: Option) -> anyhow::Resul tokio::task::block_in_place(|| helix_lsp::block_on(shell_impl_async(shell, cmd, input))) } +fn async_shell_impl( + shell: &[String], + cmd: &str, + input: Option, +) -> impl std::future::Future> { + let shell = shell.to_vec(); + let cmd = cmd.to_string(); + async move { shell_impl_async(&shell, &cmd, input).await } +} + async fn shell_impl_async( shell: &[String], cmd: &str, diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 6fbdc0d7afa31..7cf2d0c7fc5bb 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -2061,17 +2061,12 @@ fn run_shell_command( } let shell = &cx.editor.config().shell; - let (output, success) = shell_impl(shell, &args.join(" "), None)?; - if success { - cx.editor.set_status("Command succeeded"); - } else { - cx.editor.set_error("Command failed"); - } - - if !output.is_empty() { - let callback = async move { - let call: job::Callback = Callback::EditorCompositor(Box::new( - move |editor: &mut Editor, compositor: &mut Compositor| { + let job = async_shell_impl(shell, &args.join(" "), None); + let callback = async move { + let (output, success) = job.await?; + let call: job::Callback = Callback::EditorCompositor(Box::new( + move |editor: &mut Editor, compositor: &mut Compositor| { + if !output.is_empty() { let contents = ui::Markdown::new( format!("```sh\n{}\n```", output), editor.syn_loader.clone(), @@ -2080,13 +2075,17 @@ fn run_shell_command( helix_core::Position::new(editor.cursor().0.unwrap_or_default().row, 2), )); compositor.replace_or_push("shell", popup); - }, - )); - Ok(call) - }; - - cx.jobs.callback(callback); - } + } + if success { + editor.set_status("Command succeeded"); + } else { + editor.set_error("Command failed"); + } + }, + )); + Ok(call) + }; + cx.jobs.callback(callback); Ok(()) }