mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-05 11:18:26 +00:00
feat(picker.lazy): don't use grep
. Parse spec files manually. Closes #972
This commit is contained in:
parent
698daf7cdf
commit
09280078e8
2 changed files with 18 additions and 15 deletions
|
@ -403,7 +403,6 @@ M.keymaps = {
|
||||||
--- Search for a lazy.nvim plugin spec
|
--- Search for a lazy.nvim plugin spec
|
||||||
M.lazy = {
|
M.lazy = {
|
||||||
finder = "lazy_spec",
|
finder = "lazy_spec",
|
||||||
live = false,
|
|
||||||
pattern = "'",
|
pattern = "'",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ function M.spec(opts, ctx)
|
||||||
local Util = require("lazy.core.util")
|
local Util = require("lazy.core.util")
|
||||||
local paths = {} ---@type string[]
|
local paths = {} ---@type string[]
|
||||||
for _, import in ipairs(spec.modules) do
|
for _, import in ipairs(spec.modules) do
|
||||||
Util.lsmod(import, function(modname, modpath)
|
Util.lsmod(import, function(_, modpath)
|
||||||
paths[#paths + 1] = modpath
|
paths[#paths + 1] = modpath
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
@ -17,21 +17,25 @@ function M.spec(opts, ctx)
|
||||||
names[#names + 1] = name
|
names[#names + 1] = name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local matcher = require("snacks.picker.core.matcher").new(ctx.picker.opts.matcher)
|
local regex = "\\M\\['\"]\\(" .. table.concat(names, "\\|") .. "\\)\\['\"]"
|
||||||
matcher:init(ctx.filter.search)
|
local re = vim.regex(regex)
|
||||||
local regex = {} ---@type string[]
|
local ret = {} ---@type snacks.picker.finder.Item[]
|
||||||
for _, name in ipairs(names) do
|
for _, path in ipairs(paths) do
|
||||||
local item = { text = name } ---@type snacks.picker.finder.Item
|
local lines = Snacks.picker.util.lines(path)
|
||||||
if matcher:match(item) > 0 then
|
for l, line in ipairs(lines) do
|
||||||
table.insert(regex, '"' .. name .. '"')
|
local from, to = re:match_str(line)
|
||||||
|
if from then
|
||||||
|
ret[#ret + 1] = {
|
||||||
|
file = path,
|
||||||
|
line = line,
|
||||||
|
text = line,
|
||||||
|
pos = { l, from },
|
||||||
|
end_pos = { l, to },
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
ctx.filter.search = "^(?:(?!\\s*--)).*(?:" .. table.concat(regex, "|") .. ")"
|
end
|
||||||
opts = vim.tbl_extend("force", vim.deepcopy(opts), {
|
return ret
|
||||||
dirs = paths,
|
|
||||||
args = { "--pcre2" },
|
|
||||||
})
|
|
||||||
return require("snacks.picker.source.grep").grep(opts, ctx)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue