diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 613964b79e9f9..22944f20e9953 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -412,8 +412,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 4dd95f5164ecc..66fe7f311eafd 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -784,6 +784,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