From 4dfb43a8f69fcef286db1b101ebd48b1ad3f54d8 Mon Sep 17 00:00:00 2001 From: Julien Vincent Date: Sat, 20 Jul 2024 15:37:28 -0600 Subject: [PATCH] Rename to hunk.nvim --- Justfile | 2 +- README.md | 24 ++++++++++----------- lua/difftool/api/init.lua | 7 ------ lua/difftool/ui/init.lua | 5 ----- lua/{difftool => hunk}/api/changeset.lua | 6 +++--- lua/{difftool => hunk}/api/diff.lua | 22 +------------------ lua/{difftool => hunk}/api/fs.lua | 0 lua/{difftool => hunk}/api/highlights.lua | 8 +++---- lua/hunk/api/init.lua | 7 ++++++ lua/{difftool => hunk}/api/signs.lua | 12 +++++------ lua/{difftool => hunk}/config.lua | 0 lua/{difftool => hunk}/init.lua | 8 +++---- lua/{difftool => hunk}/ui/file.lua | 6 +++--- lua/hunk/ui/init.lua | 5 +++++ lua/{difftool => hunk}/ui/layout.lua | 16 +++++++------- lua/{difftool => hunk}/ui/tree.lua | 9 +++----- lua/{difftool => hunk}/utils.lua | 0 plugin/difftool.vim | 4 ---- plugin/hunk.vim | 4 ++++ tests/{difftool => hunk}/changeset_spec.lua | 4 ++-- tests/{difftool => hunk}/diff_spec.lua | 2 +- tests/utils/fixtures.lua | 2 +- 22 files changed, 65 insertions(+), 88 deletions(-) delete mode 100644 lua/difftool/api/init.lua delete mode 100644 lua/difftool/ui/init.lua rename lua/{difftool => hunk}/api/changeset.lua (95%) rename lua/{difftool => hunk}/api/diff.lua (75%) rename lua/{difftool => hunk}/api/fs.lua (100%) rename lua/{difftool => hunk}/api/highlights.lua (68%) create mode 100644 lua/hunk/api/init.lua rename lua/{difftool => hunk}/api/signs.lua (66%) rename lua/{difftool => hunk}/config.lua (100%) rename lua/{difftool => hunk}/init.lua (96%) rename lua/{difftool => hunk}/ui/file.lua (94%) create mode 100644 lua/hunk/ui/init.lua rename lua/{difftool => hunk}/ui/layout.lua (77%) rename lua/{difftool => hunk}/ui/tree.lua (96%) rename lua/{difftool => hunk}/utils.lua (100%) delete mode 100644 plugin/difftool.vim create mode 100644 plugin/hunk.vim rename tests/{difftool => hunk}/changeset_spec.lua (95%) rename tests/{difftool => hunk}/diff_spec.lua (98%) diff --git a/Justfile b/Justfile index 6abd4b8..6d78d57 100644 --- a/Justfile +++ b/Justfile @@ -53,4 +53,4 @@ test channel="stable" file="": (prepare channel) --headless \ --noplugin \ -u tests/config.lua \ - -c "PlenaryBustedDirectory tests/difftool/{{ file }} { minimal_init='tests/config.lua', sequential=true }" + -c "PlenaryBustedDirectory tests/hunk/{{ file }} { minimal_init='tests/config.lua', sequential=true }" diff --git a/README.md b/README.md index 7e0dd39..8a3145f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@
-

difftool.nvim

+

hunk.nvim

