diff options
author | Skyler Hawthorne | 2022-09-17 03:17:48 +0000 |
---|---|---|
committer | Skyler Hawthorne | 2022-10-19 02:31:39 +0000 |
commit | 3f07885b351748c5b8225aadb165f8ef7066f047 (patch) | |
tree | 37ece44a32184a6902fccdab77adaf13713917bc /helix-term/src/commands.rs | |
parent | b530a86d1f15cc7df0e1ae8aa4bd02109ac33a8f (diff) |
document should save even if formatter fails
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r-- | helix-term/src/commands.rs | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 6deecbe2..f6d583f5 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2518,7 +2518,8 @@ async fn make_format_callback( format: impl Future<Output = Result<Transaction, FormatterError>> + Send + 'static, write: Option<(Option<PathBuf>, bool)>, ) -> anyhow::Result<job::Callback> { - let format = format.await?; + let format = format.await; + let call: job::Callback = Callback::Editor(Box::new(move |editor| { if !editor.documents.contains_key(&doc_id) { return; @@ -2528,19 +2529,21 @@ async fn make_format_callback( let doc = doc_mut!(editor, &doc_id); let view = view_mut!(editor); - if doc.version() == doc_version { - apply_transaction(&format, doc, view); - doc.append_changes_to_history(view.id); - doc.detect_indent_and_line_ending(); - view.ensure_cursor_in_view(doc, scrolloff); + if let Ok(format) = format { + if doc.version() == doc_version { + apply_transaction(&format, doc, view); + doc.append_changes_to_history(view.id); + doc.detect_indent_and_line_ending(); + view.ensure_cursor_in_view(doc, scrolloff); + } else { + log::info!("discarded formatting changes because the document changed"); + } + } - if let Some((path, force)) = write { - if let Err(err) = doc.save(path, force) { - editor.set_error(format!("Error saving: {}", err)); - } + if let Some((path, force)) = write { + if let Err(err) = doc.save(path, force) { + editor.set_error(format!("Error saving: {}", err)); } - } else { - log::info!("discarded formatting changes because the document changed"); } })); |