aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSkyler Hawthorne2022-09-17 03:32:25 +0000
committerSkyler Hawthorne2022-10-19 02:31:39 +0000
commit9e64974f13e91470be7b411285b7a33c698da3aa (patch)
treec724a4a9de80869ce36749517a21172537fd0bd8
parent3f07885b351748c5b8225aadb165f8ef7066f047 (diff)
remove Document::format_and_save
-rw-r--r--helix-view/src/document.rs43
1 files changed, 3 insertions, 40 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index ff64689e..4a09bedc 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -520,32 +520,12 @@ impl Document {
path: Option<P>,
force: bool,
) -> Result<(), anyhow::Error> {
- self.save_impl::<futures_util::future::Ready<_>, _>(None, path, force)
- }
-
- pub fn format_and_save<F, P>(
- &mut self,
- formatting: Option<F>,
- path: Option<P>,
- force: bool,
- ) -> anyhow::Result<()>
- where
- F: Future<Output = Result<Transaction, FormatterError>> + 'static + Send,
- P: Into<PathBuf>,
- {
- self.save_impl(formatting, path, force)
+ self.save_impl::<futures_util::future::Ready<_>, _>(path, force)
}
/// The `Document`'s text is encoded according to its encoding and written to the file located
/// at its `path()`.
- ///
- /// If `formatting` is present, it supplies some changes that we apply to the text before saving.
- fn save_impl<F, P>(
- &mut self,
- formatting: Option<F>,
- path: Option<P>,
- force: bool,
- ) -> Result<(), anyhow::Error>
+ fn save_impl<F, P>(&mut self, path: Option<P>, force: bool) -> Result<(), anyhow::Error>
where
F: Future<Output = Result<Transaction, FormatterError>> + 'static + Send,
P: Into<PathBuf>,
@@ -561,7 +541,7 @@ impl Document {
// we clone and move text + path into the future so that we asynchronously save the current
// state without blocking any further edits.
- let mut text = self.text().clone();
+ let text = self.text().clone();
let path = match path {
Some(path) => helix_core::path::get_canonicalized_path(&path.into())?,
@@ -602,23 +582,6 @@ impl Document {
}
}
- if let Some(fmt) = formatting {
- match fmt.await {
- Ok(transaction) => {
- let success = transaction.changes().apply(&mut text);
- if !success {
- // This shouldn't happen, because the transaction changes were generated
- // from the same text we're saving.
- log::error!("failed to apply format changes before saving");
- }
- }
- Err(err) => {
- // formatting failed: report error, and save file without modifications
- log::error!("{}", err);
- }
- }
- }
-
let mut file = File::create(&path).await?;
to_writer(&mut file, encoding, &text).await?;