snacks.nvim/lua/snacks/picker/source/meta.lua
Folke Lemaitre 559d6c6bf2
feat(snacks): added snacks.picker (#445)
## Description

More info coming tomorrow.

In short:
- very fast. pretty much realtime filtering/sorting in huge repos (like
1.7 million files)
- extensible
- easy to customize the layout (and lots of presets) with
`snacks.layout`
- simple to create custom pickers
- `vim.ui.select`
- lots of builtin pickers
- uses treesitter highlighting wherever it makes sense
- fast lua fuzzy matcher which supports the [fzf
syntax](https://junegunn.github.io/fzf/search-syntax/) and additionally
supports field filters, like `file:lua$ 'function`

There's no snacks picker command, just use lua.

```lua
-- all pickers
Snacks.picker()

-- run files picker
Snacks.picker.files(opts)
Snacks.picker.pick("files", opts)
Snacks.picker.pick({source = "files", ...})
```

<!-- Describe the big picture of your changes to communicate to the
maintainers
  why we should accept this pull request. -->

## Todo
- [x] issue with preview loc not always correct when scrolling fast in
list (probably due to `snacks.scroll`)
- [x] `grep` (`live_grep`) is sometimes too fast in large repos and can
impact ui rendering. Not very noticeable, but something I want to look
at.
- [x] docs
- [x] treesitter highlights are broken. Messed something up somewhere

## Related Issue(s)

<!--
  If this PR fixes any issues, please link to the issue here.
  - Fixes #<issue_number>
-->

## Screenshots

<!-- Add screenshots of the changes if applicable. -->
2025-01-14 22:53:59 +01:00

46 lines
1.1 KiB
Lua

local M = {}
---@class snacks.picker
---@field pickers fun(opts?: snacks.picker.Config): snacks.Picker
---@param file string
---@param t table<string,unknown>
function M.table(file, t)
file = Snacks.meta.file(file)
local values = vim.tbl_keys(t)
table.sort(values)
---@param value string
return vim.tbl_map(function(value)
return {
file = file,
text = value,
search = ("/^M\\.%s = \\|function M\\.%s("):format(value, value),
}
end, values)
end
---@param opts snacks.picker.Config
---@type snacks.picker.finder
function M.pickers(opts)
return M.table("picker/config/sources.lua", opts.sources or {})
end
---@param opts snacks.picker.Config
---@type snacks.picker.finder
function M.layouts(opts)
return M.table("picker/config/layouts.lua", opts.layouts or {})
end
function M.actions()
return M.table("picker/actions.lua", require("snacks.picker.actions"))
end
function M.preview()
return M.table("picker/preview.lua", require("snacks.picker.preview"))
end
function M.format()
return M.table("picker/format.lua", require("snacks.picker.format"))
end
return M