Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: auto-setup with lazy-loading #12

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions lua/hunk/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,18 @@ local function open_file(layout, tree, change)
return left_file, right_file
end

local initialised = false

local function init()
initialised = true
api.signs.define_signs()
api.highlights.define_highlights()
end

function M.start(left, right, output)
if not initialised then
init()
end
local changeset = api.changeset.load_changeset(left, right)
local layout = ui.layout.create_layout()

Expand Down Expand Up @@ -175,20 +186,6 @@ end
function M.setup(opts)
opts = opts or {}
config.update_config(opts)

api.signs.define_signs()
api.highlights.define_highlights()

vim.api.nvim_create_user_command("DiffEditor", function(params)
local args = params.fargs
if #args < 2 then
vim.notify("Error: DiffEditor expects three arguments (left, right[, output])", vim.log.levels.ERROR)
return
end
M.start(args[1], args[2], args[3] or args[2])
end, {
nargs = "*",
})
end

return M
15 changes: 15 additions & 0 deletions plugin/hunk.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
if vim.g.loaded_hunk_nvim then
return
end
vim.g.loaded_hunk_nvim = true

vim.api.nvim_create_user_command("DiffEditor", function(params)
local args = params.fargs
if #args < 2 then
vim.notify("Error: DiffEditor expects three arguments (left, right[, output])", vim.log.levels.ERROR)
return
end
require("hunk").start(args[1], args[2], args[3] or args[2])
end, {
nargs = "*",
})
4 changes: 0 additions & 4 deletions plugin/hunk.vim

This file was deleted.

Loading