on master help sign in
fix buffer-close
commite1f7bdb1d2ef68c0de38e768080291901ff4662e authorSkyler Hawthorne <skyler@dead10ck.com> dateMon 9 May 2022, 23:08 (4 years ago) parent83b6042
7 files changed+18−17
helix-term/src/application.rs+1 helix-term/src/commands/typed.rs+3−3 helix-term/tests/test/commands.rs+1−1 helix-term/tests/test/helpers.rs+4−2 helix-term/tests/test/write.rs+1−1 helix-view/src/document.rs+6−8 helix-view/src/editor.rs+2−2
helix-term/src/application.rs+1
@@ -344,6 +344,7 @@ impl Application {
344344
345345 #[cfg(feature = "integration")]
346346 {
347+ log::debug!("idle handled");
347348 idle_handled = true;
348349 }
349350 }
helix-term/src/commands/typed.rs+3−3
@@ -77,9 +77,9 @@ fn buffer_close_by_ids_impl(
7777 let (modified_ids, modified_names): (Vec<_>, Vec<_>) = doc_ids
7878 .iter()
7979 .filter_map(|&doc_id| {
80− if let Err(CloseError::BufferModified(name)) =
80+ if let Err(CloseError::BufferModified(name)) = tokio::task::block_in_place(|| {
8181 helix_lsp::block_on(editor.close_document(doc_id, force))
82− {
82+ }) {
8383 Some((doc_id, name))
8484 } else {
8585 None
@@ -151,7 +151,6 @@ fn buffer_close(
151151 }
152152
153153 let document_ids = buffer_gather_paths_impl(cx.editor, args);
154− log::debug!("closing buffers: {:?}", document_ids);
155154 buffer_close_by_ids_impl(cx.editor, &document_ids, false)
156155}
157156
@@ -519,6 +518,7 @@ fn write_quit(
519518 }
520519
521520 write_impl(cx, args.first(), false)?;
521+ // TODO: change to use document close
522522 helix_lsp::block_on(cx.jobs.finish())?;
523523 quit(cx, &[], event)
524524}
helix-term/tests/test/commands.rs+1−1
@@ -25,7 +25,7 @@ async fn test_write_quit_fail() -> anyhow::Result<()> {
2525 Ok(())
2626}
2727
28−#[tokio::test]
28+#[tokio::test(flavor = "multi_thread")]
2929async fn test_buffer_close_concurrent() -> anyhow::Result<()> {
3030 test_key_sequences(
3131 &mut Application::new(Args::default(), Config::default())?,
helix-term/tests/test/helpers.rs+4−2
@@ -56,7 +56,9 @@ pub async fn test_key_sequences(
5656 for (i, (in_keys, test_fn)) in inputs.into_iter().enumerate() {
5757 if let Some(in_keys) = in_keys {
5858 for key_event in parse_macro(in_keys)?.into_iter() {
59− tx.send(Ok(Event::Key(KeyEvent::from(key_event))))?;
59+ let key = Event::Key(KeyEvent::from(key_event));
60+ log::trace!("sending key: {:?}", key);
61+ tx.send(Ok(key))?;
6062 }
6163 }
6264
@@ -70,7 +72,7 @@ pub async fn test_key_sequences(
7072 // verify if it exited on the last iteration if it should have and
7173 // the inverse
7274 if i == num_inputs - 1 && app_exited != should_exit {
73− bail!("expected app to exit: {} != {}", app_exited, should_exit);
75+ bail!("expected app to exit: {} != {}", should_exit, app_exited);
7476 }
7577
7678 if let Some(test) = test_fn {
helix-term/tests/test/write.rs+1−1
@@ -61,7 +61,7 @@ async fn test_write_quit() -> anyhow::Result<()> {
6161 Ok(())
6262}
6363
64−#[tokio::test]
64+#[tokio::test(flavor = "multi_thread")]
6565async fn test_write_concurrent() -> anyhow::Result<()> {
6666 let mut file = tempfile::NamedTempFile::new()?;
6767 let mut command = String::new();
helix-view/src/document.rs+6−8
@@ -3,7 +3,6 @@ use futures_util::future::BoxFuture;
33use futures_util::FutureExt;
44use helix_core::auto_pairs::AutoPairs;
55use helix_core::Range;
6−use log::debug;
76use serde::de::{self, Deserialize, Deserializer};
87use serde::Serialize;
98use std::borrow::Cow;
@@ -644,16 +643,15 @@ impl Document {
644643 async fn await_save_impl(&mut self, block: bool) -> Option<DocumentSaveEventResult> {
645644 let mut current_save = self.current_save.lock().await;
646645 if let Some(ref mut save) = *current_save {
646+ log::trace!("reawaiting save of '{:?}'", self.path());
647647 let result = save.await;
648648 *current_save = None;
649− debug!("save of '{:?}' result: {:?}", self.path(), result);
649+ log::trace!("reawait save of '{:?}' result: {:?}", self.path(), result);
650650 return Some(result);
651651 }
652652
653653 // return early if the receiver is closed
654− self.save_receiver.as_ref()?;
655−
656− let rx = self.save_receiver.as_mut().unwrap();
654+ let rx = self.save_receiver.as_mut()?;
657655
658656 let save_req = if block {
659657 rx.recv().await
@@ -672,12 +670,12 @@ impl Document {
672670 // save a handle to the future so that when a poll on this
673671 // function gets cancelled, we don't lose it
674672 *current_save = Some(save);
675− debug!("awaiting save of '{:?}'", self.path());
673+ log::trace!("awaiting save of '{:?}'", self.path());
676674
677675 let result = (*current_save).as_mut().unwrap().await;
678676 *current_save = None;
679677
680− debug!("save of '{:?}' result: {:?}", self.path(), result);
678+ log::trace!("save of '{:?}' result: {:?}", self.path(), result);
681679
682680 Some(result)
683681 }
@@ -715,7 +713,7 @@ impl Document {
715713 /// it stops early before emptying the rest of the queue.
716714 pub async fn close(&mut self) -> Option<DocumentSaveEventResult> {
717715 if self.save_sender.is_some() {
718− self.save_sender = None;
716+ self.save_sender.take();
719717 }
720718
721719 self.flush_saves_impl(true).await
helix-view/src/editor.rs+2−2
@@ -1102,8 +1102,8 @@ impl Editor {
11021102 };
11031103
11041104 // flush out any pending writes first to clear the modified status
1105− if let Some(save_result) = doc.try_flush_saves().await {
1106− save_result?;
1105+ if let Some(Err(err)) = doc.try_flush_saves().await {
1106+ return Err(CloseError::SaveError(err));
11071107 }
11081108
11091109 if !force && doc.is_modified() {