From 11c3e5c34ea1b519128bcba3b53a927c32915b65 Mon Sep 17 00:00:00 2001 From: Chip Senkbeil Date: Thu, 14 Oct 2021 02:04:21 -0500 Subject: [PATCH] Update nvim_wrap_async to use vim.defer_fn instead of schedule and support optional interval; bump to v0.15.0-alpha.16 --- Cargo.lock | 8 ++++---- Cargo.toml | 6 +++--- distant-core/Cargo.toml | 2 +- distant-lua/Cargo.toml | 6 +++--- distant-lua/src/constants.rs | 3 +++ distant-lua/src/utils.rs | 21 +++++++++++++++++---- distant-ssh2/Cargo.toml | 4 ++-- 7 files changed, 33 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bcce609..e08a8e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -427,7 +427,7 @@ dependencies = [ [[package]] name = "distant" -version = "0.15.0-alpha.15" +version = "0.15.0-alpha.16" dependencies = [ "assert_cmd", "assert_fs", @@ -451,7 +451,7 @@ dependencies = [ [[package]] name = "distant-core" -version = "0.15.0-alpha.15" +version = "0.15.0-alpha.16" dependencies = [ "assert_fs", "bytes", @@ -476,7 +476,7 @@ dependencies = [ [[package]] name = "distant-lua" -version = "0.15.0-alpha.15" +version = "0.15.0-alpha.16" dependencies = [ "distant-core", "distant-ssh2", @@ -510,7 +510,7 @@ dependencies = [ [[package]] name = "distant-ssh2" -version = "0.15.0-alpha.15" +version = "0.15.0-alpha.16" dependencies = [ "assert_cmd", "assert_fs", diff --git a/Cargo.toml b/Cargo.toml index 1678bb4..c9871a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "distant" description = "Operate on a remote computer through file and process manipulation" categories = ["command-line-utilities"] keywords = ["cli"] -version = "0.15.0-alpha.15" +version = "0.15.0-alpha.16" authors = ["Chip Senkbeil "] edition = "2018" homepage = "https://github.com/chipsenkbeil/distant" @@ -25,7 +25,7 @@ ssh2 = ["distant-ssh2"] [dependencies] derive_more = { version = "0.99.16", default-features = false, features = ["display", "from", "error", "is_variant"] } -distant-core = { version = "=0.15.0-alpha.15", path = "distant-core", features = ["structopt"] } +distant-core = { version = "=0.15.0-alpha.16", path = "distant-core", features = ["structopt"] } flexi_logger = "0.18.0" log = "0.4.14" once_cell = "1.8.0" @@ -37,7 +37,7 @@ strum = { version = "0.21.0", features = ["derive"] } whoami = "1.1.2" # Optional native SSH functionality -distant-ssh2 = { version = "=0.15.0-alpha.15", path = "distant-ssh2", optional = true } +distant-ssh2 = { version = "=0.15.0-alpha.16", path = "distant-ssh2", optional = true } [target.'cfg(unix)'.dependencies] fork = "0.1.18" diff --git a/distant-core/Cargo.toml b/distant-core/Cargo.toml index 9db18a8..5d1adb7 100644 --- a/distant-core/Cargo.toml +++ b/distant-core/Cargo.toml @@ -3,7 +3,7 @@ name = "distant-core" description = "Core library for distant, enabling operation on a remote computer through file and process manipulation" categories = ["network-programming"] keywords = ["api", "async"] -version = "0.15.0-alpha.15" +version = "0.15.0-alpha.16" authors = ["Chip Senkbeil "] edition = "2018" homepage = "https://github.com/chipsenkbeil/distant" diff --git a/distant-lua/Cargo.toml b/distant-lua/Cargo.toml index 0830a48..aa3f3fe 100644 --- a/distant-lua/Cargo.toml +++ b/distant-lua/Cargo.toml @@ -3,7 +3,7 @@ name = "distant-lua" description = "Lua bindings to the distant Rust crates" categories = ["api-bindings", "network-programming"] keywords = ["api", "async"] -version = "0.15.0-alpha.15" +version = "0.15.0-alpha.16" authors = ["Chip Senkbeil "] edition = "2018" homepage = "https://github.com/chipsenkbeil/distant" @@ -24,8 +24,8 @@ luajit = ["mlua/luajit"] vendored = ["mlua/vendored"] [dependencies] -distant-core = { version = "=0.15.0-alpha.15", path = "../distant-core" } -distant-ssh2 = { version = "=0.15.0-alpha.15", features = ["serde"], path = "../distant-ssh2" } +distant-core = { version = "=0.15.0-alpha.16", path = "../distant-core" } +distant-ssh2 = { version = "=0.15.0-alpha.16", features = ["serde"], path = "../distant-ssh2" } futures = "0.3.17" log = "0.4.14" mlua = { version = "0.6.6", features = ["async", "macros", "module", "serialize"] } diff --git a/distant-lua/src/constants.rs b/distant-lua/src/constants.rs index 92101c7..cbd57d1 100644 --- a/distant-lua/src/constants.rs +++ b/distant-lua/src/constants.rs @@ -1,2 +1,5 @@ /// Default timeout (15 secs) pub const TIMEOUT_MILLIS: u64 = 15000; + +/// Default polling interval for neovim (0.2 secs) +pub const NVIM_POLL_TIMEOUT: u64 = 200; diff --git a/distant-lua/src/utils.rs b/distant-lua/src/utils.rs index d628aec..f1191da 100644 --- a/distant-lua/src/utils.rs +++ b/distant-lua/src/utils.rs @@ -1,3 +1,4 @@ +use crate::constants::NVIM_POLL_TIMEOUT; use mlua::{chunk, prelude::*}; use once_cell::sync::OnceCell; use oorandom::Rand32; @@ -12,7 +13,9 @@ pub fn make_utils_tbl(lua: &Lua) -> LuaResult { tbl.set( "nvim_wrap_async", - lua.create_function(|lua, async_fn| nvim_wrap_async(lua, async_fn))?, + lua.create_function(|lua, (async_fn, millis): (LuaFunction, Option)| { + nvim_wrap_async(lua, async_fn, millis.unwrap_or(NVIM_POLL_TIMEOUT)) + })?, )?; tbl.set( "wrap_async", @@ -23,9 +26,19 @@ pub fn make_utils_tbl(lua: &Lua) -> LuaResult { Ok(tbl) } -/// Specialty function that performs wrap_async using `vim.schedule` from neovim -pub fn nvim_wrap_async<'a>(lua: &'a Lua, async_fn: LuaFunction<'a>) -> LuaResult> { - let schedule_fn = lua.load("vim.schedule").eval()?; +/// Specialty function that performs wrap_async using `vim.defer_fn` from neovim +pub fn nvim_wrap_async<'a>( + lua: &'a Lua, + async_fn: LuaFunction<'a>, + millis: u64, +) -> LuaResult> { + let schedule_fn = lua + .load(chunk! { + function(cb) + return vim.defer_fn(cb, $millis) + end + }) + .eval()?; wrap_async(lua, async_fn, schedule_fn) } diff --git a/distant-ssh2/Cargo.toml b/distant-ssh2/Cargo.toml index 0f3d09c..102f4cb 100644 --- a/distant-ssh2/Cargo.toml +++ b/distant-ssh2/Cargo.toml @@ -2,7 +2,7 @@ name = "distant-ssh2" description = "Library to enable native ssh-2 protocol for use with distant sessions" categories = ["network-programming"] -version = "0.15.0-alpha.15" +version = "0.15.0-alpha.16" authors = ["Chip Senkbeil "] edition = "2018" homepage = "https://github.com/chipsenkbeil/distant" @@ -12,7 +12,7 @@ license = "MIT OR Apache-2.0" [dependencies] async-compat = "0.2.1" -distant-core = { version = "=0.15.0-alpha.15", path = "../distant-core" } +distant-core = { version = "=0.15.0-alpha.16", path = "../distant-core" } futures = "0.3.16" log = "0.4.14" rand = { version = "0.8.4", features = ["getrandom"] }