From ab86df7274da5da29dcdab38d15f2b0848310076 Mon Sep 17 00:00:00 2001 From: Tyler Hallada Date: Tue, 11 Aug 2026 20:30:07 +0000 Subject: [PATCH] Swap DiffView with CodeDiff CodeDiff is supposed to be the successor to DiffView. It also has file watching built-in so I can drop the custom `directory-watcher.lua`. --- lazy-lock.json | 44 +++++++-------- lua/custom/directory-watcher.lua | 96 -------------------------------- lua/plugins/codediff.lua | 39 +++++++++++++ lua/plugins/diffview.lua | 72 ------------------------ 4 files changed, 61 insertions(+), 190 deletions(-) delete mode 100644 lua/custom/directory-watcher.lua create mode 100644 lua/plugins/codediff.lua delete mode 100644 lua/plugins/diffview.lua diff --git a/lazy-lock.json b/lazy-lock.json index 4a684ee..61ea3b0 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,29 +1,29 @@ { "LazyVim": { "branch": "main", "commit": "c10948c50b18fae7f256433afdef09e432410480" }, - "SchemaStore.nvim": { "branch": "main", "commit": "19e40cef03a380bfb578793a08222826118664dd" }, + "SchemaStore.nvim": { "branch": "main", "commit": "c8170f9628265f5a01510182703bab9125ef15d8" }, "blink-copilot": { "branch": "main", "commit": "7ad8209b2f880a2840c94cdcd80ab4dc511d4f39" }, "blink-emoji.nvim": { "branch": "master", "commit": "dff709139ad5389fb55ebab026e75278a12b325a" }, "blink.cmp": { "branch": "main", "commit": "78336bc89ee5365633bcf754d93df01678b5c08f" }, "bufferline.nvim": { "branch": "main", "commit": "655133c3b4c3e5e05ec549b9f8cc2894ac6f51b3" }, - "catppuccin": { "branch": "main", "commit": "79e2049a0fdf7ec840f8463fe1d962c94493196b" }, + "catppuccin": { "branch": "main", "commit": "edefef779ab08ce1a4a404713e3012b0d202bd35" }, "clangd_extensions.nvim": { "branch": "main", "commit": "78c2ecd659d54972be17aa6ba2deac3c53223b80" }, "cmake-tools.nvim": { "branch": "master", "commit": "22859d754b5de738cfe9945e0910729f63deefd0" }, - "codesnap.nvim": { "branch": "main", "commit": "21b7561c95cc452c65ddf2fc4dfeb280f8471d45" }, - "conform.nvim": { "branch": "master", "commit": "619363c30309d29ffa631e67c8183f2a72caa373" }, - "copilot.lua": { "branch": "master", "commit": "eac6eff78e4a864daa0a5ef431d5c729e7d18a50" }, - "cord.nvim": { "branch": "master", "commit": "8f081613c1314a0d6f38839c2788216621efb4d9" }, + "codediff.nvim": { "branch": "main", "commit": "e08a35a56a52c290398ebfaec33c34cfcf2d0f3c" }, + "codesnap.nvim": { "branch": "main", "commit": "e916bdcb4112bda11028ed8ec2dbff730e4248a4" }, + "conform.nvim": { "branch": "master", "commit": "016802de402556da54c36bd7359b441266b01cdd" }, + "copilot.lua": { "branch": "master", "commit": "7e6723aabea044519462958ffcea68d7985c5ed0" }, + "cord.nvim": { "branch": "master", "commit": "012dcf6d0507e1525a682b46d6de2188fd68980c" }, "crates.nvim": { "branch": "main", "commit": "694357861ec9ebf12475ddcdd04ea45a0923c32d" }, "darkearth-nvim": { "branch": "main", "commit": "d894924296162bfb50c6ab753c30c479c100f0e6" }, "dial.nvim": { "branch": "master", "commit": "f2634758455cfa52a8acea6f142dcd6271a1bf57" }, - "diffview.nvim": { "branch": "main", "commit": "4516612fe98ff56ae0415a259ff6361a89419b0a" }, "dressing.nvim": { "branch": "master", "commit": "2d7c2db2507fa3c4956142ee607431ddb2828639" }, "eyeliner.nvim": { "branch": "main", "commit": "8f197eb30cecdf4c2cc9988a5eecc6bc34c0c7d6" }, "farout.nvim": { "branch": "main", "commit": "ebfcb874c3ebdb86fff8f22de4ae0944c3fa2bbc" }, "flash.nvim": { "branch": "main", "commit": "b6346946d10d07998efee029fb0f7a593806d0cd" }, "friendly-snippets": { "branch": "main", "commit": "6cd7280adead7f586db6fccbd15d2cac7e2188b9" }, - "fzf": { "branch": "master", "commit": "e36576429dbdcb447b05b999f266e1c2913b543b" }, + "fzf": { "branch": "master", "commit": "ca4c1b80e330522df9d768ed3139154721c6d14b" }, "gh.nvim": { "branch": "main", "commit": "6f367b2ab8f9d4a0a23df2b703a3f91137618387" }, - "gitsigns.nvim": { "branch": "main", "commit": "31d6fb2d618bca1482b9f274751ead5f03461408" }, + "gitsigns.nvim": { "branch": "main", "commit": "5be654f2232c10ddcad19c1607a67b6b4b78fc29" }, "goto-preview": { "branch": "main", "commit": "d2d6923c9b9e0e43f0b9b566f261a8b1ae016540" }, "grug-far.nvim": { "branch": "main", "commit": "6e05398cf6cad05b3fb46569db96b1ccfcbbd402" }, "gruvbox.nvim": { "branch": "main", "commit": "154eb5ff5b96d0641307113fa385eaf0d36d9796" }, @@ -32,7 +32,7 @@ "inc-rename.nvim": { "branch": "main", "commit": "ddff8bd3eccedf043bd73f5bf89cf90d2d6d8105" }, "kanagawa.nvim": { "branch": "master", "commit": "bb85e4bfc8d89b0e62c8fa53ccdd13d12e2f77b3" }, "key-analyzer.nvim": { "branch": "main", "commit": "4e4bef34498e821bcbd5203f44db8b67e4f10e04" }, - "kulala.nvim": { "branch": "main", "commit": "e4e8615dc07d9423f3dd52ad5af962db09d26a52" }, + "kulala.nvim": { "branch": "main", "commit": "81cbb767749bfe23666e8ff099306044a2743012" }, "lazy.nvim": { "branch": "main", "commit": "85c7ff3711b730b4030d03144f6db6375044ae82" }, "lazydev.nvim": { "branch": "main", "commit": "ff2cbcba459b637ec3fd165a2be59b7bbaeedf0d" }, "linear-nvim": { "branch": "master", "commit": "3832e5146f52e7b2663fec312588dbf91edfcf8b" }, @@ -45,14 +45,14 @@ "mason.nvim": { "branch": "main", "commit": "2a6940af80375532e5e9e7c1f2fc6319a1b7a69d" }, "miasma.nvim": { "branch": "main", "commit": "627f2e1cac91de0d1d4dd7472b506a30f41b2b7d" }, "mini.ai": { "branch": "main", "commit": "25248c6aa002391936a6200f12d1466015987133" }, - "mini.files": { "branch": "main", "commit": "f6d1367483b6c0695b5084c04f7cd83bf2353a3e" }, + "mini.files": { "branch": "main", "commit": "a249438d15fa6f64085ba83a9d1794d726aaf5ad" }, "mini.hipatterns": { "branch": "main", "commit": "7c840c71d6a91f53d734cab2b6fe2290d285ec3b" }, "mini.icons": { "branch": "main", "commit": "98faae31e9be1cc054ae63485e58ceb185efcad0" }, "mini.pairs": { "branch": "main", "commit": "b1c5a726921b7a8c9321e9a7a208aa0571de5810" }, "mini.surround": { "branch": "main", "commit": "8d5d0c5aa92449368ac251e85451d79d8f69d296" }, "moonbow.nvim": { "branch": "master", "commit": "baf62d035785910c5a368cbde5872190a56afb30" }, - "neo-tree.nvim": { "branch": "main", "commit": "2b9e60152b606152467441b0a74879f41707fd96" }, - "neoconf.nvim": { "branch": "main", "commit": "413ca3ee8f59d8e9d89f5cfca06ee8746ae237a8" }, + "neo-tree.nvim": { "branch": "main", "commit": "6679b9395526b52ddb2b137fcd5255dab71c5a58" }, + "neoconf.nvim": { "branch": "main", "commit": "b75d3026a98b46d3de15fc137c502f4ef0c643a6" }, "neogen": { "branch": "main", "commit": "23e7e9f883d01289ebd90e98025acc860ea26366" }, "neotest": { "branch": "master", "commit": "1c529a1ef9c82e8131e872368415cecc2bb86ea2" }, "neotest-mocha": { "branch": "main", "commit": "e28317a93e48ed7901d8ddb1bd252b64220b2e2c" }, @@ -62,7 +62,7 @@ "nightfox.nvim": { "branch": "main", "commit": "4dacd3f0185a2227bdf3b6c0975a8f0bf87cac9a" }, "noice.nvim": { "branch": "main", "commit": "7bfd942445fb63089b59f97ca487d605e715f155" }, "nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" }, - "numb.nvim": { "branch": "master", "commit": "167fbbb8de5529eac4f66ef054c260636cd9af51" }, + "numb.nvim": { "branch": "master", "commit": "36260c446465b1303b0b1922c722904791bdb03f" }, "nvim-bqf": { "branch": "main", "commit": "c282a62bec6c0621a1ef5132aa3f4c9fc4dcc2c7" }, "nvim-dap": { "branch": "master", "commit": "9e848e09a697ee95302a3ef2dd43fd6eb709e570" }, "nvim-dap-python": { "branch": "master", "commit": "1808458eba2b18f178f990e01376941a42c7f93b" }, @@ -71,10 +71,10 @@ "nvim-dap-virtual-text": { "branch": "master", "commit": "fbdb48c2ed45f4a8293d0d483f7730d24467ccb6" }, "nvim-jdtls": { "branch": "master", "commit": "6e9d953f0b82bccdb834cfde0e893f3119c22592" }, "nvim-lint": { "branch": "master", "commit": "a219b2c9e5b4765e5c845aba119dad55806fcaf1" }, - "nvim-lspconfig": { "branch": "master", "commit": "9ae2b3b63b924b1329724dae76e9d2c5c40b389c" }, + "nvim-lspconfig": { "branch": "master", "commit": "4267d26e60323a45e18f8e7a63a964cc8f53ca4e" }, "nvim-nio": { "branch": "master", "commit": "edcc181a875301dd21840189aa2f2f9ad69fc172" }, - "nvim-treesitter": { "branch": "main", "commit": "0f32dff7f19476629c77467f887b95e5e2d33509" }, - "nvim-treesitter-context": { "branch": "master", "commit": "b311b30818951d01f7b4bf650521b868b3fece16" }, + "nvim-treesitter": { "branch": "main", "commit": "c9f9ed6c1892f629ea399f4ee7905f2686fa13f2" }, + "nvim-treesitter-context": { "branch": "master", "commit": "f3061339b8eaf9fda873600bc425b8d2d8502533" }, "nvim-treesitter-textobjects": { "branch": "main", "commit": "898ee307df58f854d11cd7edd06472574d48014e" }, "nvim-ts-autotag": { "branch": "main", "commit": "88c1453db4ba7dd24131086fe51fdf74e587d275" }, "nvim-web-devicons": { "branch": "master", "commit": "2ae6958df7ced50baac5035cec0c15799eedfbf7" }, @@ -82,14 +82,14 @@ "octo.nvim": { "branch": "master", "commit": "205f024d3ea4a3d81aac751b6bf8e2d01e0c204f" }, "oil.nvim": { "branch": "master", "commit": "b73018b75affd13fa38e2fc94ef753b465f770d7" }, "overseer.nvim": { "branch": "master", "commit": "a93d9f6d6defdac4bcd6d2c8ba988650e42e0a0e" }, - "oxocarbon.nvim": { "branch": "main", "commit": "488dca6e3ff01acd88a648b83244073037261e64" }, + "oxocarbon.nvim": { "branch": "main", "commit": "7cc379b96fcbb4e75c5152906e0fccf81ce46590" }, "persistence.nvim": { "branch": "main", "commit": "b20b2a7887bd39c1a356980b45e03250f3dce49c" }, "plenary.nvim": { "branch": "master", "commit": "74b06c6c75e4eeb3108ec01852001636d85a932b" }, "project.nvim": { "branch": "main", "commit": "8c6bad7d22eef1b71144b401c9f74ed01526a4fb" }, - "render-markdown.nvim": { "branch": "main", "commit": "f422cb5c6855f150e2ddcfaf44e7157b98b34f6a" }, + "render-markdown.nvim": { "branch": "main", "commit": "4663eb3ecd538bd5062628fb6d95bbe6bdca78f6" }, "rustaceanvim": { "branch": "master", "commit": "f2f0c1231a5b019dbc1fd6dafac1751c878925a3" }, "sidekick.nvim": { "branch": "main", "commit": "208e1c5b8170c01fd1d07df0139322a76479b235" }, - "smart-splits.nvim": { "branch": "master", "commit": "32f67888ac71942442fdab3819864a10449dfc41" }, + "smart-splits.nvim": { "branch": "master", "commit": "0fe3bbd99d48458ad188c4c262c31049fa9b018c" }, "smartcolumn.nvim": { "branch": "main", "commit": "5351ae24e992a397d2abac48b7774dc8ef0acf40" }, "snacks.nvim": { "branch": "main", "commit": "882c996cf28183f4d63640de0b4c02ec886d01f2" }, "ssr.nvim": { "branch": "main", "commit": "7839acf6f940dc1c9210823a7c8b378df122765b" }, @@ -113,8 +113,8 @@ "vim-sleuth": { "branch": "master", "commit": "be69bff86754b1aa5adcbb527d7fcd1635a84080" }, "vim-startuptime": { "branch": "master", "commit": "5f33e50f1e2e2a80370c9094e4c303ea54cd2aea" }, "vim-unimpaired": { "branch": "master", "commit": "db65482581a28e4ccf355be297f1864a4e66985c" }, - "vimtex": { "branch": "master", "commit": "853eb587873a7061a083655578be56dd8027b834" }, - "wezterm-types": { "branch": "main", "commit": "ad5d3319a9b3358a7953db34677a554a4268ae58" }, + "vimtex": { "branch": "master", "commit": "a5568d902cc20a76bb8ef70743f0157ec2e79ded" }, + "wezterm-types": { "branch": "main", "commit": "851470ad5d2dfb56bda936e6aeef2f3a45e7f199" }, "which-key.nvim": { "branch": "main", "commit": "3aab2147e74890957785941f0c1ad87d0a44c15a" }, "yank-path.nvim": { "branch": "main", "commit": "e660248de1e4c91a760f510fc165c172a19cc1d5" }, "yanky.nvim": { "branch": "main", "commit": "dd6689fdda85f66cab7d9b1a1664625f3be0920d" }, diff --git a/lua/custom/directory-watcher.lua b/lua/custom/directory-watcher.lua deleted file mode 100644 index fe281a3..0000000 --- a/lua/custom/directory-watcher.lua +++ /dev/null @@ -1,96 +0,0 @@ --- Custom directory watcher using Neovim's built-in libuv bindings --- Source: https://github.com/richardgill/nix/blob/ebdd8260f770d242db7b6163158cfe9ad9784c41/modules/home-manager/dot-files/nvim/lua/custom/directory-watcher.lua - -local M = {} - -local uv = vim.uv -local watcher = nil -local debounce_timer = nil -local on_change_handlers = {} - --- Debounce helper to prevent callback storms -local debounce = function(fn, delay) - return function(...) - local args = { ... } - if debounce_timer then - debounce_timer:close() - end - debounce_timer = vim.defer_fn(function() - debounce_timer = nil - fn(unpack(args)) - end, delay) - end -end - --- Register a named handler to be called when files change --- If a handler with the same name exists, it will be replaced --- Note: Named handlers are required to support Lua hotreload - when a file is reloaded, --- it re-registers its handler with the same name, replacing the old one instead of --- creating duplicates -M.registerOnChangeHandler = function(name, handler) - on_change_handlers[name] = handler -end - --- Start watching a directory for file changes -M.setup = function(opts) - opts = opts or {} - local path = opts.path - local debounce_delay = opts.debounce or 100 -- ms - - if not path then - return false - end - - -- Stop existing watcher if any - if watcher then - M.stop() - end - - -- Create fs_event handle - local fs_event = uv.new_fs_event() - if not fs_event then - return false - end - - -- Debounced callback for file changes - local on_change = debounce(function(err, filename, events) - if err then - M.stop() - return - end - - if filename then - local full_path = path .. "/" .. filename - - -- Call all registered handlers - for _, handler in pairs(on_change_handlers) do - pcall(handler, full_path, events) - end - end - end, debounce_delay) - - -- Start watching (wrapped for thread safety) - local ok, err = fs_event:start(path, { recursive = false }, vim.schedule_wrap(on_change)) - - if ok ~= 0 then - return false - end - - watcher = fs_event - return true -end - --- Stop the watcher and clean up resources -M.stop = function() - if watcher then - watcher:stop() - watcher = nil - end - - if debounce_timer then - debounce_timer:close() - debounce_timer = nil - end -end - -return M diff --git a/lua/plugins/codediff.lua b/lua/plugins/codediff.lua new file mode 100644 index 0000000..e8bf909 --- /dev/null +++ b/lua/plugins/codediff.lua @@ -0,0 +1,39 @@ +-- VSCode-style diff viewer, replaces sindrets/diffview.nvim. +-- The C diff library is downloaded automatically on first use (:CodeDiff install to force). + +return { + "esmuellert/codediff.nvim", + cmd = "CodeDiff", + opts = { + diff = { + layout = "side-by-side", + }, + explorer = { + -- Match diffview's file panel: tree listing with +/- line stats + view_mode = "tree", + line_stats = { + enabled = true, + }, + }, + keymaps = { + view = { + -- gq closed every diffview panel, keep it alongside the default q + quit = { "q", "gq" }, + -- Default b shadows LazyVim's +buffer group, e/E mirrors + -- LazyVim's explorer mnemonic instead + toggle_explorer = "E", + focus_explorer = "e", + -- Defaults t and gc shadow the t{char} motion and the gc comment + -- operator in the (editable) modified buffer + toggle_layout = "gl", + toggle_compact = "gz", + }, + }, + }, + keys = { + { "gv", "CodeDiff", desc = "Open [g]it Diff[v]iew tab" }, + { "gl", "CodeDiff history %", desc = "Toggle git log of current file history" }, + { "gl", ":'<,'>CodeDiff history", mode = "v", desc = "Toggle git log of selected lines" }, + { "gL", "CodeDiff history", desc = "Toggle git log of current branch" }, + }, +} diff --git a/lua/plugins/diffview.lua b/lua/plugins/diffview.lua deleted file mode 100644 index 17b77c7..0000000 --- a/lua/plugins/diffview.lua +++ /dev/null @@ -1,72 +0,0 @@ --- Custom Diffview auto-refresh config from https://richardgill.org/blog/configuring-neovim-coding-agents --- Source: https://github.com/richardgill/nix/blob/ebdd8260f770d242db7b6163158cfe9ad9784c41/modules/home-manager/dot-files/nvim/lua/plugins/git-diff_diffview.lua - -return { - "sindrets/diffview.nvim", - cmd = { "DiffviewOpen", "DiffviewClose", "DiffviewToggleFiles", "DiffviewFocusFiles" }, - opts = { - enhanced_diff_hl = true, - keymaps = { - view = { - { "n", "gq", "DiffviewClose", { desc = "Close diffview" } }, - }, - file_panel = { - { "n", "gq", "DiffviewClose", { desc = "Close diffview" } }, - }, - file_history_panel = { - { "n", "gq", "DiffviewClose", { desc = "Close diffview" } }, - }, - }, - }, - keys = { - { "gl", ":'<,'>DiffviewFileHistory", mode = "v", desc = "Toggle git log of selected lines" }, - { "gL", "DiffviewFileHistory", desc = "Toggle git log of current branch" }, - { "gl", "DiffviewFileHistory %", desc = "Toggle git log of current file history" }, - { "gv", "DiffviewOpen", desc = "Open [g]it Diff[v]iew tab" }, - }, - config = function(_, opts) - require("diffview").setup(opts) - - local watcher = require("custom.directory-watcher") - - local is_git_ignored = function(filepath) - vim.fn.system("git check-ignore -q " .. vim.fn.shellescape(filepath)) - return vim.v.shell_error == 0 - end - - local update_left_pane = function() - pcall(function() - local lib = require("diffview.lib") - local view = lib.get_current_view() - if view then - view:update_files() - end - end) - end - - -- Register handler for file changes in watched directory - watcher.registerOnChangeHandler("diffview", function(filepath, events) - local is_in_dot_git_dir = filepath:match("/%.git/") or filepath:match("^%.git/") - - if is_in_dot_git_dir or not is_git_ignored(filepath) then - vim.notify("[diffview] File changed: " .. vim.fn.fnamemodify(filepath, ":t"), vim.log.levels.INFO) - update_left_pane() - end - end) - - -- Start watching the current working directory - watcher.setup({ path = vim.fn.getcwd() }) - - vim.api.nvim_create_autocmd("FocusGained", { - callback = update_left_pane, - }) - - vim.api.nvim_create_autocmd("User", { - pattern = "DiffviewViewLeave", - callback = function() - watcher.stop() - vim.cmd(":DiffviewClose") - end, - }) - end, -}