Skip to content

Commit 9ea11d4

Browse files
committed
feat: check for out of sync and force sync
maybe we should prompt the user instead? we could destroy changes, but for now whatever i guess...
1 parent 58315f3 commit 9ea11d4

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/buffers.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,16 @@ local function attach(name, force)
5454
-- hook clientbound callbacks
5555
async.handler(name, controller, function(event)
5656
ticks[buffer] = vim.api.nvim_buf_get_changedtick(buffer)
57-
print(" ~~ applying change ~~ " .. event.first .. ".." .. event.last .. "::" .. event.content)
57+
if event.hash ~= nil then
58+
if utils.hash(utils.buffer.get_content(buffer)) ~= event.hash then
59+
-- OUT OF SYNC!
60+
-- TODO this may be destructive! we should probably prompt the user before doing this
61+
print(" /!\\ out of sync, resynching...")
62+
utils.buffer.set_content(buffer, controller:content())
63+
return
64+
end
65+
end
66+
-- print(" ~~ applying change ~~ " .. event.first .. ".." .. event.last .. "::" .. event.content)
5867
utils.buffer.set_content(buffer, event.content, event.first, event.last)
5968
end, 20) -- wait 20ms before polling again because it overwhelms libuv?
6069

0 commit comments

Comments
 (0)