Skip to content

Commit e44bfe2

Browse files
committed
fix: add debounce to builtin previewer zero event (#909)
1 parent 602c669 commit e44bfe2

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

lua/fzf-lua/previewer/builtin.lua

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local path = require "fzf-lua.path"
22
local shell = require "fzf-lua.shell"
33
local utils = require "fzf-lua.utils"
4+
local libuv = require "fzf-lua.libuv"
45
local Object = require "fzf-lua.class"
56

67
local api = vim.api
@@ -293,10 +294,27 @@ function Previewer.base:cmdline(_)
293294
end
294295

295296
function Previewer.base:zero(_)
296-
local act = string.format("execute-silent(%s)",
297+
--
298+
-- debounce the zero event call to prevent reentry which may
299+
-- cause a hang of fzf or the nvim RPC server (#909)
300+
-- mkdir is an atomic operation and will fail if the directory
301+
-- already exists effectively creating a singleton shell command
302+
--
303+
-- currently awaiting an upstream fix:
304+
-- https://github.com/junegunn/fzf/issues/3516
305+
--
306+
self._zero_lock = self._zero_lock
307+
or vim.fn.systemlist({ "mktemp", "--dry-run", "--suffix", ".fzf-lua-zero" })[1]
308+
local act = string.format("execute-silent(mkdir %s && %s)",
309+
libuv.shellescape(self._zero_lock),
297310
shell.raw_action(function(_, _, _)
298-
self:clear_preview_buf(true)
299-
self.last_entry = nil
311+
vim.defer_fn(function()
312+
if self.loaded_entry then
313+
self:clear_preview_buf(true)
314+
self.last_entry = nil
315+
end
316+
vim.fn.delete(self._zero_lock, "d")
317+
end, self.delay)
300318
end, "", self.opts.debug))
301319
return act
302320
end

0 commit comments

Comments
 (0)