'live_grep' freezes on large text files (#211)
parent
cb526dbb0c
commit
e02451600a
@ -0,0 +1,112 @@
|
|||||||
|
-- for testing, copied from:
|
||||||
|
-- https://github.com/vijaymarupudi/nvim-fzf/blob/master/lua/fzf/actions.lua
|
||||||
|
local uv = vim.loop
|
||||||
|
local path = require "fzf-lua.path"
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
local _counter = 0
|
||||||
|
local _registry = {}
|
||||||
|
|
||||||
|
function M.register_func(fn)
|
||||||
|
_counter = _counter + 1
|
||||||
|
_registry[_counter] = fn
|
||||||
|
return _counter
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.get_func(counter)
|
||||||
|
return _registry[counter]
|
||||||
|
end
|
||||||
|
|
||||||
|
-- creates a new address to listen to messages from actions. This is important,
|
||||||
|
-- if the user is using a custom fixed $NVIM_LISTEN_ADDRESS. Different neovim
|
||||||
|
-- instances will then use the same path as the address and it causes a mess,
|
||||||
|
-- i.e. actions stop working on the old instance. So we create our own (random
|
||||||
|
-- path) RPC server for this instance if it hasn't been started already.
|
||||||
|
local action_server_address = nil
|
||||||
|
|
||||||
|
function M.raw_async_action(fn, fzf_field_expression)
|
||||||
|
|
||||||
|
if not fzf_field_expression then
|
||||||
|
fzf_field_expression = "{+}"
|
||||||
|
end
|
||||||
|
|
||||||
|
local receiving_function = function(pipe_path, ...)
|
||||||
|
local pipe = uv.new_pipe(false)
|
||||||
|
local args = {...}
|
||||||
|
uv.pipe_connect(pipe, pipe_path, function(err)
|
||||||
|
vim.schedule(function ()
|
||||||
|
fn(pipe, unpack(args))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
if not action_server_address then
|
||||||
|
action_server_address = vim.fn.serverstart()
|
||||||
|
end
|
||||||
|
|
||||||
|
local id = M.register_func(receiving_function)
|
||||||
|
|
||||||
|
-- this is for windows WSL and AppImage users, their nvim path isn't just
|
||||||
|
-- 'nvim', it can be something else
|
||||||
|
local nvim_command = vim.v.argv[1]
|
||||||
|
|
||||||
|
local action_string = string.format("%s --headless --clean --cmd %s %s %s %s",
|
||||||
|
vim.fn.shellescape(nvim_command),
|
||||||
|
vim.fn.shellescape("luafile " .. path.join{vim.g.fzf_lua_directory, "shell_helper.lua"}),
|
||||||
|
vim.fn.shellescape(action_server_address),
|
||||||
|
id,
|
||||||
|
fzf_field_expression)
|
||||||
|
return action_string, id
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.async_action(fn, fzf_field_expression)
|
||||||
|
local action_string, id = M.raw_async_action(fn, fzf_field_expression)
|
||||||
|
return vim.fn.shellescape(action_string), id
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.raw_action(fn, fzf_field_expression)
|
||||||
|
|
||||||
|
local receiving_function = function(pipe, ...)
|
||||||
|
local ret = fn(...)
|
||||||
|
|
||||||
|
local on_complete = function(err)
|
||||||
|
-- We are NOT asserting, in case fzf closes the pipe before we can send
|
||||||
|
-- the preview.
|
||||||
|
-- assert(not err)
|
||||||
|
uv.close(pipe)
|
||||||
|
end
|
||||||
|
|
||||||
|
if type(ret) == "string" then
|
||||||
|
uv.write(pipe, ret, on_complete)
|
||||||
|
elseif type(ret) == nil then
|
||||||
|
on_complete()
|
||||||
|
elseif type(ret) == "table" then
|
||||||
|
if not vim.tbl_isempty(ret) then
|
||||||
|
uv.write(pipe, vim.tbl_map(function(x) return x.."\n" end, ret), on_complete)
|
||||||
|
else
|
||||||
|
on_complete()
|
||||||
|
end
|
||||||
|
else
|
||||||
|
uv.write(pipe, tostring(ret) .. "\n", on_complete)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M.raw_async_action(receiving_function, fzf_field_expression)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.action(fn, fzf_field_expression)
|
||||||
|
local action_string, id = M.raw_action(fn, fzf_field_expression)
|
||||||
|
return vim.fn.shellescape(action_string), id
|
||||||
|
end
|
||||||
|
|
||||||
|
-- set to 'true' to use 'nvim-fzf'
|
||||||
|
-- set to 'false' for debugging using the local version
|
||||||
|
if false then
|
||||||
|
M.action = require("fzf.actions").action
|
||||||
|
M.raw_action = require("fzf.actions").raw_action
|
||||||
|
M.async_action = require("fzf.actions").async_action
|
||||||
|
M.raw_async_action = require("fzf.actions").raw_async_action
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
@ -0,0 +1,69 @@
|
|||||||
|
-- for testing, copied from:
|
||||||
|
-- https://github.com/vijaymarupudi/nvim-fzf/blob/master/action_helper.lua
|
||||||
|
local uv = vim.loop
|
||||||
|
|
||||||
|
local function get_preview_socket()
|
||||||
|
local tmp = vim.fn.tempname()
|
||||||
|
local socket = uv.new_pipe(false)
|
||||||
|
uv.pipe_bind(socket, tmp)
|
||||||
|
return socket, tmp
|
||||||
|
end
|
||||||
|
|
||||||
|
local preview_socket, preview_socket_path = get_preview_socket()
|
||||||
|
|
||||||
|
uv.listen(preview_socket, 100, function(err)
|
||||||
|
local preview_receive_socket = uv.new_pipe(false)
|
||||||
|
-- start listening
|
||||||
|
uv.accept(preview_socket, preview_receive_socket)
|
||||||
|
preview_receive_socket:read_start(function(err, data)
|
||||||
|
assert(not err)
|
||||||
|
if not data then
|
||||||
|
uv.close(preview_receive_socket)
|
||||||
|
uv.close(preview_socket)
|
||||||
|
vim.schedule(function()
|
||||||
|
vim.cmd[[qall]]
|
||||||
|
end)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
io.write(data)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
local function_id = tonumber(vim.fn.argv(1))
|
||||||
|
local success, errmsg = pcall(function ()
|
||||||
|
local nargs = vim.fn.argc()
|
||||||
|
local args = {}
|
||||||
|
-- this is guaranteed to be 2 or more, we are interested in those greater than 2
|
||||||
|
for i=3,nargs do
|
||||||
|
-- vim uses zero indexing
|
||||||
|
table.insert(args, vim.fn.argv(i - 1))
|
||||||
|
end
|
||||||
|
local environ = vim.fn.environ()
|
||||||
|
local chan_id = vim.fn.sockconnect("pipe", vim.fn.argv(0), { rpc = true })
|
||||||
|
-- for skim compatibility
|
||||||
|
local preview_lines = environ.FZF_PREVIEW_LINES or environ.LINES
|
||||||
|
local preview_cols = environ.FZF_PREVIEW_COLUMNS or environ.COLUMNS
|
||||||
|
vim.rpcrequest(chan_id, "nvim_exec_lua", [[
|
||||||
|
local luaargs = {...}
|
||||||
|
local function_id = luaargs[1]
|
||||||
|
local preview_socket_path = luaargs[2]
|
||||||
|
local fzf_selection = luaargs[3]
|
||||||
|
local fzf_lines = luaargs[4]
|
||||||
|
local fzf_columns = luaargs[5]
|
||||||
|
local usr_func = require"fzf-lua.shell".get_func(function_id)
|
||||||
|
return usr_func(preview_socket_path, fzf_selection, fzf_lines, fzf_columns)
|
||||||
|
]], {
|
||||||
|
function_id,
|
||||||
|
preview_socket_path,
|
||||||
|
args,
|
||||||
|
tonumber(preview_lines),
|
||||||
|
tonumber(preview_cols)
|
||||||
|
})
|
||||||
|
vim.fn.chanclose(chan_id)
|
||||||
|
end)
|
||||||
|
|
||||||
|
if not success then
|
||||||
|
io.write("FzfLua Error:\n\n" .. errmsg .. "\n")
|
||||||
|
vim.cmd [[qall]]
|
||||||
|
end
|
Loading…
Reference in New Issue