on master help sign in
remove Callback::Compositor variant

To reduce likelihood of accidental discarding of important callbacks

commitb530a86d1f15cc7df0e1ae8aa4bd02109ac33a8f authorSkyler Hawthorne <skyler@dead10ck.com> dateFri 2 Sep 2022, 23:38 (4 years ago) parentb3fc31a
5 files changed+20−31
helix-term/src/application.rs+1−1 helix-term/src/commands/dap.rs+10−8 helix-term/src/compositor.rs+1−3 helix-term/src/job.rs+4−16 helix-term/src/ui/editor.rs+4−3
helix-term/src/application.rs+1−1
@@ -991,7 +991,7 @@ impl Application {
991991
992992 let mut result = match self
993993 .jobs
994− .finish(Some(&mut self.editor), Some(&mut self.compositor))
994+ .finish(&mut self.editor, Some(&mut self.compositor))
995995 .await
996996 {
997997 Ok(_) => Ok(()),
helix-term/src/commands/dap.rs+10−8
@@ -277,10 +277,11 @@ pub fn dap_launch(cx: &mut Context) {
277277 let completions = template.completion.clone();
278278 let name = template.name.clone();
279279 let callback = Box::pin(async move {
280− let call: Callback = Callback::Compositor(Box::new(move |compositor| {
281− let prompt = debug_parameter_prompt(completions, name, Vec::new());
282− compositor.push(Box::new(prompt));
283− }));
280+ let call: Callback =
281+ Callback::EditorCompositor(Box::new(move |_editor, compositor| {
282+ let prompt = debug_parameter_prompt(completions, name, Vec::new());
283+ compositor.push(Box::new(prompt));
284+ }));
284285 Ok(call)
285286 });
286287 cx.jobs.callback(callback);
@@ -335,10 +336,11 @@ fn debug_parameter_prompt(
335336 let config_name = config_name.clone();
336337 let params = params.clone();
337338 let callback = Box::pin(async move {
338− let call: Callback = Callback::Compositor(Box::new(move |compositor| {
339− let prompt = debug_parameter_prompt(completions, config_name, params);
340− compositor.push(Box::new(prompt));
341− }));
339+ let call: Callback =
340+ Callback::EditorCompositor(Box::new(move |_editor, compositor| {
341+ let prompt = debug_parameter_prompt(completions, config_name, params);
342+ compositor.push(Box::new(prompt));
343+ }));
342344 Ok(call)
343345 });
344346 cx.jobs.callback(callback);
helix-term/src/compositor.rs+1−3
@@ -31,9 +31,7 @@ impl<'a> Context<'a> {
3131 /// Waits on all pending jobs, and then tries to flush all pending write
3232 /// operations for all documents.
3333 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− })?;
34+ tokio::task::block_in_place(|| helix_lsp::block_on(self.jobs.finish(self.editor, None)))?;
3735
3836 for doc in &mut self.editor.documents.values_mut() {
3937 tokio::task::block_in_place(|| helix_lsp::block_on(doc.try_flush_saves()))
helix-term/src/job.rs+4−16
@@ -8,7 +8,6 @@ use futures_util::stream::{FuturesUnordered, StreamExt};
88pub enum Callback {
99 EditorCompositor(Box<dyn FnOnce(&mut Editor, &mut Compositor) + Send>),
1010 Editor(Box<dyn FnOnce(&mut Editor) + Send>),
11− Compositor(Box<dyn FnOnce(&mut Compositor) + Send>),
1211}
1312
1413pub type JobFuture = BoxFuture<'static, anyhow::Result<Option<Callback>>>;
@@ -76,7 +75,6 @@ impl Jobs {
7675 Ok(Some(call)) => match call {
7776 Callback::EditorCompositor(call) => call(editor, compositor),
7877 Callback::Editor(call) => call(editor),
79− Callback::Compositor(call) => call(compositor),
8078 },
8179 Err(e) => {
8280 editor.set_error(format!("Async job failed: {}", e));
@@ -102,7 +100,7 @@ impl Jobs {
102100 /// Blocks until all the jobs that need to be waited on are done.
103101 pub async fn finish(
104102 &mut self,
105− mut editor: Option<&mut Editor>,
103+ editor: &mut Editor,
106104 mut compositor: Option<&mut Compositor>,
107105 ) -> anyhow::Result<()> {
108106 log::debug!("waiting on jobs...");
@@ -117,20 +115,10 @@ impl Jobs {
117115 // clippy doesn't realize this is an error without the derefs
118116 #[allow(clippy::needless_option_as_deref)]
119117 match callback {
120− Callback::EditorCompositor(call)
121− if editor.is_some() && compositor.is_some() =>
122− {
123− call(
124− editor.as_deref_mut().unwrap(),
125− compositor.as_deref_mut().unwrap(),
126− )
127− }
128− Callback::Editor(call) if editor.is_some() => {
129− call(editor.as_deref_mut().unwrap())
130− }
131− Callback::Compositor(call) if compositor.is_some() => {
132− call(compositor.as_deref_mut().unwrap())
118+ Callback::EditorCompositor(call) if compositor.is_some() => {
119+ call(editor, compositor.as_deref_mut().unwrap())
133120 }
121+ Callback::Editor(call) => call(editor),
134122
135123 // skip callbacks for which we don't have the necessary references
136124 _ => (),
helix-term/src/ui/editor.rs+4−3
@@ -945,9 +945,10 @@ impl EditorView {
945945
946946 // TODO: Use an on_mode_change hook to remove signature help
947947 cxt.jobs.callback(async {
948− let call: job::Callback = Callback::Compositor(Box::new(|compositor| {
949− compositor.remove(SignatureHelp::ID);
950− }));
948+ let call: job::Callback =
949+ Callback::EditorCompositor(Box::new(|_editor, compositor| {
950+ compositor.remove(SignatureHelp::ID);
951+ }));
951952 Ok(call)
952953 });
953954 }