fix(buffer): escape hyphens in infer_status Lua patterns (#119)

* fix(buffer): escape hyphens in `infer_status` Lua patterns

Problem: `infer_status` used `/-` in its Lua patterns, which is a lazy
quantifier on `/` rather than a literal hyphen. This caused the function
to always return `nil` for lines with an `/id/` prefix, so status was
never inferred from buffer text during `reapply_dirty_inline`.

Solution: escape hyphens as `%-` in both patterns. Also add debug
logging to `on_bytes`, `reapply_dirty_inline`, `apply_extmarks`, and
the `TextChanged`/`TextChangedI`/`InsertLeave` autocmds.

* ci: format
This commit is contained in:
Barrett Ruth 2026-03-09 00:31:13 -04:00 committed by GitHub
parent a38be10e67
commit 1eb2e49096
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 2 deletions

View file

@ -185,7 +185,7 @@ end
---@param line string
---@return string?
local function infer_status(line)
local ch = line:match('^/%d+/- %[(.)%]') or line:match('^- %[(.)%]')
local ch = line:match('^/%d+/%- %[(.)%]') or line:match('^%- %[(.)%]')
if not ch then
return nil
end
@ -205,12 +205,22 @@ function M.reapply_dirty_inline(bufnr)
if not next(_dirty_rows) then
return
end
log.debug(('reapply_dirty: rows=%s'):format(vim.inspect(vim.tbl_keys(_dirty_rows))))
local icons = config.get().icons
for row in pairs(_dirty_rows) do
local m = _meta[row]
if m and m.type == 'task' then
local line = vim.api.nvim_buf_get_lines(bufnr, row - 1, row, false)[1] or ''
local old_status = m.status
m.status = infer_status(line) or m.status
log.debug(
('reapply_dirty: row=%d line=%q old_status=%s new_status=%s'):format(
row,
line,
tostring(old_status),
tostring(m.status)
)
)
end
if m then
vim.api.nvim_buf_clear_namespace(bufnr, ns_inline, row - 1, row)
@ -228,7 +238,7 @@ function M.attach_bytes(bufnr)
end
_on_bytes_active = true
vim.api.nvim_buf_attach(bufnr, false, {
on_bytes = function(_, buf, _, start_row, _, _, old_end_row, _, _, new_end_row, _, _)
on_bytes = function(_, buf, _, start_row, start_col, _, old_end_row, _, _, new_end_row, _, _)
if buf ~= task_bufnr then
_on_bytes_active = false
return true
@ -237,13 +247,24 @@ function M.attach_bytes(bufnr)
return
end
local delta = new_end_row - old_end_row
log.debug(
('on_bytes: start_row=%d start_col=%d old_end=%d new_end=%d delta=%d'):format(
start_row,
start_col,
old_end_row,
new_end_row,
delta
)
)
if delta > 0 then
for _ = 1, delta do
log.debug(('on_bytes: insert meta at %d'):format(start_row + 2))
table.insert(_meta, start_row + 2, { type = 'task' })
end
elseif delta < 0 then
for _ = 1, -delta do
if _meta[start_row + 2] then
log.debug(('on_bytes: remove meta at %d'):format(start_row + 2))
table.remove(_meta, start_row + 2)
end
end
@ -251,6 +272,10 @@ function M.attach_bytes(bufnr)
for r = start_row + 1, start_row + 1 + math.max(0, new_end_row) do
_dirty_rows[r] = true
end
log.debug(('on_bytes: dirty rows=%s'):format(vim.inspect(vim.tbl_keys(_dirty_rows))))
for i, m in ipairs(_meta) do
log.debug(('on_bytes: _meta[%d] type=%s status=%s'):format(i, m.type, tostring(m.status)))
end
end,
})
end
@ -496,7 +521,11 @@ local function apply_extmarks(bufnr, line_meta)
local eol_segments = parse_eol_format(cfg.view.eol_format or '%c %r %d')
vim.api.nvim_buf_clear_namespace(bufnr, ns_eol, 0, -1)
vim.api.nvim_buf_clear_namespace(bufnr, ns_inline, 0, -1)
log.debug(('apply_extmarks: full render, %d lines'):format(#line_meta))
for i, m in ipairs(line_meta) do
log.debug(
('apply_extmarks: row=%d type=%s status=%s'):format(i - 1, m.type, tostring(m.status))
)
local row = i - 1
if m.type == 'task' then
local virt_parts = build_eol_virt(eol_segments, m, icons)

View file

@ -268,6 +268,7 @@ function M._setup_autocmds(bufnr)
if not vim.bo[bufnr].modified then
return
end
log.debug('autocmd: TextChangedI')
for row in pairs(buffer.dirty_rows()) do
buffer.clear_inline_row(bufnr, row)
end
@ -280,6 +281,7 @@ function M._setup_autocmds(bufnr)
if not vim.bo[bufnr].modified then
return
end
log.debug('autocmd: TextChanged')
buffer.reapply_dirty_inline(bufnr)
end,
})
@ -288,6 +290,7 @@ function M._setup_autocmds(bufnr)
buffer = bufnr,
callback = function()
if vim.bo[bufnr].modified then
log.debug('autocmd: InsertLeave')
buffer.reapply_dirty_inline(bufnr)
end
end,