fix(ci): format

This commit is contained in:
Barrett Ruth 2025-09-19 19:22:13 -04:00
parent 99340e551b
commit 0b14c2bb87
2 changed files with 55 additions and 49 deletions

View file

@ -14,44 +14,42 @@ local M = {}
---@param text string Raw git diff output line ---@param text string Raw git diff output line
---@return string cleaned_text, DiffHighlight[] ---@return string cleaned_text, DiffHighlight[]
local function parse_diff_line(text) local function parse_diff_line(text)
local cleaned_text = text local result_text = ''
local offset = 0 local highlights = {}
local pos = 1
-- Pattern for removed text: [-removed text-] while pos <= #text do
for removed_text in text:gmatch('%[%-(.-)%-%]') do local removed_start, removed_end, removed_content = text:find('%[%-(.-)%-%]', pos)
local start_pos = text:find('%[%-' .. vim.pesc(removed_text) .. '%-%]', 1, false) if removed_start and removed_start == pos then
if start_pos then local highlight_start = #result_text
cleaned_text = cleaned_text:gsub('%[%-' .. vim.pesc(removed_text) .. '%-%]', '', 1) result_text = result_text .. removed_content
end table.insert(highlights, {
end line = 0,
-- Reset for added text parsing on the cleaned text
local final_text = cleaned_text
local final_highlights = {}
offset = 0
-- Pattern for added text: {+added text+}
for added_text in cleaned_text:gmatch('{%+(.-)%+}') do
local start_pos = final_text:find('{%+' .. vim.pesc(added_text) .. '%+}', 1, false)
if start_pos then
-- Calculate position after previous highlights
local highlight_start = start_pos - offset - 1 -- 0-based for extmarks
local highlight_end = highlight_start + #added_text
table.insert(final_highlights, {
line = 0, -- Will be set by caller
col_start = highlight_start, col_start = highlight_start,
col_end = highlight_end, col_end = #result_text,
highlight_group = 'CpDiffAdded', highlight_group = 'CpDiffRemoved',
}) })
pos = removed_end + 1
-- Remove the marker else
final_text = final_text:gsub('{%+' .. vim.pesc(added_text) .. '%+}', added_text, 1) local added_start, added_end, added_content = text:find('{%+(.-)%+}', pos)
offset = offset + 4 -- Length of {+ and +} if added_start and added_start == pos then
local highlight_start = #result_text
result_text = result_text .. added_content
table.insert(highlights, {
line = 0,
col_start = highlight_start,
col_end = #result_text,
highlight_group = 'CpDiffAdded',
})
pos = added_end + 1
else
result_text = result_text .. text:sub(pos, pos)
pos = pos + 1
end
end end
end end
return final_text, final_highlights return result_text, highlights
end end
---Parse complete git diff output ---Parse complete git diff output
@ -97,16 +95,20 @@ function M.parse_git_diff(diff_output)
table.insert(all_highlights, highlight) table.insert(all_highlights, highlight)
end end
elseif not line:match('^%-') and not line:match('^\\') then -- Skip removed lines and "\ No newline" messages elseif not line:match('^%-') and not line:match('^\\') then -- Skip removed lines and "\ No newline" messages
-- Unchanged line - remove leading space if present -- Word-diff content line or unchanged line
local clean_line = line:match('^%s') and line:sub(2) or line local clean_line = line:match('^%s') and line:sub(2) or line
local parsed_line, line_highlights = parse_diff_line(clean_line) local parsed_line, line_highlights = parse_diff_line(clean_line)
table.insert(content_lines, parsed_line)
-- Set line numbers for any highlights (shouldn't be any for unchanged lines) -- Only add non-empty lines
local line_num = #content_lines if parsed_line ~= '' then
for _, highlight in ipairs(line_highlights) do table.insert(content_lines, parsed_line)
highlight.line = line_num - 1 -- 0-based for extmarks
table.insert(all_highlights, highlight) -- Set line numbers for highlights
local line_num = #content_lines
for _, highlight in ipairs(line_highlights) do
highlight.line = line_num - 1 -- 0-based for extmarks
table.insert(all_highlights, highlight)
end
end end
end end
end end

View file

@ -152,6 +152,19 @@ local function get_current_problem()
return filename return filename
end end
local function create_buffer_with_options(filetype)
local buf = vim.api.nvim_create_buf(false, true)
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('modifiable', false, { buf = buf })
if filetype then
vim.api.nvim_set_option_value('filetype', filetype, { buf = buf })
end
return buf
end
local setup_keybindings_for_buffer
local function toggle_run_panel(is_debug) local function toggle_run_panel(is_debug)
if state.run_panel_active then if state.run_panel_active then
if current_diff_layout then if current_diff_layout then
@ -230,15 +243,6 @@ local function toggle_run_panel(is_debug)
end end
end end
local function create_buffer_with_options()
local buf = vim.api.nvim_create_buf(false, true)
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('modifiable', false, { buf = buf })
vim.api.nvim_set_option_value('filetype', 'cptest', { buf = buf })
return buf
end
local function create_vim_diff_layout(parent_win, expected_content, actual_content) local function create_vim_diff_layout(parent_win, expected_content, actual_content)
local expected_buf = create_buffer_with_options() local expected_buf = create_buffer_with_options()
local actual_buf = create_buffer_with_options() local actual_buf = create_buffer_with_options()
@ -418,7 +422,7 @@ local function toggle_run_panel(is_debug)
refresh_run_panel() refresh_run_panel()
end end
local function setup_keybindings_for_buffer(buf) setup_keybindings_for_buffer = function(buf)
vim.keymap.set('n', 'q', function() vim.keymap.set('n', 'q', function()
toggle_run_panel() toggle_run_panel()
end, { buffer = buf, silent = true }) end, { buffer = buf, silent = true })