mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2024-12-24 06:14:53 +01:00
feat: debug prints
This commit is contained in:
parent
a74355f6a0
commit
a4c519f799
4 changed files with 13 additions and 5 deletions
|
@ -87,6 +87,7 @@ MP command autocompletes available options for current state, so cycle <Tab> if
|
|||
opts = {
|
||||
neo_tree = false, -- enable neo-tree integration
|
||||
timer_interval = 100, -- poll for codemp callbacks every __ ms
|
||||
debug = false, -- print text operations as they happen
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -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)
|
||||
if tick <= ticks[buf] then return end
|
||||
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, 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
|
||||
if new_byte_len == 0 then
|
||||
change_content = ""
|
||||
|
@ -55,7 +55,9 @@ local function attach(name, buffer, content)
|
|||
'\n'
|
||||
)
|
||||
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()
|
||||
end,
|
||||
})
|
||||
|
@ -65,7 +67,9 @@ local function attach(name, buffer, content)
|
|||
local event = controller:try_recv():await()
|
||||
if event == nil then break end
|
||||
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)
|
||||
if event.hash ~= nil then
|
||||
if utils.hash(utils.buffer.get_content(buffer)) ~= event.hash then
|
||||
|
|
|
@ -8,6 +8,7 @@ if CODEMP == nil then
|
|||
config = {
|
||||
neo_tree = false,
|
||||
timer_interval = 100,
|
||||
debug = false,
|
||||
},
|
||||
setup = function (opts)
|
||||
CODEMP.config = vim.tbl_extend('force', CODEMP.config, opts)
|
||||
|
|
|
@ -158,7 +158,9 @@ local function buffer_set_content(buf, content, first, last)
|
|||
else
|
||||
content_array = vim.split(content, "\n", {trimempty=false})
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue