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 8595c60
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
16 changes: 0 additions & 16 deletions lua/fzf-lua/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@ local M = {}
-- set this so that make_entry won't get nil err when setting remotely
M.__resume_data = {}

-- set|get the latest wrapped process PID
-- 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

M.resume_get = function(what, opts)
assert(opts.__resume_key)
if type(opts.__resume_get) == "function" then
Expand Down Expand Up @@ -797,10 +785,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
6 changes: 3 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,8 @@ 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())
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 8595c60

Please sign in to comment.