feat(git): add in-house hunks module, replace gitsigns.nvim
This commit is contained in:
@@ -819,7 +819,7 @@ end
|
||||
|
||||
---@param buf integer
|
||||
---@return boolean
|
||||
local function is_worktree_buf(buf)
|
||||
function M.is_worktree_buf(buf)
|
||||
if not vim.api.nvim_buf_is_valid(buf) or vim.bo[buf].buftype ~= "" then
|
||||
return false
|
||||
end
|
||||
@@ -830,7 +830,7 @@ end
|
||||
---@param buf? integer
|
||||
function M.track(buf)
|
||||
buf = expand_buf(buf)
|
||||
if not is_worktree_buf(buf) then
|
||||
if not M.is_worktree_buf(buf) then
|
||||
return
|
||||
end
|
||||
local r = M.resolve(buf)
|
||||
|
||||
@@ -194,6 +194,65 @@ function M.debounce(fn, delay)
|
||||
}
|
||||
end
|
||||
|
||||
---@class ow.Git.Util.KeyedDebounceHandle<K>
|
||||
---@field cancel fun(key: K)
|
||||
---@field flush fun(key: K)
|
||||
---@field pending fun(key: K): boolean
|
||||
---@field close fun()
|
||||
|
||||
---@generic K, F: fun(key: K, ...)
|
||||
---@param fn F
|
||||
---@param delay integer
|
||||
---@return F, ow.Git.Util.KeyedDebounceHandle<K>
|
||||
function M.keyed_debounce(fn, delay)
|
||||
---@type table<any, { call: fun(...), handle: ow.Git.Util.DebounceHandle }>
|
||||
local slots = {}
|
||||
|
||||
local function call(key, ...)
|
||||
local t = type(key)
|
||||
assert(
|
||||
t == "string" or t == "number" or t == "boolean",
|
||||
"key must be a primitive (string, number, boolean)"
|
||||
)
|
||||
local slot = slots[key]
|
||||
if not slot then
|
||||
local c, h = M.debounce(function(...)
|
||||
fn(key, ...)
|
||||
end, delay)
|
||||
slot = { call = c, handle = h }
|
||||
slots[key] = slot
|
||||
end
|
||||
slot.call(...)
|
||||
end
|
||||
|
||||
return call,
|
||||
{
|
||||
cancel = function(key)
|
||||
local slot = slots[key]
|
||||
if slot then
|
||||
slot.handle.close()
|
||||
slots[key] = nil
|
||||
end
|
||||
end,
|
||||
flush = function(key)
|
||||
local slot = slots[key]
|
||||
if slot then
|
||||
slot.handle.flush()
|
||||
end
|
||||
end,
|
||||
pending = function(key)
|
||||
local slot = slots[key]
|
||||
return slot ~= nil and slot.handle.pending()
|
||||
end,
|
||||
close = function()
|
||||
for _, slot in pairs(slots) do
|
||||
slot.handle.close()
|
||||
end
|
||||
slots = {}
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
---@class ow.Git.Util.ExecOpts
|
||||
---@field cwd string?
|
||||
---@field stdin string?
|
||||
|
||||
Reference in New Issue
Block a user