mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2024-11-22 15:34:53 +01:00
fix: make it work with new api
This commit is contained in:
parent
140dd0ff4c
commit
b59086bda6
2 changed files with 8 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
||||||
local codemp = require("libcodemp_nvim")
|
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 function register_controller_handler(target, controller, handler)
|
||||||
local async = vim.loop.new_async(function()
|
local async = vim.loop.new_async(function()
|
||||||
|
@ -191,11 +191,12 @@ vim.api.nvim_create_user_command(
|
||||||
buffer_mappings[buffer] = args.args
|
buffer_mappings[buffer] = args.args
|
||||||
buffer_mappings_reverse[args.args] = buffer
|
buffer_mappings_reverse[args.args] = buffer
|
||||||
|
|
||||||
buffer_set_content(buffer, controller.content)
|
-- buffer_set_content(buffer, controller.content)
|
||||||
|
|
||||||
-- hook serverbound callbacks
|
-- hook serverbound callbacks
|
||||||
vim.api.nvim_buf_attach(buffer, false, {
|
vim.api.nvim_buf_attach(buffer, false, {
|
||||||
on_lines = function (_, buf, tick, firstline, lastline, new_lastline, old_byte_size)
|
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)
|
local content = buffer_get_content(buf)
|
||||||
controller:send(0, #content - 1, content)
|
controller:send(0, #content - 1, content)
|
||||||
-- print(string.format(">[%s] %s:%s|%s (%s)", tick, firstline, lastline, new_lastline, old_byte_size))
|
-- print(string.format(">[%s] %s:%s|%s (%s)", tick, firstline, lastline, new_lastline, old_byte_size))
|
||||||
|
|
|
@ -145,7 +145,7 @@ impl LuaUserData for LuaBufferController {
|
||||||
});
|
});
|
||||||
methods.add_method("try_recv", |_, this, ()| {
|
methods.add_method("try_recv", |_, this, ()| {
|
||||||
match this.0.try_recv() .map_err(LuaCodempError::from)? {
|
match this.0.try_recv() .map_err(LuaCodempError::from)? {
|
||||||
Some(x) => Ok(Some(x)),
|
Some(x) => Ok(Some(x.content)),
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -157,7 +157,10 @@ impl LuaUserData for LuaBufferController {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_fields<'lua, F: LuaUserDataFields<'lua, Self>>(fields: &mut F) {
|
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)?
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue