From b9edb83c52a0f0ebe34cbff72f0e338a4175a25a Mon Sep 17 00:00:00 2001 From: themodrnhakr Date: Thu, 2 Oct 2025 16:32:07 -0500 Subject: [PATCH] Fix module loading issues and improve config handling --- README.md | 2 +- lua/jj_mini_diff/init.lua | 26 +++++++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1c580f6..74b583f 100644 --- a/README.md +++ b/README.md @@ -67,4 +67,4 @@ require("jj_mini_diff").setup({ * `add`: For added lines. * `change`: For changed lines. * `delete`: For deleted lines. -* **`autocmd_events`**: A list of Neovim autocommand events that will trigger a sign refresh. \ No newline at end of file +* **`autocmd_events`**: A list of Neovim autocommand events that will trigger a sign refresh. diff --git a/lua/jj_mini_diff/init.lua b/lua/jj_mini_diff/init.lua index fd61f5a..21db488 100644 --- a/lua/jj_mini_diff/init.lua +++ b/lua/jj_mini_diff/init.lua @@ -12,6 +12,18 @@ local config = { 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 local function _run_jj_command(args) local cmd = "jj " .. table.concat(args, " ") @@ -68,7 +80,7 @@ local function _parse_diff_output(diff_output) elseif line:match("^[ ]") then current_line_num = current_line_num + 1 prev_line_was_deleted = false - elseif line:match("^[+]") then + elseif line:match("^[+]") then -- Simplified regex current_line_num = current_line_num + 1 if prev_line_was_deleted then table.insert(changed_lines, current_line_num) @@ -76,8 +88,8 @@ local function _parse_diff_output(diff_output) table.insert(added_lines, current_line_num) end prev_line_was_deleted = false - elseif line:match("^[-]") then - -- For deleted lines, we mark the line *before* the deletion as changed, + elseif line:match("^[-]") then -- Simplified regex + -- For deleted lines, we mark the line *before* the deletion as changed, -- or if it's the first line, we can't mark it. -- This is a simplification for now. if current_line_num > 0 then @@ -140,11 +152,11 @@ function M.refresh_signs() end function M.setup(opts) - opts = opts or {} - _define_signs() -- Call to define signs + config = _deep_merge(config, opts or {}) -- Use custom deep merge + _define_signs() -- Call to define signs AFTER config merge -- 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 }), callback = function() if _is_jj_repo() then @@ -154,4 +166,4 @@ function M.setup(opts) }) end -return M +return M \ No newline at end of file