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
18
README.md
18
README.md
|
|
@ -9,18 +9,12 @@ syntax highlighting.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- Treesitter syntax highlighting in `:Git` diffs and commit views
|
- Treesitter syntax highlighting in fugitive diffs and commit views
|
||||||
- Diff header highlighting (`diff --git`, `index`, `---`, `+++`)
|
- Character-level intra-line diff highlighting
|
||||||
- `:Gdiffsplit` / `:Gvdiffsplit` syntax through diff backgrounds
|
- `:Gdiff` unified diff against any revision
|
||||||
- `:Gdiff` unified diff against any git revision with syntax highlighting
|
- Background-only diff colors for `&diff` buffers
|
||||||
- Fugitive status buffer keymaps (`du`/`dU`) for unified diffs
|
- Inline merge conflict detection, highlighting, and resolution
|
||||||
- Background-only diff colors for any `&diff` buffer (`:diffthis`, `vimdiff`)
|
- Vim syntax fallback, context padding, configurable blend/debounce
|
||||||
- Vim syntax fallback for languages without a treesitter parser
|
|
||||||
- Hunk header context highlighting (`@@ ... @@ function foo()`)
|
|
||||||
- Character-level (intra-line) diff highlighting for changed characters
|
|
||||||
- Inline merge conflict detection, highlighting, and resolution keymaps
|
|
||||||
- Configurable debouncing, max lines, diff prefix concealment, blend alpha, and
|
|
||||||
highlight overrides
|
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,7 @@ Configuration is done via `vim.g.diffs`. Set this before the plugin loads:
|
||||||
enabled = true,
|
enabled = true,
|
||||||
disable_diagnostics = true,
|
disable_diagnostics = true,
|
||||||
show_virtual_text = true,
|
show_virtual_text = true,
|
||||||
|
show_actions = false,
|
||||||
keymaps = {
|
keymaps = {
|
||||||
ours = 'doo',
|
ours = 'doo',
|
||||||
theirs = 'dot',
|
theirs = 'dot',
|
||||||
|
|
@ -416,6 +417,7 @@ Configuration: ~
|
||||||
enabled = true,
|
enabled = true,
|
||||||
disable_diagnostics = true,
|
disable_diagnostics = true,
|
||||||
show_virtual_text = true,
|
show_virtual_text = true,
|
||||||
|
show_actions = false,
|
||||||
keymaps = {
|
keymaps = {
|
||||||
ours = 'doo',
|
ours = 'doo',
|
||||||
theirs = 'dot',
|
theirs = 'dot',
|
||||||
|
|
@ -442,9 +444,32 @@ Configuration: ~
|
||||||
diagnostics alone.
|
diagnostics alone.
|
||||||
|
|
||||||
{show_virtual_text} (boolean, default: true)
|
{show_virtual_text} (boolean, default: true)
|
||||||
Show virtual text labels (" current" and
|
Show `(current)` and `(incoming)` labels at
|
||||||
" incoming") at the end of `<<<<<<<` and
|
the end of `<<<<<<<` and `>>>>>>>` marker
|
||||||
`>>>>>>>` marker lines.
|
lines. Also controls hunk hints in merge
|
||||||
|
diff views.
|
||||||
|
|
||||||
|
{format_virtual_text} (function|nil, default: nil)
|
||||||
|
Custom formatter for virtual text labels.
|
||||||
|
Receives `(side, keymap)` where `side` is
|
||||||
|
`"ours"` or `"theirs"` and `keymap` is the
|
||||||
|
configured keymap string or `false`. Return
|
||||||
|
a string (label text without parens) or
|
||||||
|
`nil` to hide the label. Example: >lua
|
||||||
|
format_virtual_text = function(side, keymap)
|
||||||
|
if keymap then
|
||||||
|
return side .. ' [' .. keymap .. ']'
|
||||||
|
end
|
||||||
|
return side
|
||||||
|
end
|
||||||
|
<
|
||||||
|
|
||||||
|
{show_actions} (boolean, default: false)
|
||||||
|
Show a codelens-style action line above each
|
||||||
|
`<<<<<<<` marker listing available resolution
|
||||||
|
keymaps. Renders as virtual lines using the
|
||||||
|
`DiffsConflictActions` highlight group.
|
||||||
|
Only keymaps that are not `false` appear.
|
||||||
|
|
||||||
{keymaps} (table, default: see above)
|
{keymaps} (table, default: see above)
|
||||||
Buffer-local keymaps for conflict resolution
|
Buffer-local keymaps for conflict resolution
|
||||||
|
|
@ -687,6 +712,10 @@ Conflict highlights: ~
|
||||||
*DiffsConflictBaseNr*
|
*DiffsConflictBaseNr*
|
||||||
DiffsConflictBaseNr Line number for base content lines (diff3).
|
DiffsConflictBaseNr Line number for base content lines (diff3).
|
||||||
|
|
||||||
|
*DiffsConflictActions*
|
||||||
|
DiffsConflictActions Dimmed foreground (no bold) for the codelens-style
|
||||||
|
action line shown when `show_actions` is true.
|
||||||
|
|
||||||
Diff mode window highlights: ~
|
Diff mode window highlights: ~
|
||||||
These are used for |winhighlight| remapping in `&diff` windows.
|
These are used for |winhighlight| remapping in `&diff` windows.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,17 @@ local function parse_buffer(bufnr)
|
||||||
return M.parse(lines)
|
return M.parse(lines)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param side string
|
||||||
|
---@param config diffs.ConflictConfig
|
||||||
|
---@return string?
|
||||||
|
local function get_virtual_text_label(side, config)
|
||||||
|
if config.format_virtual_text then
|
||||||
|
local keymap = side == 'ours' and config.keymaps.ours or config.keymaps.theirs
|
||||||
|
return config.format_virtual_text(side, keymap)
|
||||||
|
end
|
||||||
|
return side == 'ours' and 'current' or 'incoming'
|
||||||
|
end
|
||||||
|
|
||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
---@param regions diffs.ConflictRegion[]
|
---@param regions diffs.ConflictRegion[]
|
||||||
---@param config diffs.ConflictConfig
|
---@param config diffs.ConflictConfig
|
||||||
|
|
@ -107,10 +118,37 @@ local function apply_highlights(bufnr, regions, config)
|
||||||
})
|
})
|
||||||
|
|
||||||
if config.show_virtual_text then
|
if config.show_virtual_text then
|
||||||
pcall(vim.api.nvim_buf_set_extmark, bufnr, ns, region.marker_ours, 0, {
|
local ours_label = get_virtual_text_label('ours', config)
|
||||||
virt_text = { { ' (current)', 'DiffsConflictMarker' } },
|
if ours_label then
|
||||||
virt_text_pos = 'eol',
|
pcall(vim.api.nvim_buf_set_extmark, bufnr, ns, region.marker_ours, 0, {
|
||||||
})
|
virt_text = { { ' (' .. ours_label .. ')', 'DiffsConflictMarker' } },
|
||||||
|
virt_text_pos = 'eol',
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if config.show_actions then
|
||||||
|
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, { ' \226\148\130 ', 'DiffsConflictActions' })
|
||||||
|
end
|
||||||
|
table.insert(parts, { ('%s (%s)'):format(action[1], action[2]), 'DiffsConflictActions' })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if #parts > 0 then
|
||||||
|
pcall(vim.api.nvim_buf_set_extmark, bufnr, ns, region.marker_ours, 0, {
|
||||||
|
virt_lines = { parts },
|
||||||
|
virt_lines_above = true,
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for line = region.ours_start, region.ours_end - 1 do
|
for line = region.ours_start, region.ours_end - 1 do
|
||||||
|
|
@ -176,10 +214,13 @@ local function apply_highlights(bufnr, regions, config)
|
||||||
})
|
})
|
||||||
|
|
||||||
if config.show_virtual_text then
|
if config.show_virtual_text then
|
||||||
pcall(vim.api.nvim_buf_set_extmark, bufnr, ns, region.marker_theirs, 0, {
|
local theirs_label = get_virtual_text_label('theirs', config)
|
||||||
virt_text = { { ' (incoming)', 'DiffsConflictMarker' } },
|
if theirs_label then
|
||||||
virt_text_pos = 'eol',
|
pcall(vim.api.nvim_buf_set_extmark, bufnr, ns, region.marker_theirs, 0, {
|
||||||
})
|
virt_text = { { ' (' .. theirs_label .. ')', 'DiffsConflictMarker' } },
|
||||||
|
virt_text_pos = 'eol',
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,8 @@
|
||||||
---@field enabled boolean
|
---@field enabled boolean
|
||||||
---@field disable_diagnostics boolean
|
---@field disable_diagnostics boolean
|
||||||
---@field show_virtual_text boolean
|
---@field show_virtual_text boolean
|
||||||
|
---@field format_virtual_text? fun(side: string, keymap: string|false): string?
|
||||||
|
---@field show_actions boolean
|
||||||
---@field keymaps diffs.ConflictKeymaps
|
---@field keymaps diffs.ConflictKeymaps
|
||||||
|
|
||||||
---@class diffs.Config
|
---@class diffs.Config
|
||||||
|
|
@ -128,6 +130,7 @@ local default_config = {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
disable_diagnostics = true,
|
disable_diagnostics = true,
|
||||||
show_virtual_text = true,
|
show_virtual_text = true,
|
||||||
|
show_actions = false,
|
||||||
keymaps = {
|
keymaps = {
|
||||||
ours = 'doo',
|
ours = 'doo',
|
||||||
theirs = 'dot',
|
theirs = 'dot',
|
||||||
|
|
@ -276,6 +279,7 @@ local function compute_highlight_groups()
|
||||||
vim.api.nvim_set_hl(0, 'DiffsConflictTheirs', { default = true, bg = blended_theirs })
|
vim.api.nvim_set_hl(0, 'DiffsConflictTheirs', { default = true, bg = blended_theirs })
|
||||||
vim.api.nvim_set_hl(0, 'DiffsConflictBase', { default = true, bg = blended_base })
|
vim.api.nvim_set_hl(0, 'DiffsConflictBase', { default = true, bg = blended_base })
|
||||||
vim.api.nvim_set_hl(0, 'DiffsConflictMarker', { default = true, fg = 0x808080, bold = true })
|
vim.api.nvim_set_hl(0, 'DiffsConflictMarker', { default = true, fg = 0x808080, bold = true })
|
||||||
|
vim.api.nvim_set_hl(0, 'DiffsConflictActions', { default = true, fg = 0x808080 })
|
||||||
vim.api.nvim_set_hl(
|
vim.api.nvim_set_hl(
|
||||||
0,
|
0,
|
||||||
'DiffsConflictOursNr',
|
'DiffsConflictOursNr',
|
||||||
|
|
@ -390,6 +394,8 @@ local function init()
|
||||||
['conflict.enabled'] = { opts.conflict.enabled, 'boolean', true },
|
['conflict.enabled'] = { opts.conflict.enabled, 'boolean', true },
|
||||||
['conflict.disable_diagnostics'] = { opts.conflict.disable_diagnostics, 'boolean', true },
|
['conflict.disable_diagnostics'] = { opts.conflict.disable_diagnostics, 'boolean', true },
|
||||||
['conflict.show_virtual_text'] = { opts.conflict.show_virtual_text, 'boolean', true },
|
['conflict.show_virtual_text'] = { opts.conflict.show_virtual_text, 'boolean', true },
|
||||||
|
['conflict.format_virtual_text'] = { opts.conflict.format_virtual_text, 'function', true },
|
||||||
|
['conflict.show_actions'] = { opts.conflict.show_actions, 'boolean', true },
|
||||||
['conflict.keymaps'] = { opts.conflict.keymaps, 'table', true },
|
['conflict.keymaps'] = { opts.conflict.keymaps, 'table', true },
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -338,6 +338,43 @@ function M.goto_prev(bufnr)
|
||||||
vim.api.nvim_win_set_cursor(0, { candidates[#candidates].start_line + 1, 0 })
|
vim.api.nvim_win_set_cursor(0, { candidates[#candidates].start_line + 1, 0 })
|
||||||
end
|
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 bufnr integer
|
||||||
---@param config diffs.ConflictConfig
|
---@param config diffs.ConflictConfig
|
||||||
function M.setup_keymaps(bufnr, config)
|
function M.setup_keymaps(bufnr, config)
|
||||||
|
|
@ -358,6 +395,8 @@ function M.setup_keymaps(bufnr, config)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
apply_hunk_hints(bufnr, config)
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd('BufWipeout', {
|
vim.api.nvim_create_autocmd('BufWipeout', {
|
||||||
buffer = bufnr,
|
buffer = bufnr,
|
||||||
callback = function()
|
callback = function()
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ local function default_config(overrides)
|
||||||
enabled = true,
|
enabled = true,
|
||||||
disable_diagnostics = false,
|
disable_diagnostics = false,
|
||||||
show_virtual_text = true,
|
show_virtual_text = true,
|
||||||
|
show_actions = false,
|
||||||
keymaps = {
|
keymaps = {
|
||||||
ours = 'doo',
|
ours = 'doo',
|
||||||
theirs = 'dot',
|
theirs = 'dot',
|
||||||
|
|
@ -685,4 +686,158 @@ describe('conflict', function()
|
||||||
helpers.delete_buffer(bufnr)
|
helpers.delete_buffer(bufnr)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('virtual text formatting', function()
|
||||||
|
after_each(function()
|
||||||
|
conflict.detach(vim.api.nvim_get_current_buf())
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('default labels show current and incoming without keymaps', function()
|
||||||
|
local bufnr = create_file_buffer({
|
||||||
|
'<<<<<<< HEAD',
|
||||||
|
'local x = 1',
|
||||||
|
'=======',
|
||||||
|
'local x = 2',
|
||||||
|
'>>>>>>> feature',
|
||||||
|
})
|
||||||
|
|
||||||
|
conflict.attach(bufnr, default_config())
|
||||||
|
|
||||||
|
local extmarks = get_extmarks(bufnr)
|
||||||
|
local labels = {}
|
||||||
|
for _, mark in ipairs(extmarks) do
|
||||||
|
if mark[4] and mark[4].virt_text then
|
||||||
|
table.insert(labels, mark[4].virt_text[1][1])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert.are.equal(2, #labels)
|
||||||
|
assert.are.equal(' (current)', labels[1])
|
||||||
|
assert.are.equal(' (incoming)', labels[2])
|
||||||
|
|
||||||
|
helpers.delete_buffer(bufnr)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('uses custom format_virtual_text function', function()
|
||||||
|
local bufnr = create_file_buffer({
|
||||||
|
'<<<<<<< HEAD',
|
||||||
|
'local x = 1',
|
||||||
|
'=======',
|
||||||
|
'local x = 2',
|
||||||
|
'>>>>>>> feature',
|
||||||
|
})
|
||||||
|
|
||||||
|
conflict.attach(
|
||||||
|
bufnr,
|
||||||
|
default_config({
|
||||||
|
format_virtual_text = function(side)
|
||||||
|
return side == 'ours' and 'OURS' or 'THEIRS'
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
local extmarks = get_extmarks(bufnr)
|
||||||
|
local labels = {}
|
||||||
|
for _, mark in ipairs(extmarks) do
|
||||||
|
if mark[4] and mark[4].virt_text then
|
||||||
|
table.insert(labels, mark[4].virt_text[1][1])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert.are.equal(2, #labels)
|
||||||
|
assert.are.equal(' (OURS)', labels[1])
|
||||||
|
assert.are.equal(' (THEIRS)', labels[2])
|
||||||
|
|
||||||
|
helpers.delete_buffer(bufnr)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('hides label when format_virtual_text returns nil', function()
|
||||||
|
local bufnr = create_file_buffer({
|
||||||
|
'<<<<<<< HEAD',
|
||||||
|
'local x = 1',
|
||||||
|
'=======',
|
||||||
|
'local x = 2',
|
||||||
|
'>>>>>>> feature',
|
||||||
|
})
|
||||||
|
|
||||||
|
conflict.attach(
|
||||||
|
bufnr,
|
||||||
|
default_config({
|
||||||
|
format_virtual_text = function()
|
||||||
|
return nil
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
local extmarks = get_extmarks(bufnr)
|
||||||
|
local virt_text_count = 0
|
||||||
|
for _, mark in ipairs(extmarks) do
|
||||||
|
if mark[4] and mark[4].virt_text then
|
||||||
|
virt_text_count = virt_text_count + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert.are.equal(0, virt_text_count)
|
||||||
|
|
||||||
|
helpers.delete_buffer(bufnr)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
describe('action lines', function()
|
||||||
|
after_each(function()
|
||||||
|
conflict.detach(vim.api.nvim_get_current_buf())
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('adds virt_lines when show_actions is true', function()
|
||||||
|
local bufnr = create_file_buffer({
|
||||||
|
'<<<<<<< HEAD',
|
||||||
|
'local x = 1',
|
||||||
|
'=======',
|
||||||
|
'local x = 2',
|
||||||
|
'>>>>>>> feature',
|
||||||
|
})
|
||||||
|
|
||||||
|
conflict.attach(bufnr, default_config({ show_actions = true }))
|
||||||
|
|
||||||
|
local extmarks = get_extmarks(bufnr)
|
||||||
|
local virt_lines_count = 0
|
||||||
|
for _, mark in ipairs(extmarks) do
|
||||||
|
if mark[4] and mark[4].virt_lines then
|
||||||
|
virt_lines_count = virt_lines_count + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert.are.equal(1, virt_lines_count)
|
||||||
|
|
||||||
|
helpers.delete_buffer(bufnr)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('omits disabled keymaps from action line', function()
|
||||||
|
local bufnr = create_file_buffer({
|
||||||
|
'<<<<<<< HEAD',
|
||||||
|
'local x = 1',
|
||||||
|
'=======',
|
||||||
|
'local x = 2',
|
||||||
|
'>>>>>>> feature',
|
||||||
|
})
|
||||||
|
|
||||||
|
conflict.attach(
|
||||||
|
bufnr,
|
||||||
|
default_config({ show_actions = true, keymaps = { both = false, none = false } })
|
||||||
|
)
|
||||||
|
|
||||||
|
local extmarks = get_extmarks(bufnr)
|
||||||
|
for _, mark in ipairs(extmarks) do
|
||||||
|
if mark[4] and mark[4].virt_lines then
|
||||||
|
local line = mark[4].virt_lines[1]
|
||||||
|
local text = ''
|
||||||
|
for _, chunk in ipairs(line) do
|
||||||
|
text = text .. chunk[1]
|
||||||
|
end
|
||||||
|
assert.is_truthy(text:find('Current'))
|
||||||
|
assert.is_truthy(text:find('Incoming'))
|
||||||
|
assert.is_falsy(text:find('Both'))
|
||||||
|
assert.is_falsy(text:find('None'))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
helpers.delete_buffer(bufnr)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ local function default_config(overrides)
|
||||||
enabled = true,
|
enabled = true,
|
||||||
disable_diagnostics = false,
|
disable_diagnostics = false,
|
||||||
show_virtual_text = true,
|
show_virtual_text = true,
|
||||||
|
show_actions = false,
|
||||||
keymaps = {
|
keymaps = {
|
||||||
ours = 'doo',
|
ours = 'doo',
|
||||||
theirs = 'dot',
|
theirs = 'dot',
|
||||||
|
|
@ -617,6 +618,65 @@ describe('merge', function()
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('hunk hints', function()
|
||||||
|
it('adds keymap hints on hunk header lines', function()
|
||||||
|
local d_bufnr = create_diff_buffer({
|
||||||
|
'diff --git a/file.lua b/file.lua',
|
||||||
|
'--- a/file.lua',
|
||||||
|
'+++ b/file.lua',
|
||||||
|
'@@ -1,1 +1,1 @@',
|
||||||
|
'-local x = 1',
|
||||||
|
'+local x = 2',
|
||||||
|
})
|
||||||
|
|
||||||
|
merge.setup_keymaps(d_bufnr, default_config())
|
||||||
|
|
||||||
|
local extmarks =
|
||||||
|
vim.api.nvim_buf_get_extmarks(d_bufnr, merge.get_namespace(), 0, -1, { details = true })
|
||||||
|
local hint_marks = {}
|
||||||
|
for _, mark in ipairs(extmarks) do
|
||||||
|
if mark[4] and mark[4].virt_text then
|
||||||
|
local text = ''
|
||||||
|
for _, chunk in ipairs(mark[4].virt_text) do
|
||||||
|
text = text .. chunk[1]
|
||||||
|
end
|
||||||
|
table.insert(hint_marks, { line = mark[2], text = text })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert.are.equal(1, #hint_marks)
|
||||||
|
assert.are.equal(3, hint_marks[1].line)
|
||||||
|
assert.is_truthy(hint_marks[1].text:find('doo'))
|
||||||
|
assert.is_truthy(hint_marks[1].text:find('dot'))
|
||||||
|
|
||||||
|
helpers.delete_buffer(d_bufnr)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('does not add hints when show_virtual_text is false', function()
|
||||||
|
local d_bufnr = create_diff_buffer({
|
||||||
|
'diff --git a/file.lua b/file.lua',
|
||||||
|
'--- a/file.lua',
|
||||||
|
'+++ b/file.lua',
|
||||||
|
'@@ -1,1 +1,1 @@',
|
||||||
|
'-local x = 1',
|
||||||
|
'+local x = 2',
|
||||||
|
})
|
||||||
|
|
||||||
|
merge.setup_keymaps(d_bufnr, default_config({ show_virtual_text = false }))
|
||||||
|
|
||||||
|
local extmarks =
|
||||||
|
vim.api.nvim_buf_get_extmarks(d_bufnr, merge.get_namespace(), 0, -1, { details = true })
|
||||||
|
local virt_text_count = 0
|
||||||
|
for _, mark in ipairs(extmarks) do
|
||||||
|
if mark[4] and mark[4].virt_text then
|
||||||
|
virt_text_count = virt_text_count + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert.are.equal(0, virt_text_count)
|
||||||
|
|
||||||
|
helpers.delete_buffer(d_bufnr)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
describe('fugitive integration', function()
|
describe('fugitive integration', function()
|
||||||
it('parse_file_line returns status for unmerged files', function()
|
it('parse_file_line returns status for unmerged files', function()
|
||||||
local fugitive = require('diffs.fugitive')
|
local fugitive = require('diffs.fugitive')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue