refactor(diff): Improve api with lua types and more flexibility

This commit is contained in:
NicolasGB
2025-10-31 14:50:43 +01:00
parent f0915d415d
commit a33cbba40f
2 changed files with 36 additions and 18 deletions
+22 -12
View File
@@ -975,18 +975,28 @@ function M.register_command()
desc = "Execute jj commands with subcommand support",
})
vim.api.nvim_create_user_command("Jdiff", diff.open_vdiff, {
nargs = "?",
desc = "Diff against jj revision",
})
vim.api.nvim_create_user_command("Jhdiff", diff.open_hdiff, {
nargs = "?",
desc = "Horizontal diff against jj revision",
})
vim.api.nvim_create_user_command("Jvdiff", diff.open_vdiff, {
nargs = "?",
desc = "Vertical diff against jj revision",
})
-- Unified creation of jj diff commands with optional revision argument
local function create_diff_command(name, fn, desc)
vim.api.nvim_create_user_command(name, function(opts)
local rev = opts.fargs[1]
if rev then
fn({ rev = rev })
else
fn()
end
end, {
nargs = "?",
desc = desc .. " (optionally pass jj revision)",
})
end
-- Commands:
-- Jdiff : vertical diff by default
-- Jhdiff : horizontal diff
-- Jvdiff : vertical diff (explicit)
create_diff_command("Jdiff", diff.open_vdiff, "Vertical diff against jj revision")
create_diff_command("Jhdiff", diff.open_hdiff, "Horizontal diff against jj revision")
create_diff_command("Jvdiff", diff.open_vdiff, "Vertical diff against jj revision")
end
return M