diff --git a/lazy-lock.json b/lazy-lock.json index 01f0cf06..0a9aac1c 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -18,6 +18,7 @@ "nvim-web-devicons": { "branch": "master", "commit": "803353450c374192393f5387b6a0176d0972b848" }, "oil.nvim": { "branch": "master", "commit": "f55b25e493a7df76371cfadd0ded5004cb9cd48a" }, "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, + "snacks.nvim": { "branch": "main", "commit": "fe7cfe9800a182274d0f868a74b7263b8c0c020b" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "6fea601bd2b694c6f2ae08a6c6fab14930c60e2c" }, "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" }, "telescope.nvim": { "branch": "master", "commit": "0d8b6eaa0b5ae6bb3d9785f7a3ba4a4c6c1b1af2" }, diff --git a/lua/custom/plugins/lazygit.lua b/lua/custom/plugins/lazygit.lua index 5c77df03..eb385990 100644 --- a/lua/custom/plugins/lazygit.lua +++ b/lua/custom/plugins/lazygit.lua @@ -15,6 +15,6 @@ return { -- setting the keybinding for LazyGit with 'keys' is recommended in -- order to load the plugin when the command is run for the first time keys = { - { "lg", "LazyGit", desc = "LazyGit" } + { "gl", "LazyGit", desc = "LazyGit" } } } diff --git a/lua/custom/plugins/snack.lua b/lua/custom/plugins/snack.lua new file mode 100644 index 00000000..4368e6e6 --- /dev/null +++ b/lua/custom/plugins/snack.lua @@ -0,0 +1,116 @@ +local function open_pr_diff(picker, item, action) + -- Get the current item if not provided + item = item or picker:current() + if not item then + return + end + + -- Get the gh_item if available (for gh_pr picker) + local gh_item = item.gh_item or item + if not gh_item.baseRefName or not gh_item.headRefName then + Snacks.notify.error 'PR diff: Missing branch information' + return + end + + picker:close() + + local base_ref = gh_item.baseRefName + local head_ref = gh_item.headRefName + local pr_number = gh_item.number + + -- Fetch the PR head branch using gh (this ensures the branch is available) + if pr_number then + -- Use gh to fetch the PR branch - this handles remote branches correctly + vim.fn.system('gh pr checkout ' .. pr_number .. ' --detach --force 2>&1') + end + + -- Fetch both branches from origin to ensure they're available + vim.fn.system('git fetch origin ' .. base_ref .. ' 2>&1') + vim.fn.system('git fetch origin ' .. head_ref .. ' 2>&1') + + -- Use origin/ prefix for remote branches in DiffviewOpen + -- This ensures we reference the remote branches correctly + local diff_cmd = string.format('DiffviewOpen origin/%s...origin/%s', base_ref, head_ref) + vim.cmd(diff_cmd) +end + +return { + 'folke/snacks.nvim', + priority = 1000, + lazy = false, + ---@type snacks.Config + opts = { + -- your configuration comes here + -- or leave it empty to use the default settings + -- refer to the configuration section below + bigfile = { enabled = true }, + dashboard = { enabled = true }, + explorer = { + enabled = true, + show_hidden = true, + }, + indent = { enabled = true }, + input = { enabled = true }, + picker = { + enabled = true, + sources = { + explorer = { + hidden = true, -- Show hidden files by default + ignored = false, -- Optional: show git-ignored files by default + }, + gh_pr = { + actions = { + side_by_side = { + desc = 'Open PR diff side-by-side', + action = open_pr_diff, + }, + }, + win = { + input = { + keys = { + -- in PR picker: Open side-by-side diff in DiffviewOpen + [''] = { 'side_by_side', mode = { 'n', 'i' }, desc = 'Open PR diff side-by-side' }, + }, + }, + }, + }, + }, + }, + notifier = { enabled = true }, + quickfile = { enabled = true }, + scope = { enabled = true }, + scroll = { enabled = false }, + statuscolumn = { enabled = true }, + words = { enabled = true }, + }, + keys = { + { + 'gi', + function() + Snacks.picker.gh_issue() + end, + desc = 'GitHub Issues (open)', + }, + { + 'gI', + function() + Snacks.picker.gh_issue { state = 'all' } + end, + desc = 'GitHub Issues (all)', + }, + { + 'gp', + function() + Snacks.picker.gh_pr() + end, + desc = 'GitHub Pull Requests (open) - Press in picker for side-by-side diff', + }, + { + 'gP', + function() + Snacks.picker.gh_pr { state = 'all' } + end, + desc = 'GitHub Pull Requests (all) - Press in picker for side-by-side diff', + }, + }, +}