Fix module loading issues and improve config handling
This commit is contained in:
parent
43a62d7e3f
commit
b9edb83c52
@ -12,6 +12,18 @@ local config = {
|
|||||||
autocmd_events = { "BufReadPost", "BufWritePost", "CursorHold" },
|
autocmd_events = { "BufReadPost", "BufWritePost", "CursorHold" },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- Helper function for deep merging tables
|
||||||
|
local function _deep_merge(target, source)
|
||||||
|
for k, v in pairs(source) do
|
||||||
|
if type(v) == "table" and type(target[k]) == "table" then
|
||||||
|
_deep_merge(target[k], v)
|
||||||
|
else
|
||||||
|
target[k] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return target
|
||||||
|
end
|
||||||
|
|
||||||
-- Helper function to run jj commands
|
-- Helper function to run jj commands
|
||||||
local function _run_jj_command(args)
|
local function _run_jj_command(args)
|
||||||
local cmd = "jj " .. table.concat(args, " ")
|
local cmd = "jj " .. table.concat(args, " ")
|
||||||
@ -68,7 +80,7 @@ local function _parse_diff_output(diff_output)
|
|||||||
elseif line:match("^[ ]") then
|
elseif line:match("^[ ]") then
|
||||||
current_line_num = current_line_num + 1
|
current_line_num = current_line_num + 1
|
||||||
prev_line_was_deleted = false
|
prev_line_was_deleted = false
|
||||||
elseif line:match("^[+]") then
|
elseif line:match("^[+]") then -- Simplified regex
|
||||||
current_line_num = current_line_num + 1
|
current_line_num = current_line_num + 1
|
||||||
if prev_line_was_deleted then
|
if prev_line_was_deleted then
|
||||||
table.insert(changed_lines, current_line_num)
|
table.insert(changed_lines, current_line_num)
|
||||||
@ -76,7 +88,7 @@ local function _parse_diff_output(diff_output)
|
|||||||
table.insert(added_lines, current_line_num)
|
table.insert(added_lines, current_line_num)
|
||||||
end
|
end
|
||||||
prev_line_was_deleted = false
|
prev_line_was_deleted = false
|
||||||
elseif line:match("^[-]") then
|
elseif line:match("^[-]") then -- Simplified regex
|
||||||
-- For deleted lines, we mark the line *before* the deletion as changed,
|
-- For deleted lines, we mark the line *before* the deletion as changed,
|
||||||
-- or if it's the first line, we can't mark it.
|
-- or if it's the first line, we can't mark it.
|
||||||
-- This is a simplification for now.
|
-- This is a simplification for now.
|
||||||
@ -140,11 +152,11 @@ function M.refresh_signs()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
opts = opts or {}
|
config = _deep_merge(config, opts or {}) -- Use custom deep merge
|
||||||
_define_signs() -- Call to define signs
|
_define_signs() -- Call to define signs AFTER config merge
|
||||||
|
|
||||||
-- Autocommands to update signs
|
-- Autocommands to update signs
|
||||||
vim.api.nvim_create_autocmd({ "BufReadPost", "BufWritePost", "CursorHold" }, {
|
vim.api.nvim_create_autocmd(config.autocmd_events, { -- Use configured events
|
||||||
group = vim.api.nvim_create_augroup("JjMiniDiff", { clear = true }),
|
group = vim.api.nvim_create_augroup("JjMiniDiff", { clear = true }),
|
||||||
callback = function()
|
callback = function()
|
||||||
if _is_jj_repo() then
|
if _is_jj_repo() then
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user