Skip to content

Commit 795306c

Browse files
committed
fix(resume): do not over "protect"
1 parent c8b5361 commit 795306c

6 files changed

Lines changed: 46 additions & 25 deletions

File tree

lua/fzf-lua/core.lua

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,10 @@ M.fzf_exec = function(contents, opts)
155155
-- the API accepts both tables and functions which we "stringify"
156156
-- We also send string commands as stringify is also responsible
157157
-- for multiprocess wrapping of shell commands with processing
158-
contents = contents and shell.stringify(contents, opts) or nil
158+
contents = contents and shell.stringify(contents, opts, nil, true) or nil
159159
assert(contents == nil or type(contents) == "string", "contents must be of type string")
160+
opts = M.convert_reload_actions(contents, opts)
161+
opts = M.convert_exec_silent_actions(opts)
160162
return M.fzf_wrap(contents, opts)
161163
end
162164

@@ -172,10 +174,14 @@ M.fzf_live = function(contents, opts)
172174
-- AKA "live": fzf acts as a selector only (fuzzy matching is disabled)
173175
-- each keypress reloads fzf's input usually based on the typed query
174176
-- utilizes fzf's 'change:reload' event or skim's "interactive" mode
175-
opts.fn_reload = shell.stringify(contents, opts)
177+
-- convert "reload" actions to fzf's `reload` binds
178+
-- convert "exec_silent" actions to fzf's `execute-silent` binds
179+
opts.fn_reload = shell.stringify(contents, opts, nil, true)
176180
local fzf_field_index = M.fzf_field_index(opts)
177181
local cmd = M.expand_query(opts.fn_reload, fzf_field_index)
178182
contents, opts = M.setup_fzf_interactive_flags(cmd, fzf_field_index, opts)
183+
opts = M.convert_reload_actions(contents, opts)
184+
opts = M.convert_exec_silent_actions(opts)
179185
return M.fzf_wrap(contents, opts)
180186
end
181187

@@ -392,10 +398,6 @@ M.fzf = function(contents, opts)
392398

393399
fzf_win:attach_previewer(previewer)
394400
local fzf_bufnr = fzf_win:create()
395-
-- convert "reload" actions to fzf's `reload` binds
396-
-- convert "exec_silent" actions to fzf's `execute-silent` binds
397-
opts = M.convert_reload_actions(contents, opts)
398-
opts = M.convert_exec_silent_actions(opts)
399401
local selected, exit_code = fzf.raw_fzf(contents, M.build_fzf_cli(opts, fzf_win),
400402
{
401403
fzf_bin = opts.fzf_bin,
@@ -997,7 +999,7 @@ local patch_shell_action = function(v, opts)
997999
items = (zero_matched and zero_selected) and {} or items
9981000
end
9991001
v.fn(items, opts)
1000-
end, opts, field_index)
1002+
end, opts, field_index, true)
10011003
end
10021004

10031005
-- converts actions defined with "reload=true" to use fzf's `reload` bind
@@ -1083,7 +1085,8 @@ M.convert_reload_actions = function(reload_cmd, opts)
10831085
-- NOTE: this fixes existence of both load as function and rebind, e.g. git_status with:
10841086
-- setup({ keymap = { fzf = { true, load = function() _G._fzf_load_called = true end } } }
10851087
if type(opts.keymap.fzf.load) == "function" then
1086-
opts.keymap.fzf.load = "execute-silent:" .. shell.stringify_data(opts.keymap.fzf.load, opts)
1088+
opts.keymap.fzf.load = "execute-silent:"
1089+
.. shell.stringify_data(opts.keymap.fzf.load, opts, nil, true)
10871090
end
10881091
if rebind and type(opts.keymap.fzf.load) == "string" then
10891092
return string.format("%s+%s", rebind, opts.keymap.fzf.load)

lua/fzf-lua/previewer/builtin.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ function Previewer.base:cmdline(_)
454454
-- save last entry even if we don't display
455455
self.last_entry = entry
456456
return ""
457-
end, self.opts, "{} {q} {n}")
457+
end, self.opts, "{} {q} {n}", false)
458458
return act
459459
end
460460

@@ -481,7 +481,7 @@ function Previewer.base:zero(_)
481481
self.last_entry = nil
482482
vim.fn.delete(self._zero_lock, "d")
483483
end, self.delay)
484-
end, self.opts, ""))
484+
end, self.opts, "", false))
485485
return act
486486
end
487487

lua/fzf-lua/previewer/fzf.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function Previewer.cmd:action(o)
8787
local act = shell.stringify_data(function(items, _, _)
8888
local entry = path.entry_to_file(items[1], self.opts)
8989
return entry.bufname or entry.path
90-
end, self.opts, self.opts.field_index_expr or "{}")
90+
end, self.opts, self.opts.field_index_expr or "{}", false)
9191
return act
9292
end
9393

@@ -214,7 +214,7 @@ function Previewer.cmd_async:cmdline(o)
214214
local cmd = errcmd or ("%s %s %s"):format(
215215
self.cmd, self.args, libuv.shellescape(filepath))
216216
return cmd
217-
end, self.opts, "{} {q}")
217+
end, self.opts, "{} {q}", false)
218218
return act
219219
end
220220

@@ -278,7 +278,7 @@ function Previewer.bat_async:cmdline(o)
278278
line_range,
279279
libuv.shellescape(filepath))
280280
return cmd
281-
end, self.opts, "{} {q}")
281+
end, self.opts, "{} {q}", false)
282282
return act
283283
end
284284

@@ -379,7 +379,7 @@ function Previewer.git_diff:cmdline(o)
379379
-- cmd = string.format("%s %s %s", table.concat(setenv, " "), cmd, pager)
380380
cmd = string.format("%s %s", cmd, pager)
381381
return { cmd = cmd, env = env }
382-
end, self.opts, "{}")
382+
end, self.opts, "{}", false)
383383
return act
384384
end
385385

@@ -398,7 +398,7 @@ function Previewer.man_pages:cmdline(o)
398398
local manpage = require("fzf-lua.providers.manpages").manpage_sh_arg(items[1])
399399
local cmd = self.cmd:format(manpage)
400400
return cmd
401-
end, self.opts, "{}")
401+
end, self.opts, "{}", false)
402402
return act
403403
end
404404

@@ -435,7 +435,7 @@ function Previewer.help_tags:cmdline(o)
435435
end
436436
end
437437
return cmd
438-
end, self.opts, "{}")
438+
end, self.opts, "{}", false)
439439
return act
440440
end
441441

lua/fzf-lua/profiles/telescope.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ end
88
return {
99
{ "default-title" }, -- base profile
1010
desc = "match telescope default highlights|keybinds",
11-
fzf_opts = { ["--layout"] = "default", ["--marker"] = "+" , ["--cycle"] = true},
11+
fzf_opts = { ["--layout"] = "default", ["--marker"] = "+", ["--cycle"] = true },
1212
winopts = {
1313
width = 0.8,
1414
height = 0.9,

lua/fzf-lua/rpc.lua

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ local rpc_nvim_exec_lua = function(opts)
8282
vim.fn.chanclose(chan_id)
8383
end)
8484

85-
if not success or opts.debug then
85+
if not success or opts.debug == "v" or opts.debug == 2 then
8686
io.stderr:write(("[DEBUG] debug = %s\n"):format(opts.debug))
8787
io.stderr:write(("[DEBUG] function ID = %d\n"):format(opts.fnc_id))
8888
io.stderr:write(("[DEBUG] fzf_lua_server = %s\n"):format(opts.fzf_lua_server))
@@ -107,7 +107,18 @@ local args = vim.deepcopy(_G.arg)
107107
args[0] = nil -- remove filename
108108
local opts = {
109109
fnc_id = tonumber(table.remove(args, 1)),
110-
debug = table.remove(args, 1) == "true",
110+
debug = (function()
111+
local ret = table.remove(args, 1)
112+
if ret == "nil" then
113+
return nil
114+
elseif ret == "true" then
115+
return true
116+
elseif ret == "false" then
117+
return false
118+
else
119+
return tonumber(ret) or tostring(ret)
120+
end
121+
end)(),
111122
fzf_selection = args,
112123
fzf_lua_server = vim.env.FZF_LUA_SERVER or vim.env.SKIM_FZF_LUA_SERVER or vim.env.NVIM,
113124
}

lua/fzf-lua/shell.lua

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ end
235235
---Fzf field index expression, e.g. "{+}" (selected), "{q}" (query)
236236
---@param fzf_field_index string?
237237
---@return string, integer?
238-
M.stringify = function(contents, opts, fzf_field_index)
238+
M.stringify = function(contents, opts, fzf_field_index, protect)
239239
assert(contents, "must supply contents")
240240

241241
-- TODO: should we let this assert?
@@ -411,20 +411,27 @@ M.stringify = function(contents, opts, fzf_field_index)
411411
end
412412
end, fzf_field_index or "", opts.debug)
413413

414-
M.set_protected(id)
414+
-- "protect" a function ptr, cleared when opening a new picker in `core.fzf()`
415+
-- protected functions include init (content) commands and acrions (reload
416+
-- and execute-silent), previewer trigger commands are excluded (zero event
417+
-- and preview callback)
418+
if protect then
419+
M.set_protected(id)
420+
end
421+
415422
return cmd, id
416423
end
417424

418-
M.stringify_cmd = function(fn, opts, fzf_field_index)
425+
M.stringify_cmd = function(fn, opts, fzf_field_index, protect)
419426
assert(type(fn) == "function", "fn must be of type function")
420427
return M.stringify(fn, {
421428
__stringify_cmd = true,
422429
PidObject = utils.pid_object("__stringify_cmd_pid", opts),
423430
debug = opts.debug,
424-
}, fzf_field_index)
431+
}, fzf_field_index, protect)
425432
end
426433

427-
M.stringify_data = function(fn, opts, fzf_field_index)
434+
M.stringify_data = function(fn, opts, fzf_field_index, protect)
428435
assert(type(fn) == "function", "fn must be of type function")
429436
return M.stringify(function(cb, _, ...)
430437
local ret = fn(...)
@@ -436,7 +443,7 @@ M.stringify_data = function(fn, opts, fzf_field_index)
436443
cb(tostring(ret))
437444
end
438445
cb(nil)
439-
end, { debug = opts.debug }, fzf_field_index)
446+
end, { debug = opts.debug }, fzf_field_index, protect)
440447
end
441448

442449
return M

0 commit comments

Comments
 (0)