mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-05 03:08:13 +00:00
feat(picker): added opts.rtp
(bool) to find/grep over files in the rtp. See #680
This commit is contained in:
parent
3fb111090e
commit
9d5d3bdb17
4 changed files with 26 additions and 6 deletions
|
@ -121,6 +121,7 @@ M.diagnostics_buffer = {
|
|||
---@field follow? boolean follow symlinks
|
||||
---@field exclude? string[] exclude patterns
|
||||
---@field args? string[] additional arguments
|
||||
---@field rtp? boolean search in runtimepath
|
||||
M.files = {
|
||||
finder = "files",
|
||||
format = "file",
|
||||
|
@ -221,6 +222,7 @@ M.git_diff = {
|
|||
---@field need_search? boolean require a search pattern
|
||||
---@field exclude? string[] exclude patterns
|
||||
---@field args? string[] additional arguments
|
||||
---@field rtp? boolean search in runtimepath
|
||||
M.grep = {
|
||||
finder = "grep",
|
||||
format = "file",
|
||||
|
|
|
@ -82,8 +82,12 @@ local function get_cmd(opts, filter)
|
|||
end
|
||||
|
||||
-- dirs
|
||||
if opts.dirs and #opts.dirs > 0 then
|
||||
local dirs = vim.tbl_map(vim.fs.normalize, opts.dirs) ---@type string[]
|
||||
local dirs = opts.dirs or {}
|
||||
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
|
||||
args[#args + 1] = "."
|
||||
end
|
||||
|
@ -103,7 +107,9 @@ end
|
|||
---@param opts snacks.picker.files.Config
|
||||
---@type snacks.picker.finder
|
||||
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)
|
||||
return require("snacks.picker.source.proc").proc({
|
||||
opts,
|
||||
|
|
|
@ -85,8 +85,10 @@ local function get_cmd(opts, filter)
|
|||
paths[#paths + 1] = name
|
||||
end
|
||||
end
|
||||
elseif opts.dirs and #opts.dirs > 0 then
|
||||
paths = opts.dirs or {}
|
||||
end
|
||||
vim.list_extend(paths, opts.dirs or {})
|
||||
if opts.rtp then
|
||||
vim.list_extend(paths, Snacks.picker.util.rtp())
|
||||
end
|
||||
|
||||
-- dirs
|
||||
|
@ -104,7 +106,7 @@ function M.grep(opts, ctx)
|
|||
if opts.need_search ~= false and ctx.filter.search == "" then
|
||||
return function() 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 cmd, args = get_cmd(opts, ctx.filter)
|
||||
return require("snacks.picker.source.proc").proc({
|
||||
|
|
|
@ -198,6 +198,16 @@ function M.title(str)
|
|||
)
|
||||
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
|
||||
---@return string text, string[] args
|
||||
function M.parse(str)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue