on master help sign in
fix panic when view of pending write is closed
commite5fd5e2a9c78a3f391cda24cb57d187e248f06d1 authorSkyler Hawthorne <skyler@dead10ck.com> dateTue 9 Aug 2022, 00:32 (4 years ago) parentfaa00d4
2 files changed+26−10
helix-term/src/commands/typed.rs+8−10 helix-term/src/compositor.rs+18
helix-term/src/commands/typed.rs+8−10
@@ -34,6 +34,7 @@ fn quit(cx: &mut compositor::Context, args: &[Cow<str>], event: PromptEvent) ->
3434 buffers_remaining_impl(cx.editor)?
3535 }
3636
37+ cx.block_try_flush_writes()?;
3738 cx.editor.close(view!(cx.editor).id);
3839
3940 Ok(())
@@ -518,15 +519,7 @@ fn write_quit(
518519 }
519520
520521 write_impl(cx, args.first(), false)?;
521−
522− tokio::task::block_in_place(|| helix_lsp::block_on(cx.jobs.finish(Some(cx.editor), None)))?;
523−
524− let doc = doc_mut!(cx.editor);
525−
526− tokio::task::block_in_place(|| helix_lsp::block_on(doc.try_flush_saves()))
527− .map(|result| result.map(|_| ()))
528− .unwrap_or(Ok(()))?;
529−
522+ cx.block_try_flush_writes()?;
530523 quit(cx, &[], event)
531524}
532525
@@ -540,6 +533,7 @@ fn force_write_quit(
540533 }
541534
542535 write_impl(cx, args.first(), true)?;
536+ cx.block_try_flush_writes()?;
543537 force_quit(cx, &[], event)
544538}
545539
@@ -613,6 +607,8 @@ fn write_all_impl(
613607 buffers_remaining_impl(cx.editor)?;
614608 }
615609
610+ cx.block_try_flush_writes()?;
611+
616612 // close all views
617613 let views: Vec<_> = cx.editor.tree.views().map(|(view, _)| view.id).collect();
618614 for view_id in views {
@@ -682,6 +678,7 @@ fn quit_all(
682678 return Ok(());
683679 }
684680
681+ cx.block_try_flush_writes()?;
685682 quit_all_impl(cx.editor, false)
686683}
687684
@@ -710,8 +707,9 @@ fn cquit(
710707 .first()
711708 .and_then(|code| code.parse::<i32>().ok())
712709 .unwrap_or(1);
713− cx.editor.exit_code = exit_code;
714710
711+ cx.editor.exit_code = exit_code;
712+ cx.block_try_flush_writes()?;
715713 quit_all_impl(cx.editor, false)
716714}
717715
helix-term/src/compositor.rs+18
@@ -27,6 +27,24 @@ pub struct Context<'a> {
2727 pub jobs: &'a mut Jobs,
2828}
2929
30+impl<'a> Context<'a> {
31+ /// Waits on all pending jobs, and then tries to flush all pending write
32+ /// operations for the current document.
33+ pub fn block_try_flush_writes(&mut self) -> anyhow::Result<()> {
34+ tokio::task::block_in_place(|| {
35+ helix_lsp::block_on(self.jobs.finish(Some(self.editor), None))
36+ })?;
37+
38+ let doc = doc_mut!(self.editor);
39+
40+ tokio::task::block_in_place(|| helix_lsp::block_on(doc.try_flush_saves()))
41+ .map(|result| result.map(|_| ()))
42+ .unwrap_or(Ok(()))?;
43+
44+ Ok(())
45+ }
46+}
47+
3048pub trait Component: Any + AnyComponent {
3149 /// Process input events, return true if handled.
3250 fn handle_event(&mut self, _event: &Event, _ctx: &mut Context) -> EventResult {