better error handling of fzf exit status (nvim-fzf PR #36)

main
bhagwan 3 years ago
parent 76b6a994b8
commit 913c3c650d

@ -40,9 +40,9 @@ M.fzf = function(opts, contents)
fzf_win:attach_previewer(previewer) fzf_win:attach_previewer(previewer)
fzf_win:create() fzf_win:create()
local selected = fzf.raw_fzf(contents, M.build_fzf_cli(opts), local selected, exit_code = fzf.raw_fzf(contents, M.build_fzf_cli(opts),
{ fzf_binary = opts.fzf_bin, fzf_cwd = opts.cwd }) { fzf_binary = opts.fzf_bin, fzf_cwd = opts.cwd })
fzf_win:check_exit_status() fzf_win:check_exit_status(exit_code)
if fzf_win:autoclose() == nil or fzf_win:autoclose() then if fzf_win:autoclose() == nil or fzf_win:autoclose() then
fzf_win:close() fzf_win:close()
end end

@ -202,11 +202,15 @@ function FzfWin:reset_win_highlights(win, is_border)
vim.api.nvim_win_set_option(win, 'winhighlight', hl) vim.api.nvim_win_set_option(win, 'winhighlight', hl)
end end
function FzfWin:check_exit_status() function FzfWin:check_exit_status(exit_code)
if not self:validate() then return end if not self:validate() then return end
local lines = vim.api.nvim_buf_get_lines(self.fzf_bufnr, 0, 1, false) if not exit_code or tonumber(exit_code) ~= 130 then
if lines and #lines[1]>0 then local lines = vim.api.nvim_buf_get_lines(self.fzf_bufnr, 0, 1, false)
utils.warn("fzf error: " .. lines[1]) -- this can happen before nvim-fzf returned exit code (PR #36)
if not exit_code and (not lines or #lines[1]==0) then return end
utils.warn(("fzf error %s: %s")
:format(exit_code or "<null>",
lines and #lines[1]>0 and lines[1] or "<null>"))
end end
end end

Loading…
Cancel
Save