mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-05 19:28:24 +00:00
feat(picker): added lazy
source to search for a plugin spec. Closes #680
This commit is contained in:
parent
9d5d3bdb17
commit
d03bd00ced
2 changed files with 44 additions and 0 deletions
|
@ -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
|
||||
|
|
37
lua/snacks/picker/source/lazy.lua
Normal file
37
lua/snacks/picker/source/lazy.lua
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue