on master help sign in
remove Document::format_and_save
commit9e64974f13e91470be7b411285b7a33c698da3aa authorSkyler Hawthorne <skyler@dead10ck.com> dateFri 16 Sep 2022, 23:32 (4 years ago) parent3f07885
1 file changed+3−40
helix-view/src/document.rs+3−40
helix-view/src/document.rs+3−40
@@ -520,32 +520,12 @@ impl Document {
520520 path: Option<P>,
521521 force: bool,
522522 ) -> Result<(), anyhow::Error> {
523− self.save_impl::<futures_util::future::Ready<_>, _>(None, path, force)
524− }
525−
526− pub fn format_and_save<F, P>(
527− &mut self,
528− formatting: Option<F>,
529− path: Option<P>,
530− force: bool,
531− ) -> anyhow::Result<()>
532− where
533− F: Future<Output = Result<Transaction, FormatterError>> + 'static + Send,
534− P: Into<PathBuf>,
535− {
536− self.save_impl(formatting, path, force)
523+ self.save_impl::<futures_util::future::Ready<_>, _>(path, force)
537524 }
538525
539526 /// The `Document`'s text is encoded according to its encoding and written to the file located
540527 /// at its `path()`.
541− ///
542− /// If `formatting` is present, it supplies some changes that we apply to the text before saving.
543− fn save_impl<F, P>(
544− &mut self,
545− formatting: Option<F>,
546− path: Option<P>,
547− force: bool,
548− ) -> Result<(), anyhow::Error>
528+ fn save_impl<F, P>(&mut self, path: Option<P>, force: bool) -> Result<(), anyhow::Error>
549529 where
550530 F: Future<Output = Result<Transaction, FormatterError>> + 'static + Send,
551531 P: Into<PathBuf>,
@@ -561,7 +541,7 @@ impl Document {
561541
562542 // we clone and move text + path into the future so that we asynchronously save the current
563543 // state without blocking any further edits.
564− let mut text = self.text().clone();
544+ let text = self.text().clone();
565545
566546 let path = match path {
567547 Some(path) => helix_core::path::get_canonicalized_path(&path.into())?,
@@ -602,23 +582,6 @@ impl Document {
602582 }
603583 }
604584
605− if let Some(fmt) = formatting {
606− match fmt.await {
607− Ok(transaction) => {
608− let success = transaction.changes().apply(&mut text);
609− if !success {
610− // This shouldn't happen, because the transaction changes were generated
611− // from the same text we're saving.
612− log::error!("failed to apply format changes before saving");
613− }
614− }
615− Err(err) => {
616− // formatting failed: report error, and save file without modifications
617− log::error!("{}", err);
618− }
619− }
620− }
621−
622585 let mut file = File::create(&path).await?;
623586 to_writer(&mut file, encoding, &text).await?;
624587