mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2024-11-22 15:34:53 +01:00
feat: added get_buffer, renamed recv -> try_recv
This commit is contained in:
parent
23b4adafcb
commit
d6b9e21836
1 changed files with 20 additions and 5 deletions
25
src/lib.rs
25
src/lib.rs
|
@ -59,6 +59,14 @@ fn get_cursor(_: &Lua, _args: ()) -> LuaResult<LuaCursorController> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_buffer(_: &Lua, (path,): (String,)) -> LuaResult<LuaBufferController> {
|
||||||
|
Ok(
|
||||||
|
CODEMP_INSTANCE.get_buffer(&path)
|
||||||
|
.map_err(LuaCodempError::from)?
|
||||||
|
.into()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// join a remote workspace and start processing cursor events
|
/// join a remote workspace and start processing cursor events
|
||||||
fn join(_: &Lua, (session,): (String,)) -> LuaResult<LuaCursorController> {
|
fn join(_: &Lua, (session,): (String,)) -> LuaResult<LuaCursorController> {
|
||||||
let controller = CODEMP_INSTANCE.join(&session)
|
let controller = CODEMP_INSTANCE.join(&session)
|
||||||
|
@ -74,7 +82,7 @@ impl LuaUserData for LuaCursorController {
|
||||||
methods.add_method("send", |_, this, (usr, sr, sc, er, ec):(String, i32, i32, i32, i32)| {
|
methods.add_method("send", |_, this, (usr, sr, sc, er, ec):(String, i32, i32, i32, i32)| {
|
||||||
Ok(this.0.send(make_cursor(usr, sr, sc, er, ec)).map_err(LuaCodempError::from)?)
|
Ok(this.0.send(make_cursor(usr, sr, sc, er, ec)).map_err(LuaCodempError::from)?)
|
||||||
});
|
});
|
||||||
methods.add_method("recv", |lua, this, ()| {
|
methods.add_method("try_recv", |lua, this, ()| {
|
||||||
match this.0.try_recv() .map_err(LuaCodempError::from)? {
|
match this.0.try_recv() .map_err(LuaCodempError::from)? {
|
||||||
Some(x) => Ok(Some(cursor_to_table(lua, x)?)),
|
Some(x) => Ok(Some(cursor_to_table(lua, x)?)),
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
|
@ -165,10 +173,16 @@ impl LuaUserData for LuaBufferController {
|
||||||
methods.add_method("insert", |_, this, (txt, pos):(String, u64)| {
|
methods.add_method("insert", |_, this, (txt, pos):(String, u64)| {
|
||||||
Ok(this.0.send(this.0.insert(&txt, pos)).map_err(LuaCodempError::from)?)
|
Ok(this.0.send(this.0.insert(&txt, pos)).map_err(LuaCodempError::from)?)
|
||||||
});
|
});
|
||||||
methods.add_method("recv", |_, this, ()| {
|
methods.add_method("try_recv", |_, this, ()| {
|
||||||
let change = this.0.blocking_recv(CODEMP_INSTANCE.rt())
|
match this.0.try_recv() .map_err(LuaCodempError::from)? {
|
||||||
.map_err(LuaCodempError::from)?;
|
Some(x) => Ok(Some(LuaTextChange(x))),
|
||||||
Ok(LuaTextChange(change))
|
None => Ok(None),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
methods.add_method("poll", |_, this, ()| {
|
||||||
|
CODEMP_INSTANCE.rt().block_on(this.0.poll())
|
||||||
|
.map_err(LuaCodempError::from)?;
|
||||||
|
Ok(())
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,5 +215,6 @@ fn libcodemp_nvim(lua: &Lua) -> LuaResult<LuaTable> {
|
||||||
exports.set("create", lua.create_function(create)?)?;
|
exports.set("create", lua.create_function(create)?)?;
|
||||||
exports.set("attach", lua.create_function(attach)?)?;
|
exports.set("attach", lua.create_function(attach)?)?;
|
||||||
exports.set("get_cursor", lua.create_function(get_cursor)?)?;
|
exports.set("get_cursor", lua.create_function(get_cursor)?)?;
|
||||||
|
exports.set("get_buffer", lua.create_function(get_buffer)?)?;
|
||||||
Ok(exports)
|
Ok(exports)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue