From d55db75d1a29702c18c55b572600116cee48b1a2 Mon Sep 17 00:00:00 2001 From: bhagwan Date: Tue, 15 Mar 2022 10:56:11 -0700 Subject: [PATCH] suppress exit code 1 error msg, better warning for non-matched tags --- lua/fzf-lua/previewer/fzf.lua | 4 ++-- lua/fzf-lua/win.lua | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lua/fzf-lua/previewer/fzf.lua b/lua/fzf-lua/previewer/fzf.lua index 70c6cbb..35a24d8 100644 --- a/lua/fzf-lua/previewer/fzf.lua +++ b/lua/fzf-lua/previewer/fzf.lua @@ -157,9 +157,9 @@ local grep_tag = function(file, tag) table.insert(cmd, filepath) local out = utils.io_system(cmd) if not utils.shell_error() then - line = out:match("[^:]+") + line = tonumber(out:match("[^:]+")) or 1 else - utils.warn(("Unable to find pattern '%s' in file '%s'"):format(pattern, file)) + utils.warn(("previewer: unable to find pattern '%s' in file '%s'"):format(pattern, file)) end -- if line == 1 then print(cmd) end return line diff --git a/lua/fzf-lua/win.lua b/lua/fzf-lua/win.lua index 5474f85..4b7a667 100644 --- a/lua/fzf-lua/win.lua +++ b/lua/fzf-lua/win.lua @@ -292,13 +292,21 @@ end function FzfWin:check_exit_status(exit_code) if not self:validate() then return end - if not exit_code or (exit_code ~=0 and exit_code ~= 130) then + -- from 'man fzf': + -- 0 Normal exit + -- 1 No match + -- 2 Error + -- 130 Interrupted with CTRL-C or ESC + if exit_code ~=0 and exit_code ~= 130 then local lines = vim.api.nvim_buf_get_lines(self.fzf_bufnr, 0, 1, false) - -- 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 "", + -- the reason we're not ignoring error 1 is due + -- to skim returning 1 for unexpected arguments + -- only warn about there is an actual error msg + if exit_code ~= 1 or (lines and #lines[1]>0) then + utils.warn(("fzf error %s: %s"):format( + exit_code or "", lines and #lines[1]>0 and lines[1] or "")) + end end end