fix: make it work with new api

This commit is contained in:
əlemi 2023-11-16 06:54:32 +01:00
parent 140dd0ff4c
commit b59086bda6
2 changed files with 8 additions and 4 deletions

View file

@ -1,6 +1,6 @@
local codemp = require("libcodemp_nvim")
local codemp_changed_tick = nil -- TODO this doesn't work when events are coalesced
local codemp_changed_tick = 0 -- TODO this doesn't work when events are coalesced
local function register_controller_handler(target, controller, handler)
local async = vim.loop.new_async(function()
@ -191,11 +191,12 @@ vim.api.nvim_create_user_command(
buffer_mappings[buffer] = args.args
buffer_mappings_reverse[args.args] = buffer
buffer_set_content(buffer, controller.content)
-- buffer_set_content(buffer, controller.content)
-- hook serverbound callbacks
vim.api.nvim_buf_attach(buffer, false, {
on_lines = function (_, buf, tick, firstline, lastline, new_lastline, old_byte_size)
if tick <= codemp_changed_tick then return end
local content = buffer_get_content(buf)
controller:send(0, #content - 1, content)
-- print(string.format(">[%s] %s:%s|%s (%s)", tick, firstline, lastline, new_lastline, old_byte_size))

View file

@ -145,7 +145,7 @@ impl LuaUserData for LuaBufferController {
});
methods.add_method("try_recv", |_, this, ()| {
match this.0.try_recv() .map_err(LuaCodempError::from)? {
Some(x) => Ok(Some(x)),
Some(x) => Ok(Some(x.content)),
None => Ok(None),
}
});
@ -157,7 +157,10 @@ impl LuaUserData for LuaBufferController {
}
fn add_fields<'lua, F: LuaUserDataFields<'lua, Self>>(fields: &mut F) {
fields.add_field_method_get("content", |_, this| Ok(this.0.try_recv().unwrap().unwrap()));
fields.add_field_method_get("content", |_, this| Ok(
this.0.try_recv().map(|x| x.map(|y| y.content))
.map_err(LuaCodempError::from)?
));
}
}