on master help sign in
fix panic when view of pending write is closed
e5fd5e2Skyler Hawthorne
helix-term/src/commands/typed.rs+8−10
@@ -34,6 +34,7 @@ fn quit(cx: &mut compositor::Context, args: &[Cow<str>], event: PromptEvent) ->
34 buffers_remaining_impl(cx.editor)?
34 buffers_remaining_impl(cx.editor)?
35 }
35 }
36
36
37+ cx.block_try_flush_writes()?;
37 cx.editor.close(view!(cx.editor).id);
38 cx.editor.close(view!(cx.editor).id);
38
39
39 Ok(())
40 Ok(())
@@ -518,15 +519,7 @@ fn write_quit(
518 }
519 }
519
520
520 write_impl(cx, args.first(), false)?;
521 write_impl(cx, args.first(), false)?;
521−
522+ cx.block_try_flush_writes()?;
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−
530 quit(cx, &[], event)
523 quit(cx, &[], event)
531}
524}
532
525
@@ -540,6 +533,7 @@ fn force_write_quit(
540 }
533 }
541
534
542 write_impl(cx, args.first(), true)?;
535 write_impl(cx, args.first(), true)?;
536+ cx.block_try_flush_writes()?;
543 force_quit(cx, &[], event)
537 force_quit(cx, &[], event)
544}
538}
545
539
@@ -613,6 +607,8 @@ fn write_all_impl(
613 buffers_remaining_impl(cx.editor)?;
607 buffers_remaining_impl(cx.editor)?;
614 }
608 }
615
609
610+ cx.block_try_flush_writes()?;
611+
616 // close all views
612 // close all views
617 let views: Vec<_> = cx.editor.tree.views().map(|(view, _)| view.id).collect();
613 let views: Vec<_> = cx.editor.tree.views().map(|(view, _)| view.id).collect();
618 for view_id in views {
614 for view_id in views {
@@ -682,6 +678,7 @@ fn quit_all(
682 return Ok(());
678 return Ok(());
683 }
679 }
684
680
681+ cx.block_try_flush_writes()?;
685 quit_all_impl(cx.editor, false)
682 quit_all_impl(cx.editor, false)
686}
683}
687
684
@@ -710,8 +707,9 @@ fn cquit(
710 .first()
707 .first()
711 .and_then(|code| code.parse::<i32>().ok())
708 .and_then(|code| code.parse::<i32>().ok())
712 .unwrap_or(1);
709 .unwrap_or(1);
713− cx.editor.exit_code = exit_code;
714
710
711+ cx.editor.exit_code = exit_code;
712+ cx.block_try_flush_writes()?;
715 quit_all_impl(cx.editor, false)
713 quit_all_impl(cx.editor, false)
716}
714}
717
715
helix-term/src/compositor.rs+18
@@ -27,6 +27,24 @@ pub struct Context<'a> {
27 pub jobs: &'a mut Jobs,
27 pub jobs: &'a mut Jobs,
28}
28}
29
29
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+
30pub trait Component: Any + AnyComponent {
48pub trait Component: Any + AnyComponent {
31 /// Process input events, return true if handled.
49 /// Process input events, return true if handled.
32 fn handle_event(&mut self, _event: &Event, _ctx: &mut Context) -> EventResult {
50 fn handle_event(&mut self, _event: &Event, _ctx: &mut Context) -> EventResult {