aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs33
1 files changed, 22 insertions, 11 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 803f4051..1c1edece 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -114,17 +114,7 @@ impl<'a> Context<'a> {
T: for<'de> serde::Deserialize<'de> + Send + 'static,
F: FnOnce(&mut Editor, &mut Compositor, T) + Send + 'static,
{
- let callback = Box::pin(async move {
- let json = call.await?;
- let response = serde_json::from_value(json)?;
- let call: job::Callback = Callback::EditorCompositor(Box::new(
- move |editor: &mut Editor, compositor: &mut Compositor| {
- callback(editor, compositor, response)
- },
- ));
- Ok(call)
- });
- self.jobs.callback(callback);
+ self.jobs.callback(make_job_callback(call, callback));
}
/// Returns 1 if no explicit count was provided
@@ -134,6 +124,27 @@ impl<'a> Context<'a> {
}
}
+#[inline]
+fn make_job_callback<T, F>(
+ call: impl Future<Output = helix_lsp::Result<serde_json::Value>> + 'static + Send,
+ callback: F,
+) -> std::pin::Pin<Box<impl Future<Output = Result<Callback, anyhow::Error>>>>
+where
+ T: for<'de> serde::Deserialize<'de> + Send + 'static,
+ F: FnOnce(&mut Editor, &mut Compositor, T) + Send + 'static,
+{
+ Box::pin(async move {
+ let json = call.await?;
+ let response = serde_json::from_value(json)?;
+ let call: job::Callback = Callback::EditorCompositor(Box::new(
+ move |editor: &mut Editor, compositor: &mut Compositor| {
+ callback(editor, compositor, response)
+ },
+ ));
+ Ok(call)
+ })
+}
+
use helix_view::{align_view, Align};
/// A MappableCommand is either a static command like "jump_view_up" or a Typable command like