feat(conflict): add virtual text formatting and action lines (#101)
## Problem Conflict resolution virtual text only showed plain "current" / "incoming" labels with no keymap hints. Users had no way to discover available resolution keymaps without reading docs. ## Solution Default virtual text labels now include keymap hints: `(current — doo)` and `(incoming — dot)`. A new `format_virtual_text` config option lets users customize or hide labels entirely. A new `show_actions` option (off by default) renders a codelens-style action line above each `<<<<<<<` marker listing all enabled resolution keymaps. Merge diff views also gain hunk hints on `@@` header lines showing available keymaps. New config fields: `conflict.format_virtual_text` (function|nil), `conflict.show_actions` (boolean). New highlight group: `DiffsConflictActions`.
This commit is contained in:
parent
f5a090baae
commit
b5d28e9f2b
7 changed files with 347 additions and 23 deletions
|
|
@ -338,6 +338,43 @@ function M.goto_prev(bufnr)
|
|||
vim.api.nvim_win_set_cursor(0, { candidates[#candidates].start_line + 1, 0 })
|
||||
end
|
||||
|
||||
---@param bufnr integer
|
||||
---@param config diffs.ConflictConfig
|
||||
local function apply_hunk_hints(bufnr, config)
|
||||
if not config.show_virtual_text then
|
||||
return
|
||||
end
|
||||
|
||||
local hunks = M.parse_hunks(bufnr)
|
||||
for _, hunk in ipairs(hunks) do
|
||||
if M.is_resolved(bufnr, hunk.index) then
|
||||
add_resolved_virtual_text(bufnr, hunk)
|
||||
else
|
||||
local parts = {}
|
||||
local actions = {
|
||||
{ 'current', config.keymaps.ours },
|
||||
{ 'incoming', config.keymaps.theirs },
|
||||
{ 'both', config.keymaps.both },
|
||||
{ 'none', config.keymaps.none },
|
||||
}
|
||||
for _, action in ipairs(actions) do
|
||||
if action[2] then
|
||||
if #parts > 0 then
|
||||
table.insert(parts, { ' | ', 'Comment' })
|
||||
end
|
||||
table.insert(parts, { ('%s: %s'):format(action[2], action[1]), 'Comment' })
|
||||
end
|
||||
end
|
||||
if #parts > 0 then
|
||||
pcall(vim.api.nvim_buf_set_extmark, bufnr, ns, hunk.start_line, 0, {
|
||||
virt_text = parts,
|
||||
virt_text_pos = 'eol',
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param bufnr integer
|
||||
---@param config diffs.ConflictConfig
|
||||
function M.setup_keymaps(bufnr, config)
|
||||
|
|
@ -358,6 +395,8 @@ function M.setup_keymaps(bufnr, config)
|
|||
end
|
||||
end
|
||||
|
||||
apply_hunk_hints(bufnr, config)
|
||||
|
||||
vim.api.nvim_create_autocmd('BufWipeout', {
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue