fix: while attaching, set content later

This commit is contained in:
əlemi 2024-09-06 17:23:18 +02:00
parent 46de8c5661
commit 30cf1e1554
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -32,10 +32,6 @@ local function attach(name, buffer, content)
buffer_id_map[name] = buffer
ticks[buffer] = 0
if content ~= nil then
local _ = controller:send(0, 0, content) -- no need to await
end
-- hook serverbound callbacks
-- TODO breaks when deleting whole lines at buffer end
vim.api.nvim_buf_attach(buffer, false, {
@ -84,8 +80,13 @@ local function attach(name, buffer, content)
end))
local remote_content = controller:content():await()
if content ~= nil then
-- TODO this may happen too soon!!
local _ = controller:send(0, #remote_content, content) -- no need to await
else
ticks[buffer] = vim.api.nvim_buf_get_changedtick(buffer)
utils.buffer.set_content(buffer, remote_content)
end
controller:callback(function (_controller) async:send() end)
vim.defer_fn(function() async:send() end, 500) -- force a try_recv after 500ms