aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/compositor.rs
diff options
context:
space:
mode:
authorSkyler Hawthorne2022-08-09 04:32:04 +0000
committerSkyler Hawthorne2022-10-19 02:31:39 +0000
commite5fd5e2a9c78a3f391cda24cb57d187e248f06d1 (patch)
tree610a3f5f39510ffe8049c80429eee3fc1c56bf30 /helix-term/src/compositor.rs
parentfaa00d4cc3de89a89679f6315c0345182929beb2 (diff)
fix panic when view of pending write is closed
Diffstat (limited to 'helix-term/src/compositor.rs')
-rw-r--r--helix-term/src/compositor.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/helix-term/src/compositor.rs b/helix-term/src/compositor.rs
index c0898dae..6ef77341 100644
--- a/helix-term/src/compositor.rs
+++ b/helix-term/src/compositor.rs
@@ -27,6 +27,24 @@ pub struct Context<'a> {
pub jobs: &'a mut Jobs,
}
+impl<'a> Context<'a> {
+ /// Waits on all pending jobs, and then tries to flush all pending write
+ /// operations for the current document.
+ pub fn block_try_flush_writes(&mut self) -> anyhow::Result<()> {
+ tokio::task::block_in_place(|| {
+ helix_lsp::block_on(self.jobs.finish(Some(self.editor), None))
+ })?;
+
+ let doc = doc_mut!(self.editor);
+
+ tokio::task::block_in_place(|| helix_lsp::block_on(doc.try_flush_saves()))
+ .map(|result| result.map(|_| ()))
+ .unwrap_or(Ok(()))?;
+
+ Ok(())
+ }
+}
+
pub trait Component: Any + AnyComponent {
/// Process input events, return true if handled.
fn handle_event(&mut self, _event: &Event, _ctx: &mut Context) -> EventResult {