Skip to content

Commit

Permalink
update write-quit to wait for saves
Browse files Browse the repository at this point in the history
  • Loading branch information
dead10ck committed May 13, 2022
1 parent 5ceaf59 commit acf8abc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
8 changes: 6 additions & 2 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
7 changes: 6 additions & 1 deletion helix-term/tests/test/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;

Expand All @@ -22,6 +22,11 @@ async fn test_write_quit_fail() -> anyhow::Result<()> {
)?,
Some("ihello<esc>:wq<ret>"),
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);
}),
)
Expand Down
13 changes: 13 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit acf8abc

Please sign in to comment.