From 9ae5a8c30afd3b3f9361881da7d3c9750bd15a73 Mon Sep 17 00:00:00 2001 From: bhagwan Date: Tue, 15 Mar 2022 12:15:43 -0700 Subject: [PATCH] internal: reuse grep code in tags|tags_grep --- lua/fzf-lua/providers/grep.lua | 2 +- lua/fzf-lua/providers/tags.lua | 31 ++++++++----------------------- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/lua/fzf-lua/providers/grep.lua b/lua/fzf-lua/providers/grep.lua index 53992f0..fc87d34 100644 --- a/lua/fzf-lua/providers/grep.lua +++ b/lua/fzf-lua/providers/grep.lua @@ -114,7 +114,7 @@ M.grep = function(opts) -- if user did not provide a search term -- provide an input prompt - if not opts.search then + if not opts.search and not opts.raw_cmd then opts.search = vim.fn.input(opts.input_prompt) or '' end diff --git a/lua/fzf-lua/providers/tags.lua b/lua/fzf-lua/providers/tags.lua index 0a9d939..784ca95 100644 --- a/lua/fzf-lua/providers/tags.lua +++ b/lua/fzf-lua/providers/tags.lua @@ -1,4 +1,3 @@ -local core = require "fzf-lua.core" local path = require "fzf-lua.path" local utils = require "fzf-lua.utils" local libuv = require "fzf-lua.libuv" @@ -100,29 +99,12 @@ local function tags(opts) end return require'fzf-lua.providers.grep'.live_grep_st(opts) end + else + opts._curr_file = opts._curr_file and + path.relative(opts._curr_file, opts.cwd or vim.loop.cwd()) + opts.raw_cmd = opts.cmd or get_tags_cmd(opts) + return require'fzf-lua.providers.grep'.grep(opts) end - - -- see my comment in 'grep.lua:grep' what this is for - opts.fn_post_fzf = function(o, _) - local last_search, _ = M.get_last_search(o) - local last_query = config.__resume_data and config.__resume_data.last_query - if not last_search or #last_search==0 - and (last_query and #last_query>0) then - M.set_last_search(opts, last_query) - end - end - - -- save the search query so the use can - -- call the same search again - M.set_last_search(opts, opts.search, opts.no_esc) - - opts._curr_file = opts._curr_file and - path.relative(opts._curr_file, opts.cwd or vim.loop.cwd()) - opts.cmd = opts.cmd or get_tags_cmd(opts) - local contents = core.mt_cmd_wrapper(opts) - opts = core.set_header(opts) - opts = core.set_fzf_field_index(opts) - return core.fzf_files(opts, contents) end M.tags = function(opts) @@ -134,6 +116,9 @@ 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 utils.info("'btags' is not available for unnamed buffers.")