Skip to content

Commit f301125

Browse files
the-mikedavisShekhinah Memmel
authored andcommitted
Look for the external formatter before invoking it (helix-editor#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.
1 parent 318c744 commit f301125

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

helix-view/src/document.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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);

0 commit comments

Comments
 (0)