feat(picker): added lazy source to search for a plugin spec. Closes #680

This commit is contained in:
Folke Lemaitre 2025-01-23 13:04:00 +01:00
parent 9d5d3bdb17
commit d03bd00ced
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
2 changed files with 44 additions and 0 deletions

View file

@ -328,6 +328,13 @@ M.keymaps = {
},
}
--- Search for a lazy.nvim plugin spec
M.lazy = {
finder = "lazy_spec",
live = true,
search = "'",
}
-- Search lines in the current buffer
---@class snacks.picker.lines.Config: snacks.picker.Config
---@field buf? number

View file

@ -0,0 +1,37 @@
local M = {}
---@type snacks.picker.finder
function M.spec(opts, ctx)
local spec = require("lazy.core.config").spec
local Util = require("lazy.core.util")
local paths = {} ---@type string[]
for _, import in ipairs(spec.modules) do
Util.lsmod(import, function(modname, modpath)
paths[#paths + 1] = modpath
end)
end
local names = {} ---@type string[]
for _, frag in pairs(spec.meta.fragments.fragments) do
local name = frag.spec[1] or frag.name
if not vim.tbl_contains(names, name) then
names[#names + 1] = name
end
end
local matcher = require("snacks.picker.core.matcher").new(ctx.picker.opts.matcher)
matcher:init(ctx.filter.search)
local regex = {} ---@type string[]
for _, name in ipairs(names) do
local item = { text = name } ---@type snacks.picker.finder.Item
if matcher:match(item) > 0 then
table.insert(regex, '"' .. name .. '"')
end
end
ctx.filter.search = "^(?:(?!\\s*--)).*(?:" .. table.concat(regex, "|") .. ")"
opts = vim.tbl_extend("force", vim.deepcopy(opts), {
dirs = paths,
args = { "--pcre2" },
})
return require("snacks.picker.source.grep").grep(opts, ctx)
end
return M