From 69068770c888c01d6e9e1ead02979bfdb1acd112 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Fri, 17 Jan 2025 10:55:25 -0500 Subject: [PATCH] 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. --- helix-term/src/commands.rs | 21 +++++++++++++-------- helix-view/src/document.rs | 5 +++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index aa159a992..583f46c33 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -3438,14 +3438,19 @@ async fn make_format_callback( let doc = doc_mut!(editor, &doc_id); let view = view_mut!(editor, view_id); - if let Ok(format) = format { - if doc.version() == doc_version { - doc.apply(&format, view.id); - doc.append_changes_to_history(view); - doc.detect_indent_and_line_ending(); - view.ensure_cursor_in_view(doc, scrolloff); - } else { - log::info!("discarded formatting changes because the document changed"); + match format { + Ok(format) => { + if doc.version() == doc_version { + doc.apply(&format, view.id); + doc.append_changes_to_history(view); + doc.detect_indent_and_line_ending(); + view.ensure_cursor_in_view(doc, scrolloff); + } else { + log::info!("discarded formatting changes because the document changed"); + } + } + Err(err) => { + log::info!("failed to format '{}': {err}", doc.display_name()); } } diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index edbc96b01..42e9b99d5 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -772,6 +772,11 @@ impl Document { )) }) { + log::debug!( + "formatting '{}' with command '{}', args {fmt_args:?}", + self.display_name(), + fmt_cmd.display(), + ); use std::process::Stdio; let text = self.text().clone();