live_grep resume search is working again

main
bhagwan 3 years ago
parent 0d24020629
commit 57ce1bff55

@ -289,6 +289,7 @@ M.fzf_files = function(opts)
end
M.fzf_files_interactive = function(opts)
opts = opts or config.normalize_opts(opts, config.globals.files)
@ -305,43 +306,54 @@ M.fzf_files_interactive = function(opts)
local shell_cmd = opts._cb_live_cmd(args[1])
local output_pipe = uv.new_pipe(false)
local error_pipe = uv.new_pipe(false)
local read_cb_count = 0
local shell = vim.env.SHELL or "sh"
local close_pipe = function()
if not uv.is_closing(pipe) then
uv.close(pipe)
end
end
uv.spawn(shell, {
args = { "-c", shell_cmd },
stdio = { nil, output_pipe, error_pipe },
cwd = opts.cwd
}, function(code, signal)
end)
local cleaned_up = false
local cleanup = function()
if not cleaned_up then
cleaned_up = true
uv.read_stop(output_pipe)
uv.read_stop(error_pipe)
uv.close(output_pipe)
uv.close(error_pipe)
uv.close(pipe)
output_pipe:read_stop()
error_pipe:read_stop()
output_pipe:close()
error_pipe :close()
if read_cb_count==0 then
-- only close if all our uv.write
-- calls are completed
close_pipe()
end
end
end)
local read_cb = function(err, data)
read_cb_count = read_cb_count + 1
if err then
cleanup()
close_pipe()
assert(not err)
end
if not data then
cleanup()
read_cb_count = read_cb_count - 1
return
end
uv.write(pipe, data, function(err)
if err then
cleanup()
close_pipe()
end
read_cb_count = read_cb_count - 1
if read_cb_count == 0 and uv.is_closing(output_pipe) then
-- spawn callback already called and did not close the pipe
-- due to read_cb_count>0, since this is the last call
-- we can close the fzf pipe
close_pipe()
end
end)
end
@ -367,7 +379,7 @@ M.fzf_files_interactive = function(opts)
opts.prompt, opts.prompt,
-- since we surrounded the skim placeholder with quotes
-- we need to escape them in the initial query
vim.fn.shellescape(query:gsub([["]], [[\"]])),
vim.fn.shellescape(utils.sk_escape(query)),
act_cmd)
else
-- fzf already adds single quotes

@ -42,7 +42,7 @@ M.fzf_files = require'fzf-lua.core'.fzf_files
M.files = require'fzf-lua.providers.files'.files
M.files_resume = require'fzf-lua.providers.files'.files_resume
M.grep = require'fzf-lua.providers.grep'.grep
M.live_grep = require'fzf-lua.providers.grep'.live_grep_native
M.live_grep = require'fzf-lua.providers.grep'.live_grep
M.live_grep_native = require'fzf-lua.providers.grep'.live_grep_native
M.live_grep_resume = require'fzf-lua.providers.grep'.live_grep_resume
M.grep_last = require'fzf-lua.providers.grep'.grep_last

@ -213,10 +213,7 @@ M.live_grep_native = function(opts)
opts.prompt, opts.prompt,
-- since we surrounded the skim placeholder with quotes
-- we need to escape them in the initial query
vim.fn.shellescape(query:gsub('["`]',
function(x)
return '\\' .. x
end)),
vim.fn.shellescape(utils.sk_escape(query)),
vim.fn.shellescape(
("(cd %s && %s)"):format(
vim.fn.shellescape(opts.cwd or '.'),

@ -71,6 +71,13 @@ function M.rg_escape(str)
end)
end
function M.sk_escape(str)
if not str then return str end
return str:gsub('["`]', function(x)
return '\\' .. x
end)
end
M.read_file = function(filepath)
local fd = vim.loop.fs_open(filepath, "r", 438)
if fd == nil then return '' end

Loading…
Cancel
Save