Add extra logging for external formatters and formatting errors

This should help debug formatting failures when using external
formatters in the future. Previously we didn't log anything when an
external formatter failed despite having a custom error type for it.
This commit is contained in:
Michael Davis 2025-01-17 10:55:25 -05:00
parent 4c41c5250c
commit 69068770c8
No known key found for this signature in database
2 changed files with 18 additions and 8 deletions

View File

@ -3438,7 +3438,8 @@ async fn make_format_callback(
let doc = doc_mut!(editor, &doc_id); let doc = doc_mut!(editor, &doc_id);
let view = view_mut!(editor, view_id); let view = view_mut!(editor, view_id);
if let Ok(format) = format { match format {
Ok(format) => {
if doc.version() == doc_version { if doc.version() == doc_version {
doc.apply(&format, view.id); doc.apply(&format, view.id);
doc.append_changes_to_history(view); doc.append_changes_to_history(view);
@ -3448,6 +3449,10 @@ async fn make_format_callback(
log::info!("discarded formatting changes because the document changed"); log::info!("discarded formatting changes because the document changed");
} }
} }
Err(err) => {
log::info!("failed to format '{}': {err}", doc.display_name());
}
}
if let Some((path, force)) = write { if let Some((path, force)) = write {
let id = doc.id(); let id = doc.id();

View File

@ -772,6 +772,11 @@ pub fn format(&self) -> Option<BoxFuture<'static, Result<Transaction, FormatterE
)) ))
}) })
{ {
log::debug!(
"formatting '{}' with command '{}', args {fmt_args:?}",
self.display_name(),
fmt_cmd.display(),
);
use std::process::Stdio; use std::process::Stdio;
let text = self.text().clone(); let text = self.text().clone();