Skip to content

Commit 606d8c2

Browse files
phanenibhagwan
authored andcommitted
refactor: opts.cmd -> opts.contents in mt
1 parent 7c81dc5 commit 606d8c2

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

lua/fzf-lua/libuv.lua

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,17 +428,15 @@ M.spawn_stdio = function(opts)
428428
-- 'nvim -l ...', we won't be able to search single quotes
429429
-- NOTE: since we cannot guarantee the positional index
430430
-- of arguments (#291), we use the last argument instead
431-
local argv_expr = opts.is_live and type(opts.contents) == "string"
432-
if argv_expr then
433-
opts.cmd = opts.contents
434-
FzfLua.make_entry.expand_query(opts, argv())
431+
if opts.is_live and type(opts.contents) == "string" then
432+
opts.contents = FzfLua.make_entry.expand_query(opts, argv(), opts.contents)
435433
end
436434

437435
-- run the preprocessing fn
438436
if fn_preprocess then fn_preprocess(opts) end
439437

440438
---@type fzf-lua.content|fzf-lua.shell.data2
441-
local cmd = argv_expr and opts.cmd or opts.contents
439+
local cmd = opts.contents
442440
if type(cmd) == "string" and cmd:match("%-%-color[=%s]+never") then
443441
-- perf: skip stripping ansi coloring in `make_file.entry`
444442
opts.no_ansi_colors = true

lua/fzf-lua/make_entry.lua

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -430,19 +430,20 @@ end
430430

431431
---@param opts table
432432
---@param query string
433+
---@param cmd string
433434
---@return string
434-
M.expand_query = function(opts, query)
435+
M.expand_query = function(opts, query, cmd)
435436
-- live_grep replace pattern with last argument
436437
local argvz = "<query>"
437-
if opts.cmd:match(argvz) then
438+
if cmd:match(argvz) then
438439
-- The NEQ condition on Windows turned out to be a real pain in the butt
439440
-- so I decided to move the empty query test into our cmd proxy wrapper
440441
-- For obvious reasons this cannot work with `live_grep_native` and thus
441442
-- the NEQ condition remains for the "native" version
442443
if not opts.exec_empty_query and query == "" then
443444
-- query is always be the last argument
444-
opts.cmd = utils.shell_nop()
445-
return opts.cmd
445+
cmd = utils.shell_nop()
446+
return cmd
446447
end
447448

448449
-- For custom command transformations (#1927)
@@ -451,8 +452,8 @@ M.expand_query = function(opts, query)
451452
-- did the caller request rg with glob support?
452453
-- manipulation needs to be done before the argv replacement
453454
if opts.fn_transform_cmd then
454-
local new_cmd, new_query = opts.fn_transform_cmd(query, opts.cmd:gsub(argvz, ""), opts)
455-
opts.cmd = new_cmd or opts.cmd
455+
local new_cmd, new_query = opts.fn_transform_cmd(query, cmd:gsub(argvz, ""), opts)
456+
cmd = new_cmd or cmd
456457
query = new_query or query
457458
elseif opts.rg_glob then
458459
local search_query, glob_args = M.glob_parse(query, opts)
@@ -462,15 +463,15 @@ M.expand_query = function(opts, query)
462463
-- reset argvz so it doesn't get replaced again below
463464
-- insert glob args before `-- {argvz}` or `-e {argvz}` repositioned
464465
-- at the end of the command preceding the search query (#781, #794)
465-
opts.cmd = M.rg_insert_args(opts.cmd, glob_args, argvz)
466+
cmd = M.rg_insert_args(cmd, glob_args, argvz)
466467
query = search_query
467468
end
468469
end
469470
-- nifty hack to avoid having to double escape quotations
470471
-- see my comment inside 'live_grep' initial_command code
471-
opts.cmd = opts.cmd:gsub(argvz, libuv.shellescape(query))
472+
cmd = cmd:gsub(argvz, libuv.shellescape(query))
472473
end
473-
return opts.cmd
474+
return cmd
474475
end
475476

476477
M.preprocess = function(opts)

lua/fzf-lua/types.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ _G.FzfLua = require("fzf-lua")
186186
---@field _treesitter (fun(line:string):string,string?,string?,string?)|boolean?
187187
---stringify_mt
188188
---@field cmd? string
189-
---@field contents? fzf-lua.content
189+
---@field contents? fzf-lua.content|fzf-lua.shell.data2
190190
---@field debug? boolean|'v'|'verbose'
191191
---@field rg_glob? boolean
192192

0 commit comments

Comments
 (0)