Skip to content

Commit 4c3e5cd

Browse files
committed
feat(global): fallback to tags (#2184)
1 parent c4cc687 commit 4c3e5cd

3 files changed

Lines changed: 42 additions & 9 deletions

File tree

lua/fzf-lua/defaults.lua

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,14 +361,40 @@ M.defaults.files = {
361361
}
362362

363363
M.defaults.global = vim.tbl_deep_extend("force", M.defaults.files, {
364+
silent = true,
364365
cwd_prompt = true,
365366
line_query = true,
366-
pickers = {
367-
{ "files", desc = "Files" },
368-
{ "buffers", desc = "Bufs", prefix = "$" },
369-
{ "lsp_document_symbols", desc = "Symbols (buf)", prefix = "@" },
370-
{ "lsp_workspace_symbols", desc = "Symbols (project)", prefix = "#" },
371-
},
367+
pickers = function()
368+
local clients = utils.lsp_get_clients({ bufnr = FzfLua.core.CTX().bufnr })
369+
return utils.tbl_isempty(clients) and {
370+
{ "files", desc = "Files" },
371+
{ "buffers", desc = "Bufs", prefix = "$" },
372+
{
373+
"btags",
374+
desc = "Tags (buf)",
375+
prefix = "@",
376+
opts = {
377+
fn_transform = [[return require("fzf-lua.make_entry").tag]],
378+
}
379+
},
380+
{
381+
"tags",
382+
desc = "Tags (project)",
383+
prefix = "#",
384+
opts = {
385+
fn_transform = [[return require("fzf-lua.make_entry").tag]],
386+
rg_opts = "--no-heading --color=always --smart-case",
387+
grep_opts = "--color=auto --perl-regexp",
388+
}
389+
},
390+
}
391+
or {
392+
{ "files", desc = "Files" },
393+
{ "buffers", desc = "Bufs", prefix = "$" },
394+
{ "lsp_document_symbols", desc = "Symbols (buf)", prefix = "@" },
395+
{ "lsp_workspace_symbols", desc = "Symbols (project)", prefix = "#" },
396+
}
397+
end,
372398
fzf_opts = { ["--nth"] = false, ["--with-nth"] = false },
373399
winopts = { preview = { winopts = { cursorline = true } } },
374400
_ctx = { includeBuflist = true }, -- we include a buffer picker

lua/fzf-lua/providers/meta.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ M.global = function(opts)
157157
return FzfLua.files(opts)
158158
end
159159

160+
if type(opts.pickers) == "function" then
161+
opts.pickers = opts.pickers()
162+
end
163+
160164
-- Tells fzf_wrap to not start the fzf process
161165
opts._start = false
162166
local pickers = {}
@@ -177,7 +181,8 @@ M.global = function(opts)
177181
else
178182
-- Each subsequent picker gets a fresh copy of the original opts
179183
-- (unmodified by the default picker)
180-
pickers[name] = { FzfLua[name](opts_copy) }
184+
pickers[name] = { FzfLua[name](t.opts and
185+
vim.tbl_deep_extend("force", {}, opts_copy, t.opts) or opts_copy) }
181186
end
182187
else
183188
utils.warn(string.format("invalid picker '%s', ignoring.", name))

lua/fzf-lua/providers/tags.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ local function tags(opts)
9898
return
9999
end
100100
else
101-
utils.info(("Tags file ('%s') does not exist. Create one with ctags -R")
102-
:format(opts._ctags_file))
101+
if opts.silent ~= true then
102+
utils.info(("Tags file ('%s') does not exist. Create one with ctags -R")
103+
:format(opts._ctags_file))
104+
end
103105
return
104106
end
105107
end

0 commit comments

Comments
 (0)