mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-11 14:18:14 +00:00
fix(explorer.watch): pcall watcher, since it can give errors on windows
This commit is contained in:
parent
bc87992e71
commit
af968181af
1 changed files with 30 additions and 28 deletions
|
@ -21,7 +21,7 @@ local running = {} ---@type table<string, fun()>
|
||||||
|
|
||||||
function M.abort()
|
function M.abort()
|
||||||
for _, abort in pairs(running) do
|
for _, abort in pairs(running) do
|
||||||
abort()
|
pcall(abort)
|
||||||
end
|
end
|
||||||
running = {}
|
running = {}
|
||||||
end
|
end
|
||||||
|
@ -38,37 +38,39 @@ function M.watch(cwd)
|
||||||
end
|
end
|
||||||
M.abort()
|
M.abort()
|
||||||
|
|
||||||
local timer = assert(uv.new_timer())
|
pcall(function()
|
||||||
local cancel = watch(cwd, {
|
local timer = assert(uv.new_timer())
|
||||||
uvflags = { recursive = true },
|
local cancel = watch(cwd, {
|
||||||
}, function(path)
|
uvflags = { recursive = true },
|
||||||
-- handle deletes
|
}, function(path)
|
||||||
while not uv.fs_stat(path) do
|
-- handle deletes
|
||||||
local p = vim.fs.dirname(path)
|
while not uv.fs_stat(path) do
|
||||||
if p == path then
|
local p = vim.fs.dirname(path)
|
||||||
return
|
if p == path then
|
||||||
end
|
return
|
||||||
path = p
|
|
||||||
end
|
|
||||||
Tree:refresh(path)
|
|
||||||
|
|
||||||
-- batch updates and give explorer the time to update before the watcher
|
|
||||||
timer:start(100, 0, function()
|
|
||||||
local picker = Snacks.picker.get({ source = "explorer" })[1]
|
|
||||||
if picker and Tree:is_dirty(picker:cwd(), picker.opts) then
|
|
||||||
if not picker.list.target then
|
|
||||||
picker.list:set_target()
|
|
||||||
end
|
end
|
||||||
picker:find()
|
path = p
|
||||||
end
|
end
|
||||||
|
Tree:refresh(path)
|
||||||
|
|
||||||
|
-- batch updates and give explorer the time to update before the watcher
|
||||||
|
timer:start(100, 0, function()
|
||||||
|
local picker = Snacks.picker.get({ source = "explorer" })[1]
|
||||||
|
if picker and Tree:is_dirty(picker:cwd(), picker.opts) then
|
||||||
|
if not picker.list.target then
|
||||||
|
picker.list:set_target()
|
||||||
|
end
|
||||||
|
picker:find()
|
||||||
|
end
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
running[cwd] = function()
|
||||||
running[cwd] = function()
|
if not timer:is_closing() then
|
||||||
if not timer:is_closing() then
|
timer:close()
|
||||||
timer:close()
|
end
|
||||||
|
cancel()
|
||||||
end
|
end
|
||||||
cancel()
|
end)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue