on master help sign in
fix buffer-close
e1f7bdbSkyler Hawthorne
helix-term/src/application.rs+1
@@ -344,6 +344,7 @@ impl Application {
344
344
345 #[cfg(feature = "integration")]
345 #[cfg(feature = "integration")]
346 {
346 {
347+ log::debug!("idle handled");
347 idle_handled = true;
348 idle_handled = true;
348 }
349 }
349 }
350 }
helix-term/src/commands/typed.rs+3−3
@@ -77,9 +77,9 @@ fn buffer_close_by_ids_impl(
77 let (modified_ids, modified_names): (Vec<_>, Vec<_>) = doc_ids
77 let (modified_ids, modified_names): (Vec<_>, Vec<_>) = doc_ids
78 .iter()
78 .iter()
79 .filter_map(|&doc_id| {
79 .filter_map(|&doc_id| {
80− if let Err(CloseError::BufferModified(name)) =
80+ if let Err(CloseError::BufferModified(name)) = tokio::task::block_in_place(|| {
81 helix_lsp::block_on(editor.close_document(doc_id, force))
81 helix_lsp::block_on(editor.close_document(doc_id, force))
82− {
82+ }) {
83 Some((doc_id, name))
83 Some((doc_id, name))
84 } else {
84 } else {
85 None
85 None
@@ -151,7 +151,6 @@ fn buffer_close(
151 }
151 }
152
152
153 let document_ids = buffer_gather_paths_impl(cx.editor, args);
153 let document_ids = buffer_gather_paths_impl(cx.editor, args);
154− log::debug!("closing buffers: {:?}", document_ids);
155 buffer_close_by_ids_impl(cx.editor, &document_ids, false)
154 buffer_close_by_ids_impl(cx.editor, &document_ids, false)
156}
155}
157
156
@@ -519,6 +518,7 @@ fn write_quit(
519 }
518 }
520
519
521 write_impl(cx, args.first(), false)?;
520 write_impl(cx, args.first(), false)?;
521+ // TODO: change to use document close
522 helix_lsp::block_on(cx.jobs.finish())?;
522 helix_lsp::block_on(cx.jobs.finish())?;
523 quit(cx, &[], event)
523 quit(cx, &[], event)
524}
524}
helix-term/tests/test/commands.rs+1−1
@@ -25,7 +25,7 @@ async fn test_write_quit_fail() -> anyhow::Result<()> {
25 Ok(())
25 Ok(())
26}
26}
27
27
28−#[tokio::test]
28+#[tokio::test(flavor = "multi_thread")]
29async fn test_buffer_close_concurrent() -> anyhow::Result<()> {
29async fn test_buffer_close_concurrent() -> anyhow::Result<()> {
30 test_key_sequences(
30 test_key_sequences(
31 &mut Application::new(Args::default(), Config::default())?,
31 &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(
56 for (i, (in_keys, test_fn)) in inputs.into_iter().enumerate() {
56 for (i, (in_keys, test_fn)) in inputs.into_iter().enumerate() {
57 if let Some(in_keys) = in_keys {
57 if let Some(in_keys) = in_keys {
58 for key_event in parse_macro(in_keys)?.into_iter() {
58 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))?;
60 }
62 }
61 }
63 }
62
64
@@ -70,7 +72,7 @@ pub async fn test_key_sequences(
70 // verify if it exited on the last iteration if it should have and
72 // verify if it exited on the last iteration if it should have and
71 // the inverse
73 // the inverse
72 if i == num_inputs - 1 && app_exited != should_exit {
74 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);
74 }
76 }
75
77
76 if let Some(test) = test_fn {
78 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<()> {
61 Ok(())
61 Ok(())
62}
62}
63
63
64−#[tokio::test]
64+#[tokio::test(flavor = "multi_thread")]
65async fn test_write_concurrent() -> anyhow::Result<()> {
65async fn test_write_concurrent() -> anyhow::Result<()> {
66 let mut file = tempfile::NamedTempFile::new()?;
66 let mut file = tempfile::NamedTempFile::new()?;
67 let mut command = String::new();
67 let mut command = String::new();
helix-view/src/document.rs+6−8
@@ -3,7 +3,6 @@ use futures_util::future::BoxFuture;
3use futures_util::FutureExt;
3use futures_util::FutureExt;
4use helix_core::auto_pairs::AutoPairs;
4use helix_core::auto_pairs::AutoPairs;
5use helix_core::Range;
5use helix_core::Range;
6−use log::debug;
7use serde::de::{self, Deserialize, Deserializer};
6use serde::de::{self, Deserialize, Deserializer};
8use serde::Serialize;
7use serde::Serialize;
9use std::borrow::Cow;
8use std::borrow::Cow;
@@ -644,16 +643,15 @@ impl Document {
644 async fn await_save_impl(&mut self, block: bool) -> Option<DocumentSaveEventResult> {
643 async fn await_save_impl(&mut self, block: bool) -> Option<DocumentSaveEventResult> {
645 let mut current_save = self.current_save.lock().await;
644 let mut current_save = self.current_save.lock().await;
646 if let Some(ref mut save) = *current_save {
645 if let Some(ref mut save) = *current_save {
646+ log::trace!("reawaiting save of '{:?}'", self.path());
647 let result = save.await;
647 let result = save.await;
648 *current_save = None;
648 *current_save = None;
649− debug!("save of '{:?}' result: {:?}", self.path(), result);
649+ log::trace!("reawait save of '{:?}' result: {:?}", self.path(), result);
650 return Some(result);
650 return Some(result);
651 }
651 }
652
652
653 // return early if the receiver is closed
653 // 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()?;
657
655
658 let save_req = if block {
656 let save_req = if block {
659 rx.recv().await
657 rx.recv().await
@@ -672,12 +670,12 @@ impl Document {
672 // save a handle to the future so that when a poll on this
670 // save a handle to the future so that when a poll on this
673 // function gets cancelled, we don't lose it
671 // function gets cancelled, we don't lose it
674 *current_save = Some(save);
672 *current_save = Some(save);
675− debug!("awaiting save of '{:?}'", self.path());
673+ log::trace!("awaiting save of '{:?}'", self.path());
676
674
677 let result = (*current_save).as_mut().unwrap().await;
675 let result = (*current_save).as_mut().unwrap().await;
678 *current_save = None;
676 *current_save = None;
679
677
680− debug!("save of '{:?}' result: {:?}", self.path(), result);
678+ log::trace!("save of '{:?}' result: {:?}", self.path(), result);
681
679
682 Some(result)
680 Some(result)
683 }
681 }
@@ -715,7 +713,7 @@ impl Document {
715 /// it stops early before emptying the rest of the queue.
713 /// it stops early before emptying the rest of the queue.
716 pub async fn close(&mut self) -> Option<DocumentSaveEventResult> {
714 pub async fn close(&mut self) -> Option<DocumentSaveEventResult> {
717 if self.save_sender.is_some() {
715 if self.save_sender.is_some() {
718− self.save_sender = None;
716+ self.save_sender.take();
719 }
717 }
720
718
721 self.flush_saves_impl(true).await
719 self.flush_saves_impl(true).await
helix-view/src/editor.rs+2−2
@@ -1102,8 +1102,8 @@ impl Editor {
1102 };
1102 };
1103
1103
1104 // flush out any pending writes first to clear the modified status
1104 // flush out any pending writes first to clear the modified status
1105− if let Some(save_result) = doc.try_flush_saves().await {
1105+ if let Some(Err(err)) = doc.try_flush_saves().await {
1106− save_result?;
1106+ return Err(CloseError::SaveError(err));
1107 }
1107 }
1108
1108
1109 if !force && doc.is_modified() {
1109 if !force && doc.is_modified() {