feat(extras): added extra for snacks picker (#5368)

## Description

See https://github.com/folke/snacks.nvim/pull/445

NOTE: I'm **not** going to replace `fzf-lua` anytime soon. Learned my
lessons with that one :)

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

## 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. -->

## Checklist

- [x] I've read the
[CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md)
guidelines.
This commit is contained in:
Folke Lemaitre 2025-01-14 22:54:12 +01:00 committed by GitHub
parent d1529f650f
commit 13044c298e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 147 additions and 6 deletions

View file

@ -150,12 +150,12 @@ end
if vim.fn.executable("lazygit") == 1 then
map("n", "<leader>gg", function() Snacks.lazygit( { cwd = LazyVim.root.git() }) end, { desc = "Lazygit (Root Dir)" })
map("n", "<leader>gG", function() Snacks.lazygit() end, { desc = "Lazygit (cwd)" })
map("n", "<leader>gf", function() Snacks.lazygit.log_file() end, { desc = "Lazygit Current File History" })
map("n", "<leader>gl", function() Snacks.lazygit.log({ cwd = LazyVim.root.git() }) end, { desc = "Lazygit Log" })
map("n", "<leader>gL", function() Snacks.lazygit.log() end, { desc = "Lazygit Log (cwd)" })
map("n", "<leader>gf", function() Snacks.picker.git_log_file() end, { desc = "Git Current File History" })
map("n", "<leader>gl", function() Snacks.picker.git_log({ cwd = LazyVim.root.git() }) end, { desc = "Git Log" })
map("n", "<leader>gL", function() Snacks.picker.git_log() end, { desc = "Git Log (cwd)" })
end
map("n", "<leader>gb", function() Snacks.git.blame_line() end, { desc = "Git Blame Line" })
map("n", "<leader>gb", function() Snacks.picker.git_log_line() end, { desc = "Git Blame Line" })
map({ "n", "x" }, "<leader>gB", function() Snacks.gitbrowse() end, { desc = "Git Browse (open)" })
map({"n", "x" }, "<leader>gY", function()
Snacks.gitbrowse({ open = function(url) vim.fn.setreg("+", url) end, notify = false })

View file

@ -397,4 +397,10 @@ return {
return LazyVim.pick.want() == "telescope"
end,
},
{
import = "lazyvim.plugins.extras.editor.snacks_picker",
enabled = function()
return LazyVim.pick.want() == "snacks"
end,
},
}

View file

