on master help sign in
use which on formatter command (#8064)
6bef982Ezekiel Warren
helix-view/src/document.rs+6−6
@@ -733,16 +733,16 @@ impl Document {
733 // We can't use anyhow::Result here since the output of the future has to be
733 // We can't use anyhow::Result here since the output of the future has to be
734 // clonable to be used as shared future. So use a custom error type.
734 // clonable to be used as shared future. So use a custom error type.
735 pub fn format(&self) -> Option<BoxFuture<'static, Result<Transaction, FormatterError>>> {
735 pub fn format(&self) -> Option<BoxFuture<'static, Result<Transaction, FormatterError>>> {
736− if let Some(formatter) = self
736+ if let Some((fmt_cmd, fmt_args)) = self
737 .language_config()
737 .language_config()
738− .and_then(|c| c.formatter.clone())
738+ .and_then(|c| c.formatter.as_ref())
739− .filter(|formatter| which::which(&formatter.command).is_ok())
739+ .and_then(|formatter| Some((which::which(&formatter.command).ok()?, &formatter.args)))
740 {
740 {
741 use std::process::Stdio;
741 use std::process::Stdio;
742 let text = self.text().clone();
742 let text = self.text().clone();
743− let mut process = tokio::process::Command::new(&formatter.command);
743+ let mut process = tokio::process::Command::new(&fmt_cmd);
744 process
744 process
745− .args(&formatter.args)
745+ .args(fmt_args)
746 .stdin(Stdio::piped())
746 .stdin(Stdio::piped())
747 .stdout(Stdio::piped())
747 .stdout(Stdio::piped())
748 .stderr(Stdio::piped());
748 .stderr(Stdio::piped());
@@ -751,7 +751,7 @@ impl Document {
751 let mut process = process
751 let mut process = process
752 .spawn()
752 .spawn()
753 .map_err(|e| FormatterError::SpawningFailed {
753 .map_err(|e| FormatterError::SpawningFailed {
754− command: formatter.command.clone(),
754+ command: fmt_cmd.to_string_lossy().into(),
755 error: e.kind(),
755 error: e.kind(),
756 })?;
756 })?;
757 {
757 {