feat(buffer): render forge links as concealed text with eol virt text

Problem: forge tokens were visible as raw text with no virtual text
labels, and the eol separator logic collapsed all gaps when
non-adjacent specifiers were absent.

Solution: add forge conceal syntax patterns in `setup_syntax()`, add
`PendingForge`/`PendingForgeClosed` highlight groups, handle the
`%l` specifier in `build_eol_virt()`, fix separator collapsing to
buffer one separator between present segments, and change
`concealcursor` to `nc` (reveal in visual and insert mode).
This commit is contained in:
Barrett Ruth 2026-03-10 17:44:30 -04:00
parent 7405390fd9
commit f4e62b148c

View file

@ -365,7 +365,7 @@ end
---@param winid integer
local function set_win_options(winid)
vim.wo[winid].conceallevel = 3
vim.wo[winid].concealcursor = 'nvic'
vim.wo[winid].concealcursor = 'nc'
vim.wo[winid].winfixheight = true
end
@ -379,6 +379,10 @@ local function setup_syntax(bufnr)
syntax match taskCheckbox /\[!\]/ contained containedin=taskLine
syntax match taskLine /^\/\d\+\/- \[.\] .*$/ contains=taskId,taskCheckbox
]])
local forge = require('pending.forge')
for _, pat in ipairs(forge.conceal_patterns()) do
vim.cmd('syntax match forgeRef /' .. pat .. '/ conceal contained containedin=taskLine')
end
end)
end
@ -432,7 +436,7 @@ end
---@class pending.EolSegment
---@field type 'specifier'|'literal'
---@field key? 'c'|'r'|'d'
---@field key? 'c'|'r'|'d'|'l'
---@field text? string
---@param fmt string
@ -444,7 +448,7 @@ local function parse_eol_format(fmt)
while pos <= len do
if fmt:sub(pos, pos) == '%' and pos + 1 <= len then
local key = fmt:sub(pos + 1, pos + 1)
if key == 'c' or key == 'r' or key == 'd' then
if key == 'c' or key == 'r' or key == 'd' or key == 'l' then
table.insert(segments, { type = 'specifier', key = key })
pos = pos + 2
else
@ -471,7 +475,10 @@ local function build_eol_virt(segments, m, icons)
for i, seg in ipairs(segments) do
if seg.type == 'specifier' then
local text, hl
if seg.key == 'c' and m.show_category and m.category then
if seg.key == 'l' and m.forge_ref then
local forge = require('pending.forge')
text, hl = forge.format_label(m.forge_ref, m.forge_cache)
elseif seg.key == 'c' and m.show_category and m.category then
text = icons.category .. ' ' .. m.category
hl = 'PendingHeader'
elseif seg.key == 'r' and m.recur then
@ -488,26 +495,20 @@ local function build_eol_virt(segments, m, icons)
end
local virt_parts = {}
for i, r in ipairs(resolved) do
local pending_sep = nil
for _, r in ipairs(resolved) do
if r.literal then
local prev_present, next_present = false, false
for j = i - 1, 1, -1 do
if not resolved[j].literal then
prev_present = resolved[j].present
break
end
end
for j = i + 1, #resolved do
if not resolved[j].literal then
next_present = resolved[j].present
break
end
end
if prev_present and next_present then
table.insert(virt_parts, { r.text, r.hl })
if #virt_parts > 0 and not pending_sep then
pending_sep = { r.text, r.hl }
end
elseif r.present then
if pending_sep then
table.insert(virt_parts, pending_sep)
pending_sep = nil
end
table.insert(virt_parts, { r.text, r.hl })
else
pending_sep = nil
end
end
return virt_parts
@ -552,6 +553,8 @@ local function setup_highlights()
vim.api.nvim_set_hl(0, 'PendingBlocked', { link = 'DiagnosticError', default = true })
vim.api.nvim_set_hl(0, 'PendingRecur', { link = 'DiagnosticInfo', default = true })
vim.api.nvim_set_hl(0, 'PendingFilter', { link = 'DiagnosticWarn', default = true })
vim.api.nvim_set_hl(0, 'PendingForge', { link = 'DiagnosticInfo', default = true })
vim.api.nvim_set_hl(0, 'PendingForgeClosed', { link = 'Comment', default = true })
end
---@return string
@ -727,6 +730,7 @@ function M.render(bufnr)
end
end
restore_folds(bufnr)
end
---@return nil