fix(ci): selene erorrs
This commit is contained in:
parent
526c82cac0
commit
fa8c663f5e
3 changed files with 7 additions and 21 deletions
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
---@class DiffBackend
|
---@class DiffBackend
|
||||||
---@field name string
|
---@field name string
|
||||||
---@field render fun(expected: string, actual: string, mode: string?): DiffResult
|
---@field render fun(expected: string, actual: string): DiffResult
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
|
@ -12,9 +12,7 @@ local M = {}
|
||||||
---@type DiffBackend
|
---@type DiffBackend
|
||||||
local vim_backend = {
|
local vim_backend = {
|
||||||
name = 'vim',
|
name = 'vim',
|
||||||
render = function(expected, actual, mode)
|
render = function(_, actual)
|
||||||
-- For vim backend, we return the content as-is since diffthis handles highlighting
|
|
||||||
local expected_lines = vim.split(expected, '\n', { plain = true, trimempty = true })
|
|
||||||
local actual_lines = vim.split(actual, '\n', { plain = true, trimempty = true })
|
local actual_lines = vim.split(actual, '\n', { plain = true, trimempty = true })
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -28,7 +26,7 @@ local vim_backend = {
|
||||||
---@type DiffBackend
|
---@type DiffBackend
|
||||||
local git_backend = {
|
local git_backend = {
|
||||||
name = 'git',
|
name = 'git',
|
||||||
render = function(expected, actual, mode)
|
render = function(expected, actual)
|
||||||
-- Create temporary files for git diff
|
-- Create temporary files for git diff
|
||||||
local tmp_expected = vim.fn.tempname()
|
local tmp_expected = vim.fn.tempname()
|
||||||
local tmp_actual = vim.fn.tempname()
|
local tmp_actual = vim.fn.tempname()
|
||||||
|
|
@ -59,7 +57,6 @@ local git_backend = {
|
||||||
highlights = {},
|
highlights = {},
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
local highlight_module = require('cp.highlight')
|
|
||||||
return {
|
return {
|
||||||
content = {},
|
content = {},
|
||||||
highlights = {},
|
highlights = {},
|
||||||
|
|
@ -114,11 +111,10 @@ end
|
||||||
---@param expected string
|
---@param expected string
|
||||||
---@param actual string
|
---@param actual string
|
||||||
---@param backend_name? string
|
---@param backend_name? string
|
||||||
---@param mode? string
|
|
||||||
---@return DiffResult
|
---@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)
|
local backend = M.get_best_backend(backend_name)
|
||||||
return backend.render(expected, actual, mode)
|
return backend.render(expected, actual)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ 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 highlights = {}
|
|
||||||
local cleaned_text = text
|
local cleaned_text = text
|
||||||
local offset = 0
|
local offset = 0
|
||||||
|
|
||||||
|
|
@ -22,12 +21,7 @@ local function parse_diff_line(text)
|
||||||
for removed_text in text:gmatch('%[%-(.-)%-%]') do
|
for removed_text in text:gmatch('%[%-(.-)%-%]') do
|
||||||
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
|
|
||||||
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
|
|
||||||
-- This is handled by showing removed content in the expected pane
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -52,9 +46,8 @@ local function parse_diff_line(text)
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Remove the marker
|
-- Remove the marker
|
||||||
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 + 4 -- Length of {+ and +}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -99,9 +92,7 @@ function M.parse_git_diff(diff_output)
|
||||||
highlight.line = line_num - 1 -- 0-based for extmarks
|
highlight.line = line_num - 1 -- 0-based for extmarks
|
||||||
table.insert(all_highlights, highlight)
|
table.insert(all_highlights, highlight)
|
||||||
end
|
end
|
||||||
elseif line:match('^%-') then
|
elseif not line:match('^%-') and not line:match('^\\') then -- Skip removed lines and "\ No newline" messages
|
||||||
-- Removed line - we handle this in the expected pane, skip for actual
|
|
||||||
elseif not line:match('^\\') then -- Skip "\ No newline" messages
|
|
||||||
-- Unchanged line
|
-- Unchanged line
|
||||||
local parsed_line, line_highlights = parse_diff_line(line)
|
local parsed_line, line_highlights = parse_diff_line(line)
|
||||||
table.insert(content_lines, parsed_line)
|
table.insert(content_lines, parsed_line)
|
||||||
|
|
|
||||||
|
|
@ -192,7 +192,6 @@ local function toggle_test_panel(is_debug)
|
||||||
local actual_buf = vim.api.nvim_create_buf(false, true)
|
local actual_buf = vim.api.nvim_create_buf(false, true)
|
||||||
|
|
||||||
-- Set buffer options
|
-- Set buffer options
|
||||||
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 })
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue