From 5e688e9f8980a438ff1b971a00a1c210fa73b5ee Mon Sep 17 00:00:00 2001 From: Skyler Hawthorne Date: Tue, 10 May 2022 23:41:44 -0400 Subject: [PATCH] update write-quit to wait for saves --- helix-term/src/commands/typed.rs | 8 ++++++-- helix-term/tests/test/commands.rs | 7 ++++++- helix-view/src/editor.rs | 13 +++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 8ca5b52028cd1..c6997c5b8962a 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -416,8 +416,12 @@ 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())?; + let doc = doc_mut!(cx.editor); + + tokio::task::block_in_place(|| helix_lsp::block_on(doc.try_flush_saves())) + .map(|result| result.map(|_| ())) + .unwrap_or(Ok(()))?; + quit(cx, &[], event) } diff --git a/helix-term/tests/test/commands.rs b/helix-term/tests/test/commands.rs index c0da4b319f2eb..a9fc4ad18e8d8 100644 --- a/helix-term/tests/test/commands.rs +++ b/helix-term/tests/test/commands.rs @@ -8,7 +8,7 @@ use helix_term::application::Application; use super::*; -#[tokio::test] +#[tokio::test(flavor = "multi_thread")] async fn test_write_quit_fail() -> anyhow::Result<()> { let file = helpers::new_readonly_tempfile()?; @@ -22,6 +22,11 @@ async fn test_write_quit_fail() -> anyhow::Result<()> { )?, Some("ihello:wq"), Some(&|app| { + let mut docs: Vec<_> = app.editor.documents().collect(); + assert_eq!(1, docs.len()); + + let doc = docs.pop().unwrap(); + assert_eq!(Some(file.path()), doc.path().map(PathBuf::as_path)); assert_eq!(&Severity::Error, app.editor.get_status().unwrap().1); }), ) diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 4474dd6339dff..da881da7d1cc3 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -787,6 +787,19 @@ impl Editor { Ok(id) } + /// Closes every document and view, which will ultimately shut down the app. + // pub async fn close(&mut self) -> anyhow::Result<()> { + // let docs: Vec<_> = self.documents().map(|doc| doc.id()).collect(); + + // // closing all documents also closes all views, which will shut + // // down the app + // for doc in docs { + // self.close_document(doc, false).await?; + // } + + // Ok(()) + // } + pub fn close(&mut self, id: ViewId) { let view = self.tree.get(self.tree.focus); // remove selection