Update nvim_wrap_async to use vim.defer_fn instead of schedule and support optional interval; bump to v0.15.0-alpha.16

pull/96/head v0.15.0-alpha.16
Chip Senkbeil 3 years ago
parent a8b6f3eb31
commit 11c3e5c34e
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

8
Cargo.lock generated

@ -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",

@ -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 <chip@senkbeil.org>"]
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"

@ -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 <chip@senkbeil.org>"]
edition = "2018"
homepage = "https://github.com/chipsenkbeil/distant"

@ -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 <chip@senkbeil.org>"]
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"] }

@ -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;

@ -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<LuaTable> {
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<u64>)| {
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<LuaTable> {
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<LuaFunction<'a>> {
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<LuaFunction<'a>> {
let schedule_fn = lua
.load(chunk! {
function(cb)
return vim.defer_fn(cb, $millis)
end
})
.eval()?;
wrap_async(lua, async_fn, schedule_fn)
}

@ -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 <chip@senkbeil.org>"]
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"] }

Loading…
Cancel
Save