Skip to content

Commit acf8abc

Browse files
committed
update write-quit to wait for saves
1 parent 5ceaf59 commit acf8abc

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

helix-term/src/commands/typed.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,12 @@ fn write_quit(
416416
event: PromptEvent,
417417
) -> anyhow::Result<()> {
418418
write_impl(cx, args.first(), false)?;
419-
// TODO: change to use document close
420-
helix_lsp::block_on(cx.jobs.finish())?;
419+
let doc = doc_mut!(cx.editor);
420+
421+
tokio::task::block_in_place(|| helix_lsp::block_on(doc.try_flush_saves()))
422+
.map(|result| result.map(|_| ()))
423+
.unwrap_or(Ok(()))?;
424+
421425
quit(cx, &[], event)
422426
}
423427

helix-term/tests/test/commands.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use helix_term::application::Application;
88

99
use super::*;
1010

11-
#[tokio::test]
11+
#[tokio::test(flavor = "multi_thread")]
1212
async fn test_write_quit_fail() -> anyhow::Result<()> {
1313
let file = helpers::new_readonly_tempfile()?;
1414

@@ -22,6 +22,11 @@ async fn test_write_quit_fail() -> anyhow::Result<()> {
2222
)?,
2323
Some("ihello<esc>:wq<ret>"),
2424
Some(&|app| {
25+
let mut docs: Vec<_> = app.editor.documents().collect();
26+
assert_eq!(1, docs.len());
27+
28+
let doc = docs.pop().unwrap();
29+
assert_eq!(Some(file.path()), doc.path().map(PathBuf::as_path));
2530
assert_eq!(&Severity::Error, app.editor.get_status().unwrap().1);
2631
}),
2732
)

helix-view/src/editor.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,19 @@ impl Editor {
787787
Ok(id)
788788
}
789789

790+
/// Closes every document and view, which will ultimately shut down the app.
791+
// pub async fn close(&mut self) -> anyhow::Result<()> {
792+
// let docs: Vec<_> = self.documents().map(|doc| doc.id()).collect();
793+
794+
// // closing all documents also closes all views, which will shut
795+
// // down the app
796+
// for doc in docs {
797+
// self.close_document(doc, false).await?;
798+
// }
799+
800+
// Ok(())
801+
// }
802+
790803
pub fn close(&mut self, id: ViewId) {
791804
let view = self.tree.get(self.tree.focus);
792805
// remove selection

0 commit comments

Comments
 (0)