@@ -31,7 +31,7 @@ use crate::{
3131};
3232
3333use crate::job::{self, Job, Jobs};
34−use futures_util::{FutureExt, TryFutureExt};
34+use futures_util::FutureExt;
3535use std::num::NonZeroUsize;
3636use std::{fmt, future::Future};
3737
@@ -1389,7 +1389,7 @@ mod cmd {
13891389 fn write_impl<P: AsRef<Path>>(
13901390 cx: &mut compositor::Context,
13911391 path: Option<P>,
1392− ) -> Result<tokio::task::JoinHandle<Result<(), anyhow::Error>>, anyhow::Error> {
1392+ ) -> anyhow::Result<()> {
13931393 let jobs = &mut cx.jobs;
13941394 let (_, doc) = current!(cx.editor);
13951395
@@ -1410,7 +1410,9 @@ mod cmd {
14101410 jobs.callback(callback);
14111411 shared
14121412 });
1413− Ok(tokio::spawn(doc.format_and_save(fmt)))
1413+ let future = doc.format_and_save(fmt);
1414+ cx.jobs.add(Job::new(future).wait_before_exiting());
1415+ Ok(())
14141416 }
14151417
14161418 fn write(
@@ -1418,11 +1420,7 @@ mod cmd {
14181420 args: &[&str],
14191421 _event: PromptEvent,
14201422 ) -> anyhow::Result<()> {
1421− let handle = write_impl(cx, args.first())?;
1422− cx.jobs
1423− .add(Job::new(handle.unwrap_or_else(|e| Err(e.into()))).wait_before_exiting());
1424−
1425− Ok(())
1423+ write_impl(cx, args.first())
14261424 }
14271425
14281426 fn new_file(
@@ -1565,8 +1563,7 @@ mod cmd {
15651563 args: &[&str],
15661564 event: PromptEvent,
15671565 ) -> anyhow::Result<()> {
1568− let handle = write_impl(cx, args.first())?;
1569− let _ = helix_lsp::block_on(handle)?;
1566+ write_impl(cx, args.first())?;
15701567 quit(cx, &[], event)
15711568 }
15721569
@@ -1575,8 +1572,7 @@ mod cmd {
15751572 args: &[&str],
15761573 event: PromptEvent,
15771574 ) -> anyhow::Result<()> {
1578− let handle = write_impl(cx, args.first())?;
1579− let _ = helix_lsp::block_on(handle)?;
1575+ write_impl(cx, args.first())?;
15801576 force_quit(cx, &[], event)
15811577 }
15821578
@@ -1603,7 +1599,7 @@ mod cmd {
16031599 }
16041600
16051601 fn write_all_impl(
1606− editor: &mut Editor,
1602+ cx: &mut compositor::Context,
16071603 _args: &[&str],
16081604 _event: PromptEvent,
16091605 quit: bool,
@@ -1612,25 +1608,26 @@ mod cmd {
16121608 let mut errors = String::new();
16131609
16141610 // save all documents
1615− for (_, doc) in &mut editor.documents {
1611+ for (_, doc) in &mut cx.editor.documents {
16161612 if doc.path().is_none() {
16171613 errors.push_str("cannot write a buffer without a filename\n");
16181614 continue;
16191615 }
16201616
16211617 // TODO: handle error.
1622− let _ = helix_lsp::block_on(tokio::spawn(doc.save()));
1618+ let handle = doc.save();
1619+ cx.jobs.add(Job::new(handle).wait_before_exiting());
16231620 }
16241621
16251622 if quit {
16261623 if !force {
1627− buffers_remaining_impl(editor)?;
1624+ buffers_remaining_impl(cx.editor)?;
16281625 }
16291626
16301627 // close all views
1631− let views: Vec<_> = editor.tree.views().map(|(view, _)| view.id).collect();
1628+ let views: Vec<_> = cx.editor.tree.views().map(|(view, _)| view.id).collect();
16321629 for view_id in views {
1633− editor.close(view_id, false);
1630+ cx.editor.close(view_id, false);
16341631 }
16351632 }
16361633
@@ -1642,7 +1639,7 @@ mod cmd {
16421639 args: &[&str],
16431640 event: PromptEvent,
16441641 ) -> anyhow::Result<()> {
1645− write_all_impl(&mut cx.editor, args, event, false, false)
1642+ write_all_impl(cx, args, event, false, false)
16461643 }
16471644
16481645 fn write_all_quit(
@@ -1650,7 +1647,7 @@ mod cmd {
16501647 args: &[&str],
16511648 event: PromptEvent,
16521649 ) -> anyhow::Result<()> {
1653− write_all_impl(&mut cx.editor, args, event, true, false)
1650+ write_all_impl(cx, args, event, true, false)
16541651 }
16551652
16561653 fn force_write_all_quit(
@@ -1658,7 +1655,7 @@ mod cmd {
16581655 args: &[&str],
16591656 event: PromptEvent,
16601657 ) -> anyhow::Result<()> {
1661− write_all_impl(&mut cx.editor, args, event, true, true)
1658+ write_all_impl(cx, args, event, true, true)
16621659 }
16631660
16641661 fn quit_all_impl(