Skip to content

Commit

Permalink
fix buffer-close
Browse files Browse the repository at this point in the history
  • Loading branch information
dead10ck committed May 13, 2022
1 parent 2068162 commit 5ceaf59
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
8 changes: 5 additions & 3 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ fn buffer_close_by_ids_impl(
doc_ids: &[DocumentId],
force: bool,
) -> anyhow::Result<()> {
for &doc_id in doc_ids {
helix_lsp::block_on(editor.close_document(doc_id, force))?;
log::debug!("closing buffers: {:?}", doc_ids);

for doc_id in doc_ids {
tokio::task::block_in_place(|| helix_lsp::block_on(editor.close_document(*doc_id, force)))?;
}

Ok(())
Expand Down Expand Up @@ -111,7 +113,6 @@ fn buffer_close(
_event: PromptEvent,
) -> anyhow::Result<()> {
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)
}

Expand Down Expand Up @@ -415,6 +416,7 @@ fn write_quit(
event: PromptEvent,
) -> anyhow::Result<()> {
write_impl(cx, args.first(), false)?;
// TODO: change to use document close
helix_lsp::block_on(cx.jobs.finish())?;
quit(cx, &[], event)
}
Expand Down
2 changes: 1 addition & 1 deletion helix-term/tests/test/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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())?,
Expand Down
4 changes: 3 additions & 1 deletion helix-term/tests/test/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ pub async fn test_key_sequences(
for (in_keys, test_fn) in inputs {
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))?;
}
}

Expand Down
2 changes: 1 addition & 1 deletion helix-term/tests/test/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async fn test_write() -> 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();
Expand Down
14 changes: 6 additions & 8 deletions helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use anyhow::{anyhow, bail, Context, Error};
use futures_util::future::BoxFuture;
use helix_core::auto_pairs::AutoPairs;
use helix_core::Range;
use log::debug;
use serde::de::{self, Deserialize, Deserializer};
use serde::Serialize;
use std::cell::Cell;
Expand Down Expand Up @@ -580,16 +579,15 @@ impl Document {
async fn await_save_impl(&mut self, block: bool) -> Option<DocumentSaveEventResult> {
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
Expand All @@ -608,12 +606,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)
}
Expand Down Expand Up @@ -651,7 +649,7 @@ impl Document {
/// it stops early before emptying the rest of the queue.
pub async fn close(&mut self) -> Option<DocumentSaveEventResult> {
if self.save_sender.is_some() {
self.save_sender = None;
self.save_sender.take();
}

self.flush_saves_impl(true).await
Expand Down

0 comments on commit 5ceaf59

Please sign in to comment.