feat: add sync command to resync without reloading

This commit is contained in:
əlemi 2023-11-27 23:31:31 +01:00
parent ae4d1f58cd
commit 592837c664
2 changed files with 22 additions and 8 deletions

View file

@ -92,10 +92,10 @@ local function buffer_get_content(buf)
return table.concat(lines, '\n')
end
-- local function buffer_set_content(buf, content)
-- local lines = split_without_trim(content, "\n")
-- vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
-- end
local function buffer_set_content(buf, content)
local lines = split_without_trim(content, "\n")
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
end
local function buffer_replace_content(buffer, first, last, content)
-- TODO send help it works but why is lost knowledge
@ -259,6 +259,23 @@ vim.api.nvim_create_user_command(
{ nargs = 1 }
)
vim.api.nvim_create_user_command(
"Sync",
function (args)
local buffer = vim.api.nvim_get_current_buf()
local name = buffer_mappings[buffer]
if name ~= nil then
local controller = codemp.get_buffer(name)
codemp_changed_tick = vim.api.nvim_buf_get_changedtick(buffer) + 1
buffer_set_content(buffer, controller.content)
print(" :: synched buffer " .. name)
else
print(" !! buffer not managed")
end
end,
{ }
)
vim.api.nvim_create_user_command(
"Detach",
function (args)

View file

@ -156,10 +156,7 @@ 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().map(|x| x.map(|y| y.content))
.map_err(LuaCodempError::from)?
));
fields.add_field_method_get("content", |_, this| Ok(this.0.content()));
}
}