@@ -8,7 +8,7 @@ use tui::text::Spans;
88pub use typed::*;
99
1010use helix_core::{
11− comment, coords_at_pos, find_first_non_whitespace_char, find_root, graphemes,
11+ comment, coords_at_pos, encoding, find_first_non_whitespace_char, find_root, graphemes,
1212 history::UndoKind,
1313 increment::date_time::DateTimeIncrementor,
1414 increment::{number::NumberIncrementor, Increment},
@@ -4630,7 +4630,7 @@ fn shell_keep_pipe(cx: &mut Context) {
46304630
46314631 for (i, range) in selection.ranges().iter().enumerate() {
46324632 let fragment = range.slice(text);
4633− let (_output, success) = match shell_impl(shell, input, Some(fragment)) {
4633+ let (_output, success) = match shell_impl(shell, input, Some(fragment.into())) {
46344634 Ok(result) => result,
46354635 Err(err) => {
46364636 cx.editor.set_error(err.to_string());
@@ -4658,13 +4658,17 @@ fn shell_keep_pipe(cx: &mut Context) {
46584658 );
46594659}
46604660
4661−fn shell_impl(
4661+fn shell_impl(shell: &[String], cmd: &str, input: Option<Rope>) -> anyhow::Result<(Tendril, bool)> {
4662+ tokio::task::block_in_place(|| helix_lsp::block_on(shell_impl_async(shell, cmd, input)))
4663+}
4664+
4665+async fn shell_impl_async(
46624666 shell: &[String],
46634667 cmd: &str,
4664− input: Option<RopeSlice>,
4668+ input: Option<Rope>,
46654669) -> anyhow::Result<(Tendril, bool)> {
4666− use std::io::Write;
4667− use std::process::{Command, Stdio};
4670+ use std::process::Stdio;
4671+ use tokio::process::Command;
46684672 ensure!(!shell.is_empty(), "No shell set");
46694673
46704674 let mut process = Command::new(&shell[0]);
@@ -4687,13 +4691,22 @@ fn shell_impl(
46874691 return Err(e.into());
46884692 }
46894693 };
4690− if let Some(input) = input {
4691− let mut stdin = process.stdin.take().unwrap();
4692− for chunk in input.chunks() {
4693− stdin.write_all(chunk.as_bytes())?;
4694− }
4695− }
4696− let output = process.wait_with_output()?;
4694+ let output = if let Some(mut stdin) = process.stdin.take() {
4695+ let input_task = tokio::spawn(async move {
4696+ if let Some(input) = input {
4697+ helix_view::document::to_writer(&mut stdin, encoding::UTF_8, &input).await?;
4698+ }
4699+ Ok::<_, anyhow::Error>(())
4700+ });
4701+ let (output, _) = tokio::join! {
4702+ process.wait_with_output(),
4703+ input_task,
4704+ };
4705+ output?
4706+ } else {
4707+ // Process has no stdin, so we just take the output
4708+ process.wait_with_output().await?
4709+ };
46974710
46984711 if !output.status.success() {
46994712 if !output.stderr.is_empty() {
@@ -4731,7 +4744,7 @@ fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) {
47314744
47324745 for range in selection.ranges() {
47334746 let fragment = range.slice(text);
4734− let (output, success) = match shell_impl(shell, cmd, pipe.then(|| fragment)) {
4747+ let (output, success) = match shell_impl(shell, cmd, pipe.then(|| fragment.into())) {
47354748 Ok(result) => result,
47364749 Err(err) => {
47374750 cx.editor.set_error(err.to_string());