Skip to content

Commit 5ceaf59

Browse files
committed
fix buffer-close
1 parent 2068162 commit 5ceaf59

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

helix-term/src/commands/typed.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ fn buffer_close_by_ids_impl(
6161
doc_ids: &[DocumentId],
6262
force: bool,
6363
) -> anyhow::Result<()> {
64-
for &doc_id in doc_ids {
65-
helix_lsp::block_on(editor.close_document(doc_id, force))?;
64+
log::debug!("closing buffers: {:?}", doc_ids);
65+
66+
for doc_id in doc_ids {
67+
tokio::task::block_in_place(|| helix_lsp::block_on(editor.close_document(*doc_id, force)))?;
6668
}
6769

6870
Ok(())
@@ -111,7 +113,6 @@ fn buffer_close(
111113
_event: PromptEvent,
112114
) -> anyhow::Result<()> {
113115
let document_ids = buffer_gather_paths_impl(cx.editor, args);
114-
log::debug!("closing buffers: {:?}", document_ids);
115116
buffer_close_by_ids_impl(cx.editor, &document_ids, false)
116117
}
117118

@@ -415,6 +416,7 @@ fn write_quit(
415416
event: PromptEvent,
416417
) -> anyhow::Result<()> {
417418
write_impl(cx, args.first(), false)?;
419+
// TODO: change to use document close
418420
helix_lsp::block_on(cx.jobs.finish())?;
419421
quit(cx, &[], event)
420422
}

helix-term/tests/test/commands.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async fn test_write_quit_fail() -> anyhow::Result<()> {
3030
Ok(())
3131
}
3232

33-
#[tokio::test]
33+
#[tokio::test(flavor = "multi_thread")]
3434
async fn test_buffer_close_concurrent() -> anyhow::Result<()> {
3535
test_key_sequences(
3636
&mut Application::new(Args::default(), Config::default())?,

helix-term/tests/test/helpers.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ pub async fn test_key_sequences(
5252
for (in_keys, test_fn) in inputs {
5353
if let Some(in_keys) = in_keys {
5454
for key_event in parse_macro(&in_keys)?.into_iter() {
55-
tx.send(Ok(Event::Key(KeyEvent::from(key_event))))?;
55+
let key = Event::Key(KeyEvent::from(key_event));
56+
log::trace!("sending key: {:?}", key);
57+
tx.send(Ok(key))?;
5658
}
5759
}
5860

helix-term/tests/test/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async fn test_write() -> anyhow::Result<()> {
3939
Ok(())
4040
}
4141

42-
#[tokio::test]
42+
#[tokio::test(flavor = "multi_thread")]
4343
async fn test_write_concurrent() -> anyhow::Result<()> {
4444
let mut file = tempfile::NamedTempFile::new()?;
4545
let mut command = String::new();

helix-view/src/document.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use anyhow::{anyhow, bail, Context, Error};
22
use futures_util::future::BoxFuture;
33
use helix_core::auto_pairs::AutoPairs;
44
use helix_core::Range;
5-
use log::debug;
65
use serde::de::{self, Deserialize, Deserializer};
76
use serde::Serialize;
87
use std::cell::Cell;
@@ -580,16 +579,15 @@ impl Document {
580579
async fn await_save_impl(&mut self, block: bool) -> Option<DocumentSaveEventResult> {
581580
let mut current_save = self.current_save.lock().await;
582581
if let Some(ref mut save) = *current_save {
582+
log::trace!("reawaiting save of '{:?}'", self.path());
583583
let result = save.await;
584584
*current_save = None;
585-
debug!("save of '{:?}' result: {:?}", self.path(), result);
585+
log::trace!("reawait save of '{:?}' result: {:?}", self.path(), result);
586586
return Some(result);
587587
}
588588

589589
// return early if the receiver is closed
590-
self.save_receiver.as_ref()?;
591-
592-
let rx = self.save_receiver.as_mut().unwrap();
590+
let rx = self.save_receiver.as_mut()?;
593591

594592
let save_req = if block {
595593
rx.recv().await
@@ -608,12 +606,12 @@ impl Document {
608606
// save a handle to the future so that when a poll on this
609607
// function gets cancelled, we don't lose it
610608
*current_save = Some(save);
611-
debug!("awaiting save of '{:?}'", self.path());
609+
log::trace!("awaiting save of '{:?}'", self.path());
612610

613611
let result = (*current_save).as_mut().unwrap().await;
614612
*current_save = None;
615613

616-
debug!("save of '{:?}' result: {:?}", self.path(), result);
614+
log::trace!("save of '{:?}' result: {:?}", self.path(), result);
617615

618616
Some(result)
619617
}
@@ -651,7 +649,7 @@ impl Document {
651649
/// it stops early before emptying the rest of the queue.
652650
pub async fn close(&mut self) -> Option<DocumentSaveEventResult> {
653651
if self.save_sender.is_some() {
654-
self.save_sender = None;
652+
self.save_sender.take();
655653
}
656654

657655
self.flush_saves_impl(true).await

0 commit comments

Comments
 (0)