on master help sign in
Look for the external formatter before invoking it (#3670)

Currently it is not possible to save a file with a language that has an external formatter configuration unless the external formatter is installed, even if the language has a Language Server configuration capable of auto-format. This change checks that the external formatter exists before using it to create a formatting callback.

commitf0d1caafcf0f2941110084a29cf4ce9d83071433 authorMichael Davis <mcarsondavis@gmail.com> dateSat 3 Sep 2022, 23:29 (4 years ago) parent0d76775
1 file changed+5−1
helix-view/src/document.rs+5−1
helix-view/src/document.rs+5−1
@@ -407,7 +407,11 @@ impl Document {
407407 // We can't use anyhow::Result here since the output of the future has to be
408408 // clonable to be used as shared future. So use a custom error type.
409409 pub fn format(&self) -> Option<BoxFuture<'static, Result<Transaction, FormatterError>>> {
410− if let Some(formatter) = self.language_config().and_then(|c| c.formatter.clone()) {
410+ if let Some(formatter) = self
411+ .language_config()
412+ .and_then(|c| c.formatter.clone())
413+ .filter(|formatter| which::which(&formatter.command).is_ok())
414+ {
411415 use std::process::Stdio;
412416 let text = self.text().clone();
413417 let mut process = tokio::process::Command::new(&formatter.command);