fix(ci): format
This commit is contained in:
parent
d193fabfb9
commit
ab9a0f43b5
5 changed files with 48 additions and 33 deletions
|
|
@ -83,14 +83,14 @@ M.defaults = {
|
||||||
scrapers = constants.PLATFORMS,
|
scrapers = constants.PLATFORMS,
|
||||||
filename = nil,
|
filename = nil,
|
||||||
test_panel = {
|
test_panel = {
|
||||||
diff_mode = "vim",
|
diff_mode = 'vim',
|
||||||
toggle_key = "t",
|
toggle_key = 't',
|
||||||
status_format = "compact",
|
status_format = 'compact',
|
||||||
},
|
},
|
||||||
diff = {
|
diff = {
|
||||||
git = {
|
git = {
|
||||||
command = "git",
|
command = 'git',
|
||||||
args = {"diff", "--no-index", "--word-diff=plain", "--word-diff-regex=.", "--no-prefix"},
|
args = { 'diff', '--no-index', '--word-diff=plain', '--word-diff-regex=.', '--no-prefix' },
|
||||||
},
|
},
|
||||||
vim = {
|
vim = {
|
||||||
enable_diffthis = true,
|
enable_diffthis = true,
|
||||||
|
|
@ -142,7 +142,7 @@ function M.setup(user_config)
|
||||||
diff_mode = {
|
diff_mode = {
|
||||||
user_config.test_panel.diff_mode,
|
user_config.test_panel.diff_mode,
|
||||||
function(value)
|
function(value)
|
||||||
return vim.tbl_contains({"vim", "git"}, value)
|
return vim.tbl_contains({ 'vim', 'git' }, value)
|
||||||
end,
|
end,
|
||||||
"diff_mode must be 'vim' or 'git'",
|
"diff_mode must be 'vim' or 'git'",
|
||||||
},
|
},
|
||||||
|
|
@ -150,7 +150,7 @@ function M.setup(user_config)
|
||||||
status_format = {
|
status_format = {
|
||||||
user_config.test_panel.status_format,
|
user_config.test_panel.status_format,
|
||||||
function(value)
|
function(value)
|
||||||
return vim.tbl_contains({"compact", "verbose"}, value)
|
return vim.tbl_contains({ 'compact', 'verbose' }, value)
|
||||||
end,
|
end,
|
||||||
"status_format must be 'compact' or 'verbose'",
|
"status_format must be 'compact' or 'verbose'",
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,9 @@ local vim_backend = {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
content = actual_lines,
|
content = actual_lines,
|
||||||
highlights = nil -- diffthis handles highlighting
|
highlights = nil, -- diffthis handles highlighting
|
||||||
}
|
}
|
||||||
end
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
---Git word-diff backend for character-level precision
|
---Git word-diff backend for character-level precision
|
||||||
|
|
@ -37,8 +37,14 @@ local git_backend = {
|
||||||
vim.fn.writefile(vim.split(actual, '\n', { plain = true }), tmp_actual)
|
vim.fn.writefile(vim.split(actual, '\n', { plain = true }), tmp_actual)
|
||||||
|
|
||||||
local cmd = {
|
local cmd = {
|
||||||
'git', 'diff', '--no-index', '--word-diff=plain', '--word-diff-regex=.',
|
'git',
|
||||||
'--no-prefix', tmp_expected, tmp_actual
|
'diff',
|
||||||
|
'--no-index',
|
||||||
|
'--word-diff=plain',
|
||||||
|
'--word-diff-regex=.',
|
||||||
|
'--no-prefix',
|
||||||
|
tmp_expected,
|
||||||
|
tmp_actual,
|
||||||
}
|
}
|
||||||
|
|
||||||
local result = vim.system(cmd, { text = true }):wait()
|
local result = vim.system(cmd, { text = true }):wait()
|
||||||
|
|
@ -50,17 +56,17 @@ local git_backend = {
|
||||||
if result.code == 0 then
|
if result.code == 0 then
|
||||||
return {
|
return {
|
||||||
content = vim.split(actual, '\n', { plain = true, trimempty = true }),
|
content = vim.split(actual, '\n', { plain = true, trimempty = true }),
|
||||||
highlights = {}
|
highlights = {},
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
local highlight_module = require('cp.highlight')
|
local highlight_module = require('cp.highlight')
|
||||||
return {
|
return {
|
||||||
content = {},
|
content = {},
|
||||||
highlights = {},
|
highlights = {},
|
||||||
raw_diff = result.stdout or ''
|
raw_diff = result.stdout or '',
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
---Available diff backends
|
---Available diff backends
|
||||||
|
|
@ -86,7 +92,7 @@ end
|
||||||
---Check if git backend is available
|
---Check if git backend is available
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function M.is_git_available()
|
function M.is_git_available()
|
||||||
local result = vim.system({'git', '--version'}, { text = true }):wait()
|
local result = vim.system({ 'git', '--version' }, { text = true }):wait()
|
||||||
return result.code == 0
|
return result.code == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -115,4 +121,4 @@ function M.render_diff(expected, actual, backend_name, mode)
|
||||||
return backend.render(expected, actual, mode)
|
return backend.render(expected, actual, mode)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ local function parse_diff_line(text)
|
||||||
local start_pos = text:find('%[%-' .. vim.pesc(removed_text) .. '%-%]', 1, false)
|
local start_pos = text:find('%[%-' .. vim.pesc(removed_text) .. '%-%]', 1, false)
|
||||||
if start_pos then
|
if start_pos then
|
||||||
-- Remove the marker and adjust positions
|
-- Remove the marker and adjust positions
|
||||||
local marker_len = #('[-%-%]') + #removed_text
|
local marker_len = #'[-%-%]' + #removed_text
|
||||||
cleaned_text = cleaned_text:gsub('%[%-' .. vim.pesc(removed_text) .. '%-%]', '', 1)
|
cleaned_text = cleaned_text:gsub('%[%-' .. vim.pesc(removed_text) .. '%-%]', '', 1)
|
||||||
|
|
||||||
-- Since we're removing text, we don't add highlights for removed content in the actual pane
|
-- Since we're removing text, we don't add highlights for removed content in the actual pane
|
||||||
|
|
@ -41,20 +41,20 @@ local function parse_diff_line(text)
|
||||||
local start_pos = final_text:find('{%+' .. vim.pesc(added_text) .. '%+}', 1, false)
|
local start_pos = final_text:find('{%+' .. vim.pesc(added_text) .. '%+}', 1, false)
|
||||||
if start_pos then
|
if start_pos then
|
||||||
-- Calculate position after previous highlights
|
-- Calculate position after previous highlights
|
||||||
local highlight_start = start_pos - offset - 1 -- 0-based for extmarks
|
local highlight_start = start_pos - offset - 1 -- 0-based for extmarks
|
||||||
local highlight_end = highlight_start + #added_text
|
local highlight_end = highlight_start + #added_text
|
||||||
|
|
||||||
table.insert(final_highlights, {
|
table.insert(final_highlights, {
|
||||||
line = 0, -- Will be set by caller
|
line = 0, -- Will be set by caller
|
||||||
col_start = highlight_start,
|
col_start = highlight_start,
|
||||||
col_end = highlight_end,
|
col_end = highlight_end,
|
||||||
highlight_group = 'CpDiffAdded'
|
highlight_group = 'CpDiffAdded',
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Remove the marker
|
-- Remove the marker
|
||||||
local marker_len = #{'{+'} + #{'+}'} + #added_text
|
local marker_len = #{ '{+' } + #{ '+}' } + #added_text
|
||||||
final_text = final_text:gsub('{%+' .. vim.pesc(added_text) .. '%+}', added_text, 1)
|
final_text = final_text:gsub('{%+' .. vim.pesc(added_text) .. '%+}', added_text, 1)
|
||||||
offset = offset + #{'{+'} + #{'+}'}
|
offset = offset + #{ '{+' } + #{ '+}' }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -73,13 +73,16 @@ function M.parse_git_diff(diff_output)
|
||||||
local content_started = false
|
local content_started = false
|
||||||
for _, line in ipairs(lines) do
|
for _, line in ipairs(lines) do
|
||||||
-- Skip header lines (@@, +++, ---, index, etc.)
|
-- Skip header lines (@@, +++, ---, index, etc.)
|
||||||
if content_started or (
|
if
|
||||||
not line:match('^@@') and
|
content_started
|
||||||
not line:match('^%+%+%+') and
|
or (
|
||||||
not line:match('^%-%-%-') and
|
not line:match('^@@')
|
||||||
not line:match('^index') and
|
and not line:match('^%+%+%+')
|
||||||
not line:match('^diff %-%-git')
|
and not line:match('^%-%-%-')
|
||||||
) then
|
and not line:match('^index')
|
||||||
|
and not line:match('^diff %-%-git')
|
||||||
|
)
|
||||||
|
then
|
||||||
content_started = true
|
content_started = true
|
||||||
|
|
||||||
-- Process content lines
|
-- Process content lines
|
||||||
|
|
@ -115,7 +118,7 @@ function M.parse_git_diff(diff_output)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
content = content_lines,
|
content = content_lines,
|
||||||
highlights = all_highlights
|
highlights = all_highlights,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -161,4 +164,4 @@ function M.parse_and_apply_diff(bufnr, diff_output, namespace)
|
||||||
return parsed.content
|
return parsed.content
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
|
|
@ -193,7 +193,7 @@ local function toggle_test_panel(is_debug)
|
||||||
|
|
||||||
-- Set buffer options
|
-- Set buffer options
|
||||||
local buffer_opts = { 'bufhidden', 'wipe' }
|
local buffer_opts = { 'bufhidden', 'wipe' }
|
||||||
for _, buf in ipairs({tab_buf, expected_buf, actual_buf}) do
|
for _, buf in ipairs({ tab_buf, expected_buf, actual_buf }) do
|
||||||
vim.api.nvim_set_option_value('bufhidden', 'wipe', { buf = buf })
|
vim.api.nvim_set_option_value('bufhidden', 'wipe', { buf = buf })
|
||||||
vim.api.nvim_set_option_value('readonly', true, { buf = buf })
|
vim.api.nvim_set_option_value('readonly', true, { buf = buf })
|
||||||
vim.api.nvim_set_option_value('modifiable', false, { buf = buf })
|
vim.api.nvim_set_option_value('modifiable', false, { buf = buf })
|
||||||
|
|
@ -295,7 +295,11 @@ local function toggle_test_panel(is_debug)
|
||||||
if backend.name == 'git' then
|
if backend.name == 'git' then
|
||||||
local diff_result = backend.render(current_test.expected, current_test.actual)
|
local diff_result = backend.render(current_test.expected, current_test.actual)
|
||||||
if diff_result.raw_diff and diff_result.raw_diff ~= '' then
|
if diff_result.raw_diff and diff_result.raw_diff ~= '' then
|
||||||
highlight.parse_and_apply_diff(test_buffers.actual_buf, diff_result.raw_diff, diff_namespace)
|
highlight.parse_and_apply_diff(
|
||||||
|
test_buffers.actual_buf,
|
||||||
|
diff_result.raw_diff,
|
||||||
|
diff_namespace
|
||||||
|
)
|
||||||
else
|
else
|
||||||
update_buffer_content(test_buffers.actual_buf, actual_lines)
|
update_buffer_content(test_buffers.actual_buf, actual_lines)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,9 @@ function M.render_test_list(test_state, config)
|
||||||
table.insert(lines, line)
|
table.insert(lines, line)
|
||||||
|
|
||||||
if is_current and test_case.input and test_case.input ~= '' then
|
if is_current and test_case.input and test_case.input ~= '' then
|
||||||
for _, input_line in ipairs(vim.split(test_case.input, '\n', { plain = true, trimempty = false })) do
|
for _, input_line in
|
||||||
|
ipairs(vim.split(test_case.input, '\n', { plain = true, trimempty = false }))
|
||||||
|
do
|
||||||
table.insert(lines, ' ' .. input_line)
|
table.insert(lines, ' ' .. input_line)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue