fix buffer-close

pull/2267/head
Skyler Hawthorne 2 years ago
parent 83b6042b97
commit e1f7bdb1d2

@ -344,6 +344,7 @@ impl Application {
#[cfg(feature = "integration")] #[cfg(feature = "integration")]
{ {
log::debug!("idle handled");
idle_handled = true; idle_handled = true;
} }
} }

@ -77,9 +77,9 @@ fn buffer_close_by_ids_impl(
let (modified_ids, modified_names): (Vec<_>, Vec<_>) = doc_ids let (modified_ids, modified_names): (Vec<_>, Vec<_>) = doc_ids
.iter() .iter()
.filter_map(|&doc_id| { .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)) helix_lsp::block_on(editor.close_document(doc_id, force))
{ }) {
Some((doc_id, name)) Some((doc_id, name))
} else { } else {
None None
@ -151,7 +151,6 @@ fn buffer_close(
} }
let document_ids = buffer_gather_paths_impl(cx.editor, args); 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) buffer_close_by_ids_impl(cx.editor, &document_ids, false)
} }
@ -519,6 +518,7 @@ fn write_quit(
} }
write_impl(cx, args.first(), false)?; write_impl(cx, args.first(), false)?;
// TODO: change to use document close
helix_lsp::block_on(cx.jobs.finish())?; helix_lsp::block_on(cx.jobs.finish())?;
quit(cx, &[], event) quit(cx, &[], event)
} }

@ -25,7 +25,7 @@ async fn test_write_quit_fail() -> anyhow::Result<()> {
Ok(()) Ok(())
} }
#[tokio::test] #[tokio::test(flavor = "multi_thread")]
async fn test_buffer_close_concurrent() -> anyhow::Result<()> { async fn test_buffer_close_concurrent() -> anyhow::Result<()> {
test_key_sequences( test_key_sequences(
&mut Application::new(Args::default(), Config::default())?, &mut Application::new(Args::default(), Config::default())?,

@ -56,7 +56,9 @@ pub async fn test_key_sequences(
for (i, (in_keys, test_fn)) in inputs.into_iter().enumerate() { for (i, (in_keys, test_fn)) in inputs.into_iter().enumerate() {
if let Some(in_keys) = in_keys { if let Some(in_keys) = in_keys {
for key_event in parse_macro(in_keys)?.into_iter() { 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 // verify if it exited on the last iteration if it should have and
// the inverse // the inverse
if i == num_inputs - 1 && app_exited != should_exit { 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 { if let Some(test) = test_fn {

@ -61,7 +61,7 @@ async fn test_write_quit() -> anyhow::Result<()> {
Ok(()) Ok(())
} }
#[tokio::test] #[tokio::test(flavor = "multi_thread")]
async fn test_write_concurrent() -> anyhow::Result<()> { async fn test_write_concurrent() -> anyhow::Result<()> {
let mut file = tempfile::NamedTempFile::new()?; let mut file = tempfile::NamedTempFile::new()?;
let mut command = String::new(); let mut command = String::new();

@ -3,7 +3,6 @@ use futures_util::future::BoxFuture;
use futures_util::FutureExt; use futures_util::FutureExt;
use helix_core::auto_pairs::AutoPairs; use helix_core::auto_pairs::AutoPairs;
use helix_core::Range; use helix_core::Range;
use log::debug;
use serde::de::{self, Deserialize, Deserializer}; use serde::de::{self, Deserialize, Deserializer};
use serde::Serialize; use serde::Serialize;
use std::borrow::Cow; use std::borrow::Cow;
@ -644,16 +643,15 @@ impl Document {
async fn await_save_impl(&mut self, block: bool) -> Option<DocumentSaveEventResult> { async fn await_save_impl(&mut self, block: bool) -> Option<DocumentSaveEventResult> {
let mut current_save = self.current_save.lock().await; let mut current_save = self.current_save.lock().await;
if let Some(ref mut save) = *current_save { if let Some(ref mut save) = *current_save {
log::trace!("reawaiting save of '{:?}'", self.path());
let result = save.await; let result = save.await;
*current_save = None; *current_save = None;
debug!("save of '{:?}' result: {:?}", self.path(), result); log::trace!("reawait save of '{:?}' result: {:?}", self.path(), result);
return Some(result); return Some(result);
} }
// return early if the receiver is closed // return early if the receiver is closed
self.save_receiver.as_ref()?; let rx = self.save_receiver.as_mut()?;
let rx = self.save_receiver.as_mut().unwrap();
let save_req = if block { let save_req = if block {
rx.recv().await rx.recv().await
@ -672,12 +670,12 @@ impl Document {
// save a handle to the future so that when a poll on this // save a handle to the future so that when a poll on this
// function gets cancelled, we don't lose it // function gets cancelled, we don't lose it
*current_save = Some(save); *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; let result = (*current_save).as_mut().unwrap().await;
*current_save = None; *current_save = None;
debug!("save of '{:?}' result: {:?}", self.path(), result); log::trace!("save of '{:?}' result: {:?}", self.path(), result);
Some(result) Some(result)
} }
@ -715,7 +713,7 @@ impl Document {
/// it stops early before emptying the rest of the queue. /// it stops early before emptying the rest of the queue.
pub async fn close(&mut self) -> Option<DocumentSaveEventResult> { pub async fn close(&mut self) -> Option<DocumentSaveEventResult> {
if self.save_sender.is_some() { if self.save_sender.is_some() {
self.save_sender = None; self.save_sender.take();
} }
self.flush_saves_impl(true).await self.flush_saves_impl(true).await

@ -1102,8 +1102,8 @@ impl Editor {
}; };
// flush out any pending writes first to clear the modified status // flush out any pending writes first to clear the modified status
if let Some(save_result) = doc.try_flush_saves().await { if let Some(Err(err)) = doc.try_flush_saves().await {
save_result?; return Err(CloseError::SaveError(err));
} }
if !force && doc.is_modified() { if !force && doc.is_modified() {

Loading…
Cancel
Save