@ -286,6 +286,9 @@ return {
{
"neovim/nvim-lspconfig",
opts = function()
if LazyVim.pick.want() ~= "fzf" then
return
end
local Keys = require("lazyvim.plugins.lsp.keymaps").get()
-- stylua: ignore
vim.list_extend(Keys, {

View file

@ -0,0 +1,127 @@
if lazyvim_docs then
-- In case you don't want to use `:LazyExtras`,
-- then you need to set the option below.
vim.g.lazyvim_picker = "snacks"
end
---@module 'snacks'
---@type LazyPicker
local picker = {
name = "snacks",
commands = {
files = "files",
live_grep = "grep",
oldfiles = "recent",
},
---@param source string
---@param opts? snacks.picker.Config
open = function(source, opts)
return Snacks.picker.pick(source, opts)
end,
}
if not LazyVim.pick.register(picker) then
return {}
end
return {
desc = "Fast and modern file picker",
-- recommended = true,
{
"folke/snacks.nvim",
opts = {
picker = {},
},
-- stylua: ignore
keys = {
{ "<leader>,", function() Snacks.picker.buffers() end, desc = "Buffers" },
{ "<leader>/", LazyVim.pick("grep"), desc = "Grep (Root Dir)" },
{ "<leader>:", function() Snacks.picker.command_history() end, desc = "Command History" },
{ "<leader><space>", LazyVim.pick("files"), desc = "Find Files (Root Dir)" },
-- find
{ "<leader>fb", function() Snacks.picker.buffers() end, desc = "Buffers" },
{ "<leader>fc", LazyVim.pick.config_files(), desc = "Find Config File" },
{ "<leader>ff", LazyVim.pick("files"), desc = "Find Files (Root Dir)" },
{ "<leader>fF", LazyVim.pick("files", { root = false }), desc = "Find Files (cwd)" },
{ "<leader>fg", function() Snacks.picker.git_files() end, desc = "Find Files (git-files)" },
{ "<leader>fr", LazyVim.pick("oldfiles"), desc = "Recent" },
{ "<leader>fR", LazyVim.pick("oldfiles", { only_cwd = true }), desc = "Recent (cwd)" },
-- git
{ "<leader>gc", function() Snacks.picker.git_log() end, desc = "Git Log" },
{ "<leader>gs", function() Snacks.picker.git_status() end, desc = "Git Status" },
-- Grep
{ "<leader>sb", function() Snacks.picker.lines() end, desc = "Buffer Lines" },
{ "<leader>sB", function() Snacks.picker.grep_buffers() end, desc = "Grep Open Buffers" },
{ "<leader>sg", LazyVim.pick("live_grep"), desc = "Grep (Root Dir)" },
{ "<leader>sG", LazyVim.pick("live_grep", { root = false }), desc = "Grep (cwd)" },
{ "<leader>sw", LazyVim.pick("grep_word"), desc = "Visual selection or word (Root Dir)", mode = { "n", "x" } },
{ "<leader>sW", LazyVim.pick("grep_word", { root = false }), desc = "Visual selection or word (cwd)", mode = { "n", "x" } },
-- search
{ '<leader>s"', function() Snacks.picker.registers() end, desc = "Registers" },
{ "<leader>sa", function() Snacks.picker.autocmds() end, desc = "Autocmds" },
{ "<leader>sc", function() Snacks.picker.command_history() end, desc = "Command History" },
{ "<leader>sC", function() Snacks.picker.commands() end, desc = "Commands" },
{ "<leader>sd", function() Snacks.picker.diagnostics() end, desc = "Diagnostics" },
{ "<leader>sh", function() Snacks.picker.help() end, desc = "Help Pages" },
{ "<leader>sH", function() Snacks.picker.highlights() end, desc = "Highlights" },
{ "<leader>sj", function() Snacks.picker.jumps() end, desc = "Jumps" },
{ "<leader>sk", function() Snacks.picker.keymaps() end, desc = "Keymaps" },
{ "<leader>sl", function() Snacks.picker.loclist() end, desc = "Location List" },
{ "<leader>sM", function() Snacks.picker.man() end, desc = "Man Pages" },
{ "<leader>sm", function() Snacks.picker.marks() end, desc = "Marks" },
{ "<leader>sR", function() Snacks.picker.resume() end, desc = "Resume" },
{ "<leader>sq", function() Snacks.picker.qflist() end, desc = "Quickfix List" },
{ "<leader>uC", function() Snacks.picker.colorschemes() end, desc = "Colorschemes" },
{ "<leader>qp", function() Snacks.picker.projects() end, desc = "Projects" },
},
},
{
"folke/snacks.nvim",
opts = function(_, opts)
if LazyVim.has("trouble.nvim") then
return vim.tbl_deep_extend("force", opts or {}, {
picker = {
actions = require("trouble.sources.snacks").actions,
win = {
input = {
keys = {
["<c-t>"] = {
"trouble_open",
mode = { "n", "i" },
},
},
},
},
},
})
end
end,
},
{
"neovim/nvim-lspconfig",
opts = function()
if LazyVim.pick.want() ~= "snacks" then
return
end
local Keys = require("lazyvim.plugins.lsp.keymaps").get()
-- stylua: ignore
vim.list_extend(Keys, {
{ "gd", function() Snacks.picker.lsp_definitions() end, desc = "Goto Definition", has = "definition" },
{ "gr", function() Snacks.picker.lsp_references() end, nowait = true, desc = "References" },
{ "gI", function() Snacks.picker.lsp_implementations() end, desc = "Goto Implementation" },
{ "gy", function() Snacks.picker.lsp_type_definitions() end, desc = "Goto T[y]pe Definition" },
{ "<leader>ss", function() Snacks.picker.lsp_symbols() end, desc = "LSP Symbols", has = "documentSymbol" },
})
end,
},
{
"folke/todo-comments.nvim",
optional = true,
-- stylua: ignore
keys = {
{ "<leader>st", function() Snacks.picker.todo_comments() end, desc = "Todo" },
{ "<leader>sT", function () Snacks.picker.todo_comments({ keywords = { "TODO", "FIX", "FIXME" } }) end, desc = "Todo/Fix/Fixme" },
},
},
}

View file

@ -288,6 +288,9 @@ return {
opts = {
dashboard = {
preset = {
pick = function(cmd, opts)
return LazyVim.pick(cmd, opts)()
end,
header = [[
Z
Z

View file

@ -42,11 +42,13 @@ function M.register(picker)
return true
end
---@return "telescope" | "fzf"
---@return "telescope" | "fzf" | "snacks"
function M.want()
vim.g.lazyvim_picker = vim.g.lazyvim_picker or "auto"
if vim.g.lazyvim_picker == "auto" then
return LazyVim.has_extra("editor.telescope") and "telescope" or "fzf"
return LazyVim.has_extra("editor.snacks_picker") and "snacks"
or LazyVim.has_extra("editor.telescope") and "telescope"
or "fzf"
end
return vim.g.lazyvim_picker
end