From 8595c6073d7dfcf84263ffd86ab9373940034397 Mon Sep 17 00:00:00 2001 From: bhagwan Date: Tue, 24 Dec 2024 14:20:04 -0800 Subject: [PATCH] fix: do not kill process if was hidden (closes #1634) --- lua/fzf-lua/config.lua | 16 ---------------- lua/fzf-lua/core.lua | 6 +++--- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/lua/fzf-lua/config.lua b/lua/fzf-lua/config.lua index 7760b22a..0e5911db 100644 --- a/lua/fzf-lua/config.lua +++ b/lua/fzf-lua/config.lua @@ -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 @@ -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 diff --git a/lua/fzf-lua/core.lua b/lua/fzf-lua/core.lua index 28f97d8e..69b0ba04 100644 --- a/lua/fzf-lua/core.lua +++ b/lua/fzf-lua/core.lua @@ -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) @@ -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