Skip to content

Commit

Permalink
fix(watcher): debounce per watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis6991 committed Jun 19, 2023
1 parent a56fb7c commit b0f0612
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lua/gitsigns/manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ local function inspect(x)
return vim.inspect(x, {indent = '', newline = ' '})
end

local watch_gitdir_handler = debounce_trailing(100, void(function(bufnr)
local watch_gitdir_handler = void(function(bufnr)
local bcache = cache[bufnr]

if not bcache then
Expand Down Expand Up @@ -558,7 +558,7 @@ local watch_gitdir_handler = debounce_trailing(100, void(function(bufnr)
bcache:invalidate()

M.update(bufnr, bcache)
end))
end)

--- @param bufnr integer
--- @param gitdir string
Expand All @@ -568,6 +568,10 @@ function M.watch_gitdir(bufnr, gitdir)
return
end

-- Setup debounce as we create the luv object so the debounce is independent
-- to each watcher
local watch_gitdir_handler_db = debounce_trailing(100, watch_gitdir_handler)

dprintf('Watching git dir')
local w = assert(uv.new_fs_event())
w:start(
Expand All @@ -589,7 +593,7 @@ function M.watch_gitdir(bufnr, gitdir)

dprint(info)

watch_gitdir_handler(bufnr)
watch_gitdir_handler_db(bufnr)
end
)
return w
Expand Down

0 comments on commit b0f0612

Please sign in to comment.