feat: debug prints

This commit is contained in:
əlemi 2024-09-06 03:53:52 +02:00
parent a74355f6a0
commit a4c519f799
Signed by: alemi
GPG key ID: A4895B84D311642C
4 changed files with 13 additions and 5 deletions

View file

@ -87,6 +87,7 @@ MP command autocompletes available options for current state, so cycle <Tab> if
opts = { opts = {
neo_tree = false, -- enable neo-tree integration neo_tree = false, -- enable neo-tree integration
timer_interval = 100, -- poll for codemp callbacks every __ ms timer_interval = 100, -- poll for codemp callbacks every __ ms
debug = false, -- print text operations as they happen
} }
``` ```

View file

@ -42,10 +42,10 @@ local function attach(name, buffer, content)
on_bytes = function(_, buf, tick, start_row, start_col, start_offset, old_end_row, old_end_col, old_end_byte_len, new_end_row, new_end_col, new_byte_len) on_bytes = function(_, buf, tick, start_row, start_col, start_offset, old_end_row, old_end_col, old_end_byte_len, new_end_row, new_end_col, new_byte_len)
if tick <= ticks[buf] then return end if tick <= ticks[buf] then return end
if id_buffer_map[buf] == nil then return true end -- unregister callback handler if id_buffer_map[buf] == nil then return true end -- unregister callback handler
print(string.format( if CODEMP.config.debug then print(string.format(
"start(row:%s, col:%s) offset:%s end(row:%s, col:%s new(row:%s, col:%s)) len(old:%s, new:%s)", "start(row:%s, col:%s) offset:%s end(row:%s, col:%s new(row:%s, col:%s)) len(old:%s, new:%s)",
start_row, start_col, start_offset, old_end_row, old_end_col, new_end_row, new_end_col, old_end_byte_len, new_byte_len start_row, start_col, start_offset, old_end_row, old_end_col, new_end_row, new_end_col, old_end_byte_len, new_byte_len
)) )) end
local change_content local change_content
if new_byte_len == 0 then if new_byte_len == 0 then
change_content = "" change_content = ""
@ -55,7 +55,9 @@ local function attach(name, buffer, content)
'\n' '\n'
) )
end end
print(string.format("sending: %s %s %s %s -- '%s'", start_row, start_col, start_row + new_end_row, start_col + new_end_col, change_content)) if CODEMP.config.debug then
print(string.format("sending: %s %s %s %s -- '%s'", start_row, start_col, start_row + new_end_row, start_col + new_end_col, change_content))
end
controller:send(start_offset, start_offset + old_end_byte_len, change_content):await() controller:send(start_offset, start_offset + old_end_byte_len, change_content):await()
end, end,
}) })
@ -65,7 +67,9 @@ local function attach(name, buffer, content)
local event = controller:try_recv():await() local event = controller:try_recv():await()
if event == nil then break end if event == nil then break end
ticks[buffer] = vim.api.nvim_buf_get_changedtick(buffer) ticks[buffer] = vim.api.nvim_buf_get_changedtick(buffer)
print(" ~~ applying change ~~ " .. event.first .. ".." .. event.last .. "::[" .. event.content .. "]") if CODEMP.config.debug then
print(" ~~ applying change ~~ " .. event.first .. ".." .. event.last .. "::[" .. event.content .. "]")
end
utils.buffer.set_content(buffer, event.content, event.first, event.last) utils.buffer.set_content(buffer, event.content, event.first, event.last)
if event.hash ~= nil then if event.hash ~= nil then
if utils.hash(utils.buffer.get_content(buffer)) ~= event.hash then if utils.hash(utils.buffer.get_content(buffer)) ~= event.hash then

View file

@ -8,6 +8,7 @@ if CODEMP == nil then
config = { config = {
neo_tree = false, neo_tree = false,
timer_interval = 100, timer_interval = 100,
debug = false,
}, },
setup = function (opts) setup = function (opts)
CODEMP.config = vim.tbl_extend('force', CODEMP.config, opts) CODEMP.config = vim.tbl_extend('force', CODEMP.config, opts)

View file

@ -158,7 +158,9 @@ local function buffer_set_content(buf, content, first, last)
else else
content_array = vim.split(content, "\n", {trimempty=false}) content_array = vim.split(content, "\n", {trimempty=false})
end end
-- print(string.format("set [%s..%s::'%s'] -> start(row:%s col:%s) end(row:%s, col:%s)", first, last, content, first_row, first_col, last_row, last_col)) if CODEMP.config.debug then
print(string.format("nvim_buf_set_text [%s..%s::'%s'] -> start(row:%s col:%s) end(row:%s, col:%s)", first, last, content, first_row, first_col, last_row, last_col))
end
vim.api.nvim_buf_set_text(buf, first_row, first_col, last_row, last_col, content_array) vim.api.nvim_buf_set_text(buf, first_row, first_col, last_row, last_col, content_array)
end end
end end