@@ -11,18 +11,18 @@ --- This is a Neovim tool for splitting/editing diffs. It operates over a `left` and `right` directory, producing a diff of -the two which can subsiquently be inspected and modified. The `DiffEditor` allows selecting changes by file, hunk or +the two which can subsequently be inspected and modified. The `DiffEditor` allows selecting changes by file, hunk or individual line to produce a new partial diff. -This was primarilly built to be used with [jujutsu](https://github.com/martinvonz/jj) as an alternative diff-editor to -it's `:builtin` option, but it's designed generically enough that it can be used for other usecases. +This was primarily built to be used with [jujutsu](https://github.com/martinvonz/jj) as an alternative diff-editor to +it's `:builtin` option, but it's designed generically enough that it can be used for other use cases. To use it you need to give it two to three directories: a `left`, a `right`, and optionally and `output` directory. -These directories will then be read in by the diffeditor and used to produce a set of diffs between the two directories. -You will then be presented with the left and right side of each file and can select the lines from each diff hunk you -would like to keep. +These directories will then be read in by the diff editor and used to produce a set of diffs between the two +directories. You will then be presented with the left and right side of each file and can select the lines from each +diff hunk you would like to keep. -When you are happy with your selection you can accept changes and the diffeditor will modify the `output` directory (or +When you are happy with your selection you can accept changes and the diff editor will modify the `output` directory (or the `right` directory if no output is provided) to match your selection. ## Installation @@ -31,10 +31,10 @@ the `right` directory if no output is provided) to match your selection. ```lua { - "julienvincent/difftool.nvim", + "julienvincent/hunk.nvim", cmd = { "DiffEditor" }, config = function() - require("difftool").setup() + require("hunk").setup() end, dependencies = { { "MunifTanjim/nui.nvim" } @@ -45,8 +45,8 @@ the `right` directory if no output is provided) to match your selection. ## Configuration ```lua -local difftool = require("difftool") -difftool.setup({ +local hunk = require("hunk") +hunk.setup({ keys = { global = { quit = { "q" }, diff --git a/lua/difftool/api/init.lua b/lua/difftool/api/init.lua deleted file mode 100644 index 3394673..0000000 --- a/lua/difftool/api/init.lua +++ /dev/null @@ -1,7 +0,0 @@ -return { - diff = require("difftool.api.diff"), - changeset = require("difftool.api.changeset"), - fs = require("difftool.api.fs"), - signs = require("difftool.api.signs"), - highlights = require("difftool.api.highlights"), -} diff --git a/lua/difftool/ui/init.lua b/lua/difftool/ui/init.lua deleted file mode 100644 index ef654ba..0000000 --- a/lua/difftool/ui/init.lua +++ /dev/null @@ -1,5 +0,0 @@ -return { - layout = require("difftool.ui.layout"), - tree = require("difftool.ui.tree"), - file = require("difftool.ui.file"), -} diff --git a/lua/difftool/api/changeset.lua b/lua/hunk/api/changeset.lua similarity index 95% rename from lua/difftool/api/changeset.lua rename to lua/hunk/api/changeset.lua index 12f20c8..fd3686b 100644 --- a/lua/difftool/api/changeset.lua +++ b/lua/hunk/api/changeset.lua @@ -1,6 +1,6 @@ -local diff = require("difftool.api.diff") -local utils = require("difftool.utils") -local fs = require("difftool.api.fs") +local diff = require("hunk.api.diff") +local utils = require("hunk.utils") +local fs = require("hunk.api.fs") local M = {} diff --git a/lua/difftool/api/diff.lua b/lua/hunk/api/diff.lua similarity index 75% rename from lua/difftool/api/diff.lua rename to lua/hunk/api/diff.lua index 81873ef..96deee2 100644 --- a/lua/difftool/api/diff.lua +++ b/lua/hunk/api/diff.lua @@ -1,4 +1,4 @@ -local fs = require("difftool.api.fs") +local fs = require("hunk.api.fs") local M = {} @@ -71,24 +71,4 @@ function M.apply_diff(left, right, change) return result end --- local hunks = { --- { --- left = { 1, 4 }, --- right = { 1, 1 }, --- }, --- { --- left = { 6, 0 }, --- right = { 4, 3 }, --- }, --- } --- --- M.apply_diff({ "a", "b", "c", "f", "e", "f" }, { "a1", "e", "f", "g", "h", "i" }, hunks, { --- left = { [1] = true, [2] = true, [3] = true, [4] = true }, --- right = { [1] = true, [4] = true, [5] = true, [6] = true }, --- }) --- --- vim.diff("a\nb\nc\nf\ne\nf\n", "a1\ne\nf\ng\nh\ni\n", { --- result_type = "indices", --- }) - return M diff --git a/lua/difftool/api/fs.lua b/lua/hunk/api/fs.lua similarity index 100% rename from lua/difftool/api/fs.lua rename to lua/hunk/api/fs.lua diff --git a/lua/difftool/api/highlights.lua b/lua/hunk/api/highlights.lua similarity index 68% rename from lua/difftool/api/highlights.lua rename to lua/hunk/api/highlights.lua index c80a9fb..86f9466 100644 --- a/lua/difftool/api/highlights.lua +++ b/lua/hunk/api/highlights.lua @@ -12,17 +12,17 @@ function M.define_highlights() link = true, }) - vim.api.nvim_set_hl(0, "DiffToolDiffAddAsDelete", { + vim.api.nvim_set_hl(0, "HunkDiffAddAsDelete", { bg = string.format("#%06x", diff_delete_highlight.bg), }) - vim.api.nvim_set_hl(0, "DiffToolDiffDeleteDim", { + vim.api.nvim_set_hl(0, "HunkDiffDeleteDim", { default = true, link = "Comment", }) - vim.api.nvim_set_hl(0, "DiffToolDiffDelete", { - link = "DiffToolDiffDeleteDim", + vim.api.nvim_set_hl(0, "HunkDiffDelete", { + link = "HunkDiffDeleteDim", }) end diff --git a/lua/hunk/api/init.lua b/lua/hunk/api/init.lua new file mode 100644 index 0000000..dda7bba --- /dev/null +++ b/lua/hunk/api/init.lua @@ -0,0 +1,7 @@ +return { + diff = require("hunk.api.diff"), + changeset = require("hunk.api.changeset"), + fs = require("hunk.api.fs"), + signs = require("hunk.api.signs"), + highlights = require("hunk.api.highlights"), +} diff --git a/lua/difftool/api/signs.lua b/lua/hunk/api/signs.lua similarity index 66% rename from lua/difftool/api/signs.lua rename to lua/hunk/api/signs.lua index b868b3f..a5f0676 100644 --- a/lua/difftool/api/signs.lua +++ b/lua/hunk/api/signs.lua @@ -1,20 +1,20 @@ -local config = require("difftool.config") +local config = require("hunk.config") local M = { signs = { selected = { - name = "DiffToolLineSelected", - hl = "DiffToolSignSelected", + name = "HunkLineSelected", + hl = "HunkSignSelected", }, deselected = { - name = "DiffToolLineDeselected", - hl = "DiffToolSignDeselected", + name = "HunkLineDeselected", + hl = "HunkSignDeselected", }, }, } function M.place_sign(buf, sign, linenr) - vim.fn.sign_place(0, "DiffTool", sign.name, buf, { + vim.fn.sign_place(0, "Hunk", sign.name, buf, { lnum = linenr, priority = 100, }) diff --git a/lua/difftool/config.lua b/lua/hunk/config.lua similarity index 100% rename from lua/difftool/config.lua rename to lua/hunk/config.lua diff --git a/lua/difftool/init.lua b/lua/hunk/init.lua similarity index 96% rename from lua/difftool/init.lua rename to lua/hunk/init.lua index 2949ccc..7f7bb9e 100644 --- a/lua/difftool/init.lua +++ b/lua/hunk/init.lua @@ -1,7 +1,7 @@ -local config = require("difftool.config") -local utils = require("difftool.utils") -local api = require("difftool.api") -local ui = require("difftool.ui") +local config = require("hunk.config") +local utils = require("hunk.utils") +local api = require("hunk.api") +local ui = require("hunk.ui") local M = {} diff --git a/lua/difftool/ui/file.lua b/lua/hunk/ui/file.lua similarity index 94% rename from lua/difftool/ui/file.lua rename to lua/hunk/ui/file.lua index 193eb22..15da486 100644 --- a/lua/difftool/ui/file.lua +++ b/lua/hunk/ui/file.lua @@ -1,6 +1,6 @@ -local config = require("difftool.config") -local utils = require("difftool.utils") -local api = require("difftool.api") +local config = require("hunk.config") +local utils = require("hunk.utils") +local api = require("hunk.api") local M = {} diff --git a/lua/hunk/ui/init.lua b/lua/hunk/ui/init.lua new file mode 100644 index 0000000..a16c8d1 --- /dev/null +++ b/lua/hunk/ui/init.lua @@ -0,0 +1,5 @@ +return { + layout = require("hunk.ui.layout"), + tree = require("hunk.ui.tree"), + file = require("hunk.ui.file"), +} diff --git a/lua/difftool/ui/layout.lua b/lua/hunk/ui/layout.lua similarity index 77% rename from lua/difftool/ui/layout.lua rename to lua/hunk/ui/layout.lua index 7a5e0b7..4e3faf1 100644 --- a/lua/difftool/ui/layout.lua +++ b/lua/hunk/ui/layout.lua @@ -1,4 +1,4 @@ -local highlights = require("difftool.api.highlights") +local highlights = require("hunk.api.highlights") local M = {} @@ -28,17 +28,17 @@ function M.create_layout() local right_diff = create_vertical_split() highlights.set_win_hl(left_diff, { - "DiffAdd:DiffToolDiffAddAsDelete", - "DiffDelete:DiffToolDiffDeleteDim", + "DiffAdd:HunkDiffAddAsDelete", + "DiffDelete:HunkDiffDeleteDim", - "DiffToolSignSelected:Red", - "DiffToolSignDeselected:Red", + "HunkSignSelected:Red", + "HunkSignDeselected:Red", }) highlights.set_win_hl(right_diff, { - "DiffDelete:DiffToolDiffDeleteDim", - "DiffToolSignSelected:Green", - "DiffToolSignDeselected:Green", + "DiffDelete:HunkDiffDeleteDim", + "HunkSignSelected:Green", + "HunkSignDeselected:Green", }) resize_tree(tree_window, left_diff, right_diff, 30) diff --git a/lua/difftool/ui/tree.lua b/lua/hunk/ui/tree.lua similarity index 96% rename from lua/difftool/ui/tree.lua rename to lua/hunk/ui/tree.lua index cf61bd8..74817e9 100644 --- a/lua/difftool/ui/tree.lua +++ b/lua/hunk/ui/tree.lua @@ -1,6 +1,6 @@ -local signs = require("difftool.api.signs") -local config = require("difftool.config") -local utils = require("difftool.utils") +local signs = require("hunk.api.signs") +local config = require("hunk.config") +local utils = require("hunk.utils") local NuiTree = require("nui.tree") local Text = require("nui.text") @@ -132,9 +132,6 @@ local function apply_signs(tree, buf, nodes) nodes = nodes or tree:get_nodes() for _, node in pairs(nodes) do if node.type == "file" then - if type(node) ~= "table" then - node = tree:get_node(node) - end local _, linenr = tree:get_node(node:get_id()) if linenr then local sign diff --git a/lua/difftool/utils.lua b/lua/hunk/utils.lua similarity index 100% rename from lua/difftool/utils.lua rename to lua/hunk/utils.lua diff --git a/plugin/difftool.vim b/plugin/difftool.vim deleted file mode 100644 index e82f3da..0000000 --- a/plugin/difftool.vim +++ /dev/null @@ -1,4 +0,0 @@ -if exists("g:loaded_difftool_nvim") - finish -endif -let g:loaded_difftool_nvim = 1 diff --git a/plugin/hunk.vim b/plugin/hunk.vim new file mode 100644 index 0000000..688d6c2 --- /dev/null +++ b/plugin/hunk.vim @@ -0,0 +1,4 @@ +if exists("g:loaded_hunk_nvim") + finish +endif +let g:loaded_hunk_nvim = 1 diff --git a/tests/difftool/changeset_spec.lua b/tests/hunk/changeset_spec.lua similarity index 95% rename from tests/difftool/changeset_spec.lua rename to tests/hunk/changeset_spec.lua index f23e398..0dfaa9d 100644 --- a/tests/difftool/changeset_spec.lua +++ b/tests/hunk/changeset_spec.lua @@ -1,6 +1,6 @@ local fixtures = require("tests.utils.fixtures") -local api = require("difftool.api") -local utils = require("difftool.utils") +local api = require("hunk.api") +local utils = require("hunk.utils") describe("changesets", function() fixtures.with_workspace(function(workspace) diff --git a/tests/difftool/diff_spec.lua b/tests/hunk/diff_spec.lua similarity index 98% rename from tests/difftool/diff_spec.lua rename to tests/hunk/diff_spec.lua index 3b0f728..1fc61c0 100644 --- a/tests/difftool/diff_spec.lua +++ b/tests/hunk/diff_spec.lua @@ -1,5 +1,5 @@ local fixtures = require("tests.utils.fixtures") -local api = require("difftool.api") +local api = require("hunk.api") describe("diff patching", function() fixtures.with_workspace(function(workspace) diff --git a/tests/utils/fixtures.lua b/tests/utils/fixtures.lua index d96d486..6ffe7ef 100644 --- a/tests/utils/fixtures.lua +++ b/tests/utils/fixtures.lua @@ -1,4 +1,4 @@ -local fs = require("difftool.api.fs") +local fs = require("hunk.api.fs") local M = {}