Skip to content

Commit

Permalink
fix: do not kill process if was hidden (closes #1634)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibhagwan committed Dec 24, 2024
1 parent 72e25cc commit 769fc13
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
19 changes: 8 additions & 11 deletions lua/fzf-lua/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ M.__resume_data = {}
-- NOTE: we don't store this closure in `opts` (or store a ref to `opts`)
-- as together with `__resume_data` it can create a memory leak having to
-- store recursive copies of the `opts` table (#723)
M.set_pid = function(pid)
M.__pid = pid
end

M.get_pid = function()
return M.__pid
end
-- NOT IN USE ANY LONGER, USING `opts.__pid` instead
-- M.set_pid = function(pid)
-- M.__pid = pid
-- end
--
-- M.get_pid = function()
-- return M.__pid
-- end

M.resume_get = function(what, opts)
assert(opts.__resume_key)
Expand Down Expand Up @@ -797,10 +798,6 @@ function M.normalize_opts(opts, globals, __resume_key)
end
end

-- libuv.spawn_nvim_fzf_cmd() pid callback
opts._set_pid = M.set_pid
opts._get_pid = M.get_pid

-- mark as normalized
opts._normalized = true

Expand Down
7 changes: 4 additions & 3 deletions lua/fzf-lua/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ M.fzf_exec = function(contents, opts)
contents = libuv.spawn_nvim_fzf_cmd({
cmd = contents,
cwd = opts.cwd,
cb_pid = opts._set_pid,
cb_pid = function(pid) opts.__pid = pid end,
},
opts.fn_transform or function(x) return x end,
opts.fn_preprocess)
Expand Down Expand Up @@ -427,8 +427,9 @@ M.fzf = function(contents, opts)
-- NOTE: might be an overkill since we're using $FZF_DEFAULT_COMMAND
-- to spawn the piped process and fzf is responsible for termination
-- when the fzf process exists
if type(opts._get_pid == "function") then
libuv.process_kill(opts._get_pid())
print("pid exit", opts.__pid)
if tonumber(opts.__pid) then
libuv.process_kill(opts.__pid)
end
-- If a hidden process was killed by [re-]starting a new picker do nothing
if fzf_win:was_hidden() then return end
Expand Down

0 comments on commit 769fc13

Please sign in to comment.