From e1f7bdb1d2ef68c0de38e768080291901ff4662e Mon Sep 17 00:00:00 2001 From: Skyler Hawthorne Date: Mon, 9 May 2022 23:08:12 -0400 Subject: [PATCH] fix buffer-close --- helix-term/src/application.rs | 1 + helix-term/src/commands/typed.rs | 6 +++--- helix-term/tests/test/commands.rs | 2 +- helix-term/tests/test/helpers.rs | 6 ++++-- helix-term/tests/test/write.rs | 2 +- helix-view/src/document.rs | 14 ++++++-------- helix-view/src/editor.rs | 4 ++-- 7 files changed, 18 insertions(+), 17 deletions(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 0640de3c4..5c25e8aa2 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -344,6 +344,7 @@ impl Application { #[cfg(feature = "integration")] { + log::debug!("idle handled"); idle_handled = true; } } diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 35c846016..efe693b9d 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -77,9 +77,9 @@ fn buffer_close_by_ids_impl( let (modified_ids, modified_names): (Vec<_>, Vec<_>) = doc_ids .iter() .filter_map(|&doc_id| { - if let Err(CloseError::BufferModified(name)) = + if let Err(CloseError::BufferModified(name)) = tokio::task::block_in_place(|| { helix_lsp::block_on(editor.close_document(doc_id, force)) - { + }) { Some((doc_id, name)) } else { None @@ -151,7 +151,6 @@ fn buffer_close( } let document_ids = buffer_gather_paths_impl(cx.editor, args); - log::debug!("closing buffers: {:?}", document_ids); buffer_close_by_ids_impl(cx.editor, &document_ids, false) } @@ -519,6 +518,7 @@ fn write_quit( } write_impl(cx, args.first(), false)?; + // TODO: change to use document close helix_lsp::block_on(cx.jobs.finish())?; quit(cx, &[], event) } diff --git a/helix-term/tests/test/commands.rs b/helix-term/tests/test/commands.rs index 8aea144bd..1f1bd6a95 100644 --- a/helix-term/tests/test/commands.rs +++ b/helix-term/tests/test/commands.rs @@ -25,7 +25,7 @@ async fn test_write_quit_fail() -> anyhow::Result<()> { Ok(()) } -#[tokio::test] +#[tokio::test(flavor = "multi_thread")] async fn test_buffer_close_concurrent() -> anyhow::Result<()> { test_key_sequences( &mut Application::new(Args::default(), Config::default())?, diff --git a/helix-term/tests/test/helpers.rs b/helix-term/tests/test/helpers.rs index 8f2501e61..bbcc6632e 100644 --- a/helix-term/tests/test/helpers.rs +++ b/helix-term/tests/test/helpers.rs @@ -56,7 +56,9 @@ pub async fn test_key_sequences( for (i, (in_keys, test_fn)) in inputs.into_iter().enumerate() { if let Some(in_keys) = in_keys { for key_event in parse_macro(in_keys)?.into_iter() { - tx.send(Ok(Event::Key(KeyEvent::from(key_event))))?; + let key = Event::Key(KeyEvent::from(key_event)); + log::trace!("sending key: {:?}", key); + tx.send(Ok(key))?; } } @@ -70,7 +72,7 @@ pub async fn test_key_sequences( // verify if it exited on the last iteration if it should have and // the inverse if i == num_inputs - 1 && app_exited != should_exit { - bail!("expected app to exit: {} != {}", app_exited, should_exit); + bail!("expected app to exit: {} != {}", should_exit, app_exited); } if let Some(test) = test_fn { diff --git a/helix-term/tests/test/write.rs b/helix-term/tests/test/write.rs index d2e6922f2..544f1ba19 100644 --- a/helix-term/tests/test/write.rs +++ b/helix-term/tests/test/write.rs @@ -61,7 +61,7 @@ async fn test_write_quit() -> anyhow::Result<()> { Ok(()) } -#[tokio::test] +#[tokio::test(flavor = "multi_thread")] async fn test_write_concurrent() -> anyhow::Result<()> { let mut file = tempfile::NamedTempFile::new()?; let mut command = String::new(); diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 82d526a9c..b6e42065e 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -3,7 +3,6 @@ use futures_util::future::BoxFuture; use futures_util::FutureExt; use helix_core::auto_pairs::AutoPairs; use helix_core::Range; -use log::debug; use serde::de::{self, Deserialize, Deserializer}; use serde::Serialize; use std::borrow::Cow; @@ -644,16 +643,15 @@ impl Document { async fn await_save_impl(&mut self, block: bool) -> Option { let mut current_save = self.current_save.lock().await; if let Some(ref mut save) = *current_save { + log::trace!("reawaiting save of '{:?}'", self.path()); let result = save.await; *current_save = None; - debug!("save of '{:?}' result: {:?}", self.path(), result); + log::trace!("reawait save of '{:?}' result: {:?}", self.path(), result); return Some(result); } // return early if the receiver is closed - self.save_receiver.as_ref()?; - - let rx = self.save_receiver.as_mut().unwrap(); + let rx = self.save_receiver.as_mut()?; let save_req = if block { rx.recv().await @@ -672,12 +670,12 @@ impl Document { // save a handle to the future so that when a poll on this // function gets cancelled, we don't lose it *current_save = Some(save); - debug!("awaiting save of '{:?}'", self.path()); + log::trace!("awaiting save of '{:?}'", self.path()); let result = (*current_save).as_mut().unwrap().await; *current_save = None; - debug!("save of '{:?}' result: {:?}", self.path(), result); + log::trace!("save of '{:?}' result: {:?}", self.path(), result); Some(result) } @@ -715,7 +713,7 @@ impl Document { /// it stops early before emptying the rest of the queue. pub async fn close(&mut self) -> Option { if self.save_sender.is_some() { - self.save_sender = None; + self.save_sender.take(); } self.flush_saves_impl(true).await diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index e038a82de..e54aa7fa5 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -1102,8 +1102,8 @@ impl Editor { }; // flush out any pending writes first to clear the modified status - if let Some(save_result) = doc.try_flush_saves().await { - save_result?; + if let Some(Err(err)) = doc.try_flush_saves().await { + return Err(CloseError::SaveError(err)); } if !force && doc.is_modified() {