@@ -2,8 +2,6 @@ local uv = vim.uv or vim.loop
22local utils = require " fzf-lua.utils"
33local path = require " fzf-lua.path"
44local libuv = require " fzf-lua.libuv"
5- local base64 = require " fzf-lua.lib.base64"
6- local serpent = require " fzf-lua.lib.serpent"
75
86-- path to current file
97local __FILE__ = debug.getinfo (1 , " S" ).source :gsub (" ^@" , " " )
@@ -197,7 +195,9 @@ M.stringify_mt = function(cmd, opts)
197195 " exec_empty_query" ,
198196 " file_ignore_patterns" ,
199197 " rg_glob" ,
200- " _base64" ,
198+ " fn_transform" ,
199+ " fn_preprocess" ,
200+ " fn_postprocess" ,
201201 utils .__IS_WINDOWS and " __FZF_VERSION" or nil ,
202202 }
203203 -- caller requested rg with glob support
@@ -225,22 +225,6 @@ M.stringify_mt = function(cmd, opts)
225225 return t
226226 end
227227
228- --- @param obj table | string
229- --- @return string
230- local serialize = function (obj )
231- local str = type (obj ) == " table"
232- and serpent .line (obj , { comment = false , sortkeys = false })
233- or tostring (obj )
234- if opts ._base64 ~= false then
235- -- by default, base64 encode all arguments
236- return " [==[" .. base64 .encode (str ) .. " ]==]"
237- else
238- -- if not encoding, don't string wrap the table
239- return type (obj ) == " table" and str
240- or " [==[" .. str .. " ]==]"
241- end
242- end
243-
244228 -- `multiprocess=1` is "optional" if no opt which requires processing
245229 -- is present we return the command as is to be piped to fzf "natively"
246230 if opts .multiprocess == 1
@@ -287,12 +271,7 @@ M.stringify_mt = function(cmd, opts)
287271 opts .fn_preprocess = [[ return require("fzf-lua.make_entry").preprocess]]
288272 end
289273 end
290- local spawn_cmd = M .wrap_spawn_stdio (
291- serialize (filter_opts (opts )),
292- serialize (opts .fn_transform or " nil" ),
293- serialize (opts .fn_preprocess or " nil" ),
294- serialize (opts .fn_postprocess or " nil" )
295- )
274+ local spawn_cmd = M .wrap_spawn_stdio (filter_opts (opts ))
296275 if opts .argv_expr then
297276 -- prefix the query with `--` so we can support `--fixed-strings` (#781)
298277 spawn_cmd = string.format (" %s -- %s" , spawn_cmd , FzfLua .core .fzf_query_placeholder )
@@ -315,27 +294,12 @@ M.stringify = function(contents, opts, fzf_field_index)
315294 assert (not opts .__stringified , " twice stringified" )
316295 opts .__stringified = true
317296
318- --- @param fn_str string
319- --- @return function ?
320- local function load_fn (fn_str )
321- if type (fn_str ) ~= " string" then return end
322- local fn_loaded = nil
323- local fn = loadstring (fn_str )
324- if fn then fn_loaded = fn () end
325- if type (fn_loaded ) ~= " function" then
326- fn_loaded = nil
327- end
328- return fn_loaded
329- end
330-
331297 -- Convert string callbacks to callback functions
332298 for _ , k in ipairs ({ " fn_transform" , " fn_preprocess" , " fn_postprocess" }) do
333299 local v = opts [k ]
334- opts [k ] = load_fn (opts [k ]) or v
300+ opts [k ] = libuv . load_fn (opts [k ]) or v
335301 end
336302
337- assert (not opts .fn_reload or type (contents ) == " function" , " fn_reload must be of type function" )
338-
339303 local cmd , id = M .pipe_wrap_fn (function (pipe , ...)
340304 local args = { ... }
341305 -- Contents could be dependent or args, e.g. live_grep which
@@ -548,20 +512,16 @@ M.stringify_data2 = function(fn, opts, field_index)
548512 end , opts , field_index )
549513end
550514
551- --- @param opts string
552- --- @param fn_transform string
553- --- @param fn_preprocess string
554- --- @param fn_postprocess string
515+ --- @param opts table
555516--- @return string
556- M .wrap_spawn_stdio = function (opts , fn_transform , fn_preprocess , fn_postprocess )
517+ M .wrap_spawn_stdio = function (opts )
557518 local is_win = utils .__IS_WINDOWS
558519 local nvim_bin = os.getenv (" FZF_LUA_NVIM_BIN" ) or vim .v .progpath
559520 local cmd_str = (" %s -u NONE -l %s %s" ):format (
560521 libuv .shellescape (is_win and vim .fs .normalize (nvim_bin ) or nvim_bin ),
561522 libuv .shellescape (vim .fn .fnamemodify (is_win and vim .fs .normalize (__FILE__ ) or __FILE__ , " :h" ) ..
562523 " /spawn.lua" ),
563- libuv .shellescape ((" return %s,%s,%s,%s" ):format (opts , fn_transform , fn_preprocess , fn_postprocess ))
564- )
524+ libuv .shellescape ((libuv .serialize (opts , true ))))
565525 return cmd_str
566526end
567527
0 commit comments