From 8d0158eaa0f150e92fda95a7f58f298adf735c13 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sat, 3 Sep 2022 10:43:20 -0500 Subject: [PATCH] Look for the external formatter before invoking it 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. --- helix-view/src/document.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 3c406f8b5232..3f8dc4e6a734 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -407,7 +407,11 @@ impl Document { // We can't use anyhow::Result here since the output of the future has to be // clonable to be used as shared future. So use a custom error type. pub fn format(&self) -> Option>> { - if let Some(formatter) = self.language_config().and_then(|c| c.formatter.clone()) { + if let Some(formatter) = self + .language_config() + .and_then(|c| c.formatter.clone()) + .filter(|formatter| which::which(&formatter.command).is_ok()) + { use std::process::Stdio; let text = self.text().clone(); let mut process = tokio::process::Command::new(&formatter.command);