From fa8c663f5ed0ef93bfc3ccbf042e05fd7da46f0c Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Fri, 19 Sep 2025 14:01:17 -0400 Subject: [PATCH] fix(ci): selene erorrs --- lua/cp/diff.lua | 14 +++++--------- lua/cp/highlight.lua | 13 ++----------- lua/cp/init.lua | 1 - 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/lua/cp/diff.lua b/lua/cp/diff.lua index c665b78..07ea6d2 100644 --- a/lua/cp/diff.lua +++ b/lua/cp/diff.lua @@ -4,7 +4,7 @@ ---@class DiffBackend ---@field name string ----@field render fun(expected: string, actual: string, mode: string?): DiffResult +---@field render fun(expected: string, actual: string): DiffResult local M = {} @@ -12,9 +12,7 @@ local M = {} ---@type DiffBackend local vim_backend = { name = 'vim', - render = function(expected, actual, mode) - -- For vim backend, we return the content as-is since diffthis handles highlighting - local expected_lines = vim.split(expected, '\n', { plain = true, trimempty = true }) + render = function(_, actual) local actual_lines = vim.split(actual, '\n', { plain = true, trimempty = true }) return { @@ -28,7 +26,7 @@ local vim_backend = { ---@type DiffBackend local git_backend = { name = 'git', - render = function(expected, actual, mode) + render = function(expected, actual) -- Create temporary files for git diff local tmp_expected = vim.fn.tempname() local tmp_actual = vim.fn.tempname() @@ -59,7 +57,6 @@ local git_backend = { highlights = {}, } else - local highlight_module = require('cp.highlight') return { content = {}, highlights = {}, @@ -114,11 +111,10 @@ end ---@param expected string ---@param actual string ---@param backend_name? string ----@param mode? string ---@return DiffResult -function M.render_diff(expected, actual, backend_name, mode) +function M.render_diff(expected, actual, backend_name) local backend = M.get_best_backend(backend_name) - return backend.render(expected, actual, mode) + return backend.render(expected, actual) end return M diff --git a/lua/cp/highlight.lua b/lua/cp/highlight.lua index 3145a15..6695d6e 100644 --- a/lua/cp/highlight.lua +++ b/lua/cp/highlight.lua @@ -14,7 +14,6 @@ local M = {} ---@param text string Raw git diff output line ---@return string cleaned_text, DiffHighlight[] local function parse_diff_line(text) - local highlights = {} local cleaned_text = text local offset = 0 @@ -22,12 +21,7 @@ local function parse_diff_line(text) for removed_text in text:gmatch('%[%-(.-)%-%]') do local start_pos = text:find('%[%-' .. vim.pesc(removed_text) .. '%-%]', 1, false) if start_pos then - -- Remove the marker and adjust positions - local marker_len = #'[-%-%]' + #removed_text 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 - -- This is handled by showing removed content in the expected pane end end @@ -52,9 +46,8 @@ local function parse_diff_line(text) }) -- Remove the marker - local marker_len = #{ '{+' } + #{ '+}' } + #added_text final_text = final_text:gsub('{%+' .. vim.pesc(added_text) .. '%+}', added_text, 1) - offset = offset + #{ '{+' } + #{ '+}' } + offset = offset + 4 -- Length of {+ and +} end end @@ -99,9 +92,7 @@ function M.parse_git_diff(diff_output) highlight.line = line_num - 1 -- 0-based for extmarks table.insert(all_highlights, highlight) end - elseif line:match('^%-') then - -- Removed line - we handle this in the expected pane, skip for actual - elseif not line:match('^\\') then -- Skip "\ No newline" messages + elseif not line:match('^%-') and not line:match('^\\') then -- Skip removed lines and "\ No newline" messages -- Unchanged line local parsed_line, line_highlights = parse_diff_line(line) table.insert(content_lines, parsed_line) diff --git a/lua/cp/init.lua b/lua/cp/init.lua index 0792b37..50e7c25 100644 --- a/lua/cp/init.lua +++ b/lua/cp/init.lua @@ -192,7 +192,6 @@ local function toggle_test_panel(is_debug) local actual_buf = vim.api.nvim_create_buf(false, true) -- Set buffer options - local buffer_opts = { 'bufhidden', 'wipe' } 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('readonly', true, { buf = buf })