on master help sign in
Handle formatter errors, and save anyway (#3684)
fe37a66A-Walrus
helix-view/src/document.rs+13−6
@@ -543,12 +543,19 @@ impl Document {
543 }
543 }
544
544
545 if let Some(fmt) = formatting {
545 if let Some(fmt) = formatting {
546− let transaction = fmt.await?;
546+ match fmt.await {
547+ Ok(transaction) => {
547− let success = transaction.changes().apply(&mut text);
548+ let success = transaction.changes().apply(&mut text);
548− if !success {
549+ if !success {
549− // This shouldn't happen, because the transaction changes were generated
550+ // This shouldn't happen, because the transaction changes were generated
550− // from the same text we're saving.
551+ // from the same text we're saving.
551− log::error!("failed to apply format changes before saving");
552+ log::error!("failed to apply format changes before saving");
553+ }
554+ }
555+ Err(err) => {
556+ // formatting failed: report error, and save file without modifications
557+ log::error!("{}", err);
558+ }
552 }
559 }
553 }
560 }
554
561