aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorSkyler Hawthorne2022-09-03 03:38:38 +0000
committerSkyler Hawthorne2022-10-19 02:31:39 +0000
commitb530a86d1f15cc7df0e1ae8aa4bd02109ac33a8f (patch)
treea2dce789418ecc463490a98ee90a4da3631a076f /helix-term
parentb3fc31a211293f48696d26855781577d1859c2c6 (diff)
remove Callback::Compositor variant
To reduce likelihood of accidental discarding of important callbacks
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/application.rs2
-rw-r--r--helix-term/src/commands/dap.rs18
-rw-r--r--helix-term/src/compositor.rs4
-rw-r--r--helix-term/src/job.rs20
-rw-r--r--helix-term/src/ui/editor.rs7
5 files changed, 20 insertions, 31 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index 60610c1d..fe53d73d 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -991,7 +991,7 @@ impl Application {
let mut result = match self
.jobs
- .finish(Some(&mut self.editor), Some(&mut self.compositor))
+ .finish(&mut self.editor, Some(&mut self.compositor))
.await
{
Ok(_) => Ok(()),
diff --git a/helix-term/src/commands/dap.rs b/helix-term/src/commands/dap.rs
index 9c067eba..c27417e3 100644
--- a/helix-term/src/commands/dap.rs
+++ b/helix-term/src/commands/dap.rs
@@ -277,10 +277,11 @@ pub fn dap_launch(cx: &mut Context) {
let completions = template.completion.clone();
let name = template.name.clone();
let callback = Box::pin(async move {
- let call: Callback = Callback::Compositor(Box::new(move |compositor| {
- let prompt = debug_parameter_prompt(completions, name, Vec::new());
- compositor.push(Box::new(prompt));
- }));
+ let call: Callback =
+ Callback::EditorCompositor(Box::new(move |_editor, compositor| {
+ let prompt = debug_parameter_prompt(completions, name, Vec::new());
+ compositor.push(Box::new(prompt));
+ }));
Ok(call)
});
cx.jobs.callback(callback);
@@ -335,10 +336,11 @@ fn debug_parameter_prompt(
let config_name = config_name.clone();
let params = params.clone();
let callback = Box::pin(async move {
- let call: Callback = Callback::Compositor(Box::new(move |compositor| {
- let prompt = debug_parameter_prompt(completions, config_name, params);
- compositor.push(Box::new(prompt));
- }));
+ let call: Callback =
+ Callback::EditorCompositor(Box::new(move |_editor, compositor| {
+ let prompt = debug_parameter_prompt(completions, config_name, params);
+ compositor.push(Box::new(prompt));
+ }));
Ok(call)
});
cx.jobs.callback(callback);
diff --git a/helix-term/src/compositor.rs b/helix-term/src/compositor.rs
index 5077807d..35b9d054 100644
--- a/helix-term/src/compositor.rs
+++ b/helix-term/src/compositor.rs
@@ -31,9 +31,7 @@ impl<'a> Context<'a> {
/// Waits on all pending jobs, and then tries to flush all pending write
/// operations for all documents.
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))
- })?;
+ tokio::task::block_in_place(|| helix_lsp::block_on(self.jobs.finish(self.editor, None)))?;
for doc in &mut self.editor.documents.values_mut() {
tokio::task::block_in_place(|| helix_lsp::block_on(doc.try_flush_saves()))
diff --git a/helix-term/src/job.rs b/helix-term/src/job.rs
index 3c9e4511..2888b6eb 100644
--- a/helix-term/src/job.rs
+++ b/helix-term/src/job.rs
@@ -8,7 +8,6 @@ use futures_util::stream::{FuturesUnordered, StreamExt};
pub enum Callback {
EditorCompositor(Box<dyn FnOnce(&mut Editor, &mut Compositor) + Send>),
Editor(Box<dyn FnOnce(&mut Editor) + Send>),
- Compositor(Box<dyn FnOnce(&mut Compositor) + Send>),
}
pub type JobFuture = BoxFuture<'static, anyhow::Result<Option<Callback>>>;
@@ -76,7 +75,6 @@ impl Jobs {
Ok(Some(call)) => match call {
Callback::EditorCompositor(call) => call(editor, compositor),
Callback::Editor(call) => call(editor),
- Callback::Compositor(call) => call(compositor),
},
Err(e) => {
editor.set_error(format!("Async job failed: {}", e));
@@ -102,7 +100,7 @@ impl Jobs {
/// Blocks until all the jobs that need to be waited on are done.
pub async fn finish(
&mut self,
- mut editor: Option<&mut Editor>,
+ editor: &mut Editor,
mut compositor: Option<&mut Compositor>,
) -> anyhow::Result<()> {
log::debug!("waiting on jobs...");
@@ -117,20 +115,10 @@ impl Jobs {
// clippy doesn't realize this is an error without the derefs
#[allow(clippy::needless_option_as_deref)]
match callback {
- Callback::EditorCompositor(call)
- if editor.is_some() && compositor.is_some() =>
- {
- call(
- editor.as_deref_mut().unwrap(),
- compositor.as_deref_mut().unwrap(),
- )
- }
- Callback::Editor(call) if editor.is_some() => {
- call(editor.as_deref_mut().unwrap())
- }
- Callback::Compositor(call) if compositor.is_some() => {
- call(compositor.as_deref_mut().unwrap())
+ Callback::EditorCompositor(call) if compositor.is_some() => {
+ call(editor, compositor.as_deref_mut().unwrap())
}
+ Callback::Editor(call) => call(editor),
// skip callbacks for which we don't have the necessary references
_ => (),
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index abed7f9b..73dfd52c 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -945,9 +945,10 @@ impl EditorView {
// TODO: Use an on_mode_change hook to remove signature help
cxt.jobs.callback(async {
- let call: job::Callback = Callback::Compositor(Box::new(|compositor| {
- compositor.remove(SignatureHelp::ID);
- }));
+ let call: job::Callback =
+ Callback::EditorCompositor(Box::new(|_editor, compositor| {
+ compositor.remove(SignatureHelp::ID);
+ }));
Ok(call)
});
}