aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Davis2022-09-04 04:29:20 +0000
committerGitHub2022-09-04 04:29:20 +0000
commitf0d1caafcf0f2941110084a29cf4ce9d83071433 (patch)
treeb8569f13a3bab3fcc02b678ee15cc5623357d89b
parent0d76775453fcb99653c106bce62ec179eda2b196 (diff)
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.
-rw-r--r--helix-view/src/document.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index 3c406f8b..3f8dc4e6 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<BoxFuture<'static, Result<Transaction, FormatterError>>> {
- 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);