mirror of
https://github.com/folke/snacks.nvim
synced 2025-07-07 21:25:11 +00:00

## 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. -->
38 lines
1.4 KiB
Lua
38 lines
1.4 KiB
Lua
local M = {}
|
|
local uv = vim.uv or vim.loop
|
|
|
|
---@class snacks.picker
|
|
---@field diagnostics fun(opts?: snacks.picker.diagnostics.Config): snacks.Picker
|
|
|
|
---@param opts snacks.picker.diagnostics.Config
|
|
---@type snacks.picker.finder
|
|
function M.diagnostics(opts, filter)
|
|
local items = {} ---@type snacks.picker.finder.Item[]
|
|
local current_buf = vim.api.nvim_get_current_buf()
|
|
local cwd = vim.fs.normalize(uv.cwd() or ".")
|
|
for _, diag in ipairs(vim.diagnostic.get(filter.buf, { severity = opts.severity })) do
|
|
local buf = diag.bufnr
|
|
if buf and vim.api.nvim_buf_is_valid(buf) then
|
|
local file = vim.fs.normalize(vim.api.nvim_buf_get_name(buf), { _fast = true })
|
|
local severity = diag.severity
|
|
severity = type(severity) == "number" and vim.diagnostic.severity[severity] or severity
|
|
---@cast severity string?
|
|
items[#items + 1] = {
|
|
text = table.concat({ severity or "", tostring(diag.code or ""), file, diag.source or "", diag.message }, " "),
|
|
file = file,
|
|
buf = diag.bufnr,
|
|
is_current = buf == current_buf and 0 or 1,
|
|
is_cwd = file:sub(1, #cwd) == cwd and 0 or 1,
|
|
lnum = diag.lnum,
|
|
severity = diag.severity,
|
|
pos = { diag.lnum + 1, diag.col + 1 },
|
|
end_pos = diag.end_lnum and { diag.end_lnum + 1, diag.end_col + 1 } or nil,
|
|
item = diag,
|
|
comment = diag.message,
|
|
}
|
|
end
|
|
end
|
|
return filter:filter(items)
|
|
end
|
|
|
|
return M
|