From def8abf58667c4d2c9cabdaa5297c793e511a582 Mon Sep 17 00:00:00 2001 From: bhagwan Date: Tue, 15 Mar 2022 16:30:56 -0700 Subject: [PATCH] internal: more tags|grep code consolidation --- lua/fzf-lua/providers/grep.lua | 6 +----- lua/fzf-lua/providers/tags.lua | 17 +++++++++-------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/lua/fzf-lua/providers/grep.lua b/lua/fzf-lua/providers/grep.lua index fc87d34..1908ae3 100644 --- a/lua/fzf-lua/providers/grep.lua +++ b/lua/fzf-lua/providers/grep.lua @@ -153,7 +153,6 @@ M.grep = function(opts) opts = core.set_fzf_field_index(opts) core.fzf_files(opts, contents) - opts.search = nil end -- single threaded version @@ -191,12 +190,9 @@ M.live_grep_st = function(opts) if query and not (opts.save_last_search == false) then set_last_search(opts, query, true) end - -- can be nill when called as fzf initial command + -- can be nil when called as fzf initial command query = query or '' - -- TODO: need to empty filespec - -- fix this collision, rename to _filespec opts.no_esc = nil - opts.filespec = nil return get_grep_cmd(opts, query, true) end diff --git a/lua/fzf-lua/providers/tags.lua b/lua/fzf-lua/providers/tags.lua index 784ca95..ae75731 100644 --- a/lua/fzf-lua/providers/tags.lua +++ b/lua/fzf-lua/providers/tags.lua @@ -28,11 +28,13 @@ local function get_tags_cmd(opts) else cmd = ("%s %s"):format("grep", opts.grep_opts or '') end - if opts.search and #opts.search>0 then + -- filename (i.e. btags) takes precedence over + -- search query as we can't search for both + if opts.filename and #opts.filename>0 then + query = libuv.shellescape(opts.filename) + elseif opts.search and #opts.search>0 then query = libuv.shellescape(opts.no_esc and opts.search or utils.rg_escape(opts.search)) - elseif opts._curr_file and #opts._curr_file>0 then - query = vim.fn.shellescape(opts._curr_file) else query = "-v '^!_TAG_'" end @@ -116,14 +118,13 @@ end M.btags = function(opts) opts = config.normalize_opts(opts, config.globals.btags) if not opts then return end - -- since the grep string is the filename - -- we cannot use additional grep strings - opts.search = nil - opts._curr_file = vim.api.nvim_buf_get_name(0) - if not opts._curr_file or #opts._curr_file==0 then + opts.filename = vim.api.nvim_buf_get_name(0) + if not opts.filename or #opts.filename==0 then utils.info("'btags' is not available for unnamed buffers.") return end + -- tags use relative paths + opts.filename = path.relative(opts.filename, opts.cwd or vim.loop.cwd()) return tags(opts) end