feat(picker): added opts.rtp (bool) to find/grep over files in the rtp. See #680

This commit is contained in:
Folke Lemaitre 2025-01-23 13:03:15 +01:00
parent 3fb111090e
commit 9d5d3bdb17
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
4 changed files with 26 additions and 6 deletions

View file

@ -121,6 +121,7 @@ M.diagnostics_buffer = {
---@field follow? boolean follow symlinks ---@field follow? boolean follow symlinks
---@field exclude? string[] exclude patterns ---@field exclude? string[] exclude patterns
---@field args? string[] additional arguments ---@field args? string[] additional arguments
---@field rtp? boolean search in runtimepath
M.files = { M.files = {
finder = "files", finder = "files",
format = "file", format = "file",
@ -221,6 +222,7 @@ M.git_diff = {
---@field need_search? boolean require a search pattern ---@field need_search? boolean require a search pattern
---@field exclude? string[] exclude patterns ---@field exclude? string[] exclude patterns
---@field args? string[] additional arguments ---@field args? string[] additional arguments
---@field rtp? boolean search in runtimepath
M.grep = { M.grep = {
finder = "grep", finder = "grep",
format = "file", format = "file",

View file

@ -82,8 +82,12 @@ local function get_cmd(opts, filter)
end end
-- dirs -- dirs
if opts.dirs and #opts.dirs > 0 then local dirs = opts.dirs or {}
local dirs = vim.tbl_map(vim.fs.normalize, opts.dirs) ---@type string[] if opts.rtp then
vim.list_extend(dirs, Snacks.picker.util.rtp())
end
if #dirs > 0 then
dirs = vim.tbl_map(vim.fs.normalize, dirs) ---@type string[]
if is_fd and not pattern then if is_fd and not pattern then
args[#args + 1] = "." args[#args + 1] = "."
end end
@ -103,7 +107,9 @@ end
---@param opts snacks.picker.files.Config ---@param opts snacks.picker.files.Config
---@type snacks.picker.finder ---@type snacks.picker.finder
function M.files(opts, ctx) function M.files(opts, ctx)
local cwd = not (opts.dirs and #opts.dirs > 0) and vim.fs.normalize(opts and opts.cwd or uv.cwd() or ".") or nil local cwd = not (opts.rtp or (opts.dirs and #opts.dirs > 0))
and vim.fs.normalize(opts and opts.cwd or uv.cwd() or ".")
or nil
local cmd, args = get_cmd(opts, ctx.filter) local cmd, args = get_cmd(opts, ctx.filter)
return require("snacks.picker.source.proc").proc({ return require("snacks.picker.source.proc").proc({
opts, opts,

View file

@ -85,8 +85,10 @@ local function get_cmd(opts, filter)
paths[#paths + 1] = name paths[#paths + 1] = name
end end
end end
elseif opts.dirs and #opts.dirs > 0 then end
paths = opts.dirs or {} vim.list_extend(paths, opts.dirs or {})
if opts.rtp then
vim.list_extend(paths, Snacks.picker.util.rtp())
end end
-- dirs -- dirs
@ -104,7 +106,7 @@ function M.grep(opts, ctx)
if opts.need_search ~= false and ctx.filter.search == "" then if opts.need_search ~= false and ctx.filter.search == "" then
return function() end return function() end
end end
local absolute = (opts.dirs and #opts.dirs > 0) or opts.buffers local absolute = (opts.dirs and #opts.dirs > 0) or opts.buffers or opts.rtp
local cwd = not absolute and vim.fs.normalize(opts and opts.cwd or uv.cwd() or ".") or nil local cwd = not absolute and vim.fs.normalize(opts and opts.cwd or uv.cwd() or ".") or nil
local cmd, args = get_cmd(opts, ctx.filter) local cmd, args = get_cmd(opts, ctx.filter)
return require("snacks.picker.source.proc").proc({ return require("snacks.picker.source.proc").proc({

View file

@ -198,6 +198,16 @@ function M.title(str)
) )
end end
function M.rtp()
local ret = {} ---@type string[]
vim.list_extend(ret, vim.api.nvim_get_runtime_file("", true))
if package.loaded.lazy then
local extra = require("lazy.core.util").get_unloaded_rtp("")
vim.list_extend(ret, extra)
end
return ret
end
---@param str string ---@param str string
---@return string text, string[] args ---@return string text, string[] args
function M.parse(str) function M.parse(str)