Skip to content

Commit

Permalink
Rename to hunk.nvim
Browse files Browse the repository at this point in the history
  • Loading branch information
julienvincent committed Jul 20, 2024
1 parent df35715 commit 6951c85
Show file tree
Hide file tree
Showing 22 changed files with 58 additions and 81 deletions.
2 changes: 1 addition & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 }"
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div align="center">
<h1>difftool.nvim</h1>
<h1>hunk.nvim</h1>
</div>

<div align="center">
Expand Down Expand Up @@ -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" }
Expand All @@ -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" },
Expand Down
7 changes: 0 additions & 7 deletions lua/difftool/api/init.lua

This file was deleted.

5 changes: 0 additions & 5 deletions lua/difftool/ui/init.lua

This file was deleted.

6 changes: 3 additions & 3 deletions lua/difftool/api/changeset.lua → lua/hunk/api/changeset.lua
Original file line number Diff line number Diff line change
@@ -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 = {}

Expand Down
22 changes: 1 addition & 21 deletions lua/difftool/api/diff.lua → lua/hunk/api/diff.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local fs = require("difftool.api.fs")
local fs = require("hunk.api.fs")

local M = {}

Expand Down Expand Up @@ -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
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions lua/hunk/api/init.lua
Original file line number Diff line number Diff line change
@@ -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"),
}
12 changes: 6 additions & 6 deletions lua/difftool/api/signs.lua → lua/hunk/api/signs.lua
Original file line number Diff line number Diff line change
@@ -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,
})
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions lua/difftool/init.lua → lua/hunk/init.lua
Original file line number Diff line number Diff line change
@@ -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 = {}

Expand Down
6 changes: 3 additions & 3 deletions lua/difftool/ui/file.lua → lua/hunk/ui/file.lua
Original file line number Diff line number Diff line change
@@ -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 = {}

Expand Down
5 changes: 5 additions & 0 deletions lua/hunk/ui/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
return {
layout = require("hunk.ui.layout"),
tree = require("hunk.ui.tree"),
file = require("hunk.ui.file"),
}
16 changes: 8 additions & 8 deletions lua/difftool/ui/layout.lua → lua/hunk/ui/layout.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local highlights = require("difftool.api.highlights")
local highlights = require("hunk.api.highlights")

local M = {}

Expand Down Expand Up @@ -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)
Expand Down
9 changes: 3 additions & 6 deletions lua/difftool/ui/tree.lua → lua/hunk/ui/tree.lua
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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
Expand Down
File renamed without changes.
4 changes: 0 additions & 4 deletions plugin/difftool.vim

This file was deleted.

4 changes: 4 additions & 0 deletions plugin/hunk.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if exists("g:loaded_hunk_nvim")
finish
endif
let g:loaded_hunk_nvim = 1
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/difftool/diff_spec.lua → tests/hunk/diff_spec.lua
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/fixtures.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local fs = require("difftool.api.fs")
local fs = require("hunk.api.fs")

local M = {}

Expand Down

0 comments on commit 6951c85

Please sign in to comment.