From b98bb2618c985733d1e51daeef9b4c02a570fd62 Mon Sep 17 00:00:00 2001 From: bhagwan Date: Fri, 4 Mar 2022 09:45:24 -0800 Subject: [PATCH] tags|btags bugfix: preview/action when tag name contains / or --- lua/fzf-lua/make_entry.lua | 7 ++++--- lua/fzf-lua/path.lua | 4 ++++ lua/fzf-lua/previewer/fzf.lua | 10 ++++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lua/fzf-lua/make_entry.lua b/lua/fzf-lua/make_entry.lua index 5f45db8..daca445 100644 --- a/lua/fzf-lua/make_entry.lua +++ b/lua/fzf-lua/make_entry.lua @@ -319,9 +319,10 @@ M.file = function(opts, x) end M.tag = function(opts, x) - local name, file, text = x:match("^(.*)\t(.*)\t(.*/)") - local line, tag = text:match("(%d-);?(/.*/)") - if not file then return x end + local name, file, text = x:match("([^\t]+)\t([^\t]+)\t(.*)") + if not file or not name or not text then return x end + text = text:match('(.*);"') or text -- remove ctag comments + local line, tag = text:gsub("\\/", "/"):match("(%d-);?(/.*/)") return ("%s%s: %s %s"):format( M.file(opts, file), (not line or #line==0) and "" or ":"..utils.ansi_codes.green(tostring(line)), diff --git a/lua/fzf-lua/path.lua b/lua/fzf-lua/path.lua index 9435922..9d9d81c 100644 --- a/lua/fzf-lua/path.lua +++ b/lua/fzf-lua/path.lua @@ -141,6 +141,10 @@ end function M.entry_to_ctag(entry, noesc) local scode = entry:match("%:.-/^?\t?(.*)/") + -- if tag name contains a slash we could + -- have the wrong match, most tags start + -- with ^ so try to match based on that + scode = scode and scode:match("/^(.*)") or scode if scode and not noesc then -- scode = string.gsub(scode, "[$]$", "") scode = string.gsub(scode, [[\\]], [[\]]) diff --git a/lua/fzf-lua/previewer/fzf.lua b/lua/fzf-lua/previewer/fzf.lua index dc959ae..f578f87 100644 --- a/lua/fzf-lua/previewer/fzf.lua +++ b/lua/fzf-lua/previewer/fzf.lua @@ -13,7 +13,6 @@ function Previewer.base:new(o, opts) self.type = "cmd"; self.cmd = o.cmd; self.args = o.args or ""; - self.relative = o.relative self.opts = opts; return self end @@ -77,7 +76,7 @@ function Previewer.cmd:action(o) o = o or {} local act = shell.raw_action(function (items, _, _) -- only preview first item - local entry = path.entry_to_file(items[1], not self.relative and self.opts.cwd) + local entry = path.entry_to_file(items[1], self.opts.cwd) return entry.bufname or entry.path end, self.opts.field_index_expr or "{}") return act @@ -159,13 +158,15 @@ local grep_tag = function(file, tag) local out = utils.io_system(cmd) if not utils.shell_error() then line = out:match("[^:]+") + else + utils.warn(("Unable to find pattern '%s' in file '%s'"):format(pattern, file)) end -- if line == 1 then print(cmd) end return line end function Previewer.cmd_async:parse_entry_and_verify(entrystr) - local entry = path.entry_to_file(entrystr, not self.relative and self.opts.cwd) + local entry = path.entry_to_file(entrystr, self.opts.cwd) local filepath = entry.bufname or entry.path or '' if self.opts._ctag and entry.line<=1 then -- tags without line numbers @@ -176,6 +177,7 @@ function Previewer.cmd_async:parse_entry_and_verify(entrystr) if not line and ctag then entry.ctag = ctag entry.line = grep_tag(filepath, entry.ctag) + print("line", entry.line, entry.ctag) end end local errcmd = nil @@ -272,7 +274,7 @@ function Previewer.git_diff:cmdline(o) self.git_icons['?'] .. self.git_icons['C'] .. "]"..utils.nbsp) ~= nil - local file = path.entry_to_file(items[1], not self.relative and self.opts.cwd) + local file = path.entry_to_file(items[1], self.opts.cwd) local cmd = nil if is_modified then cmd = self.cmd_modified elseif is_deleted then cmd = self.cmd_deleted