feat(core)!: move a bunch of LazyVim features to snacks.nvim (#4706)

## Description

LazyVim comes with a bunch of smaller QoL plugin like features, but it's
not easy for non LazyVim users to use them.

That's why I started working on
[snacks.nvim](https://github.com/folke/snacks.nvim), a collection of
small QoL plugins for Neovim.

Snacks also includes a bunch of new improvements to these features.

This PR fully integrates with snacks.

## Todo

- [ ] add proper deprecations where needed
- [ ] create snacks docs
- [ ] document all the new improvements relevant to LazyVim users

## Closes

- [ ] #4492 
- [ ] #4333
- [ ] #4687

## Screenshots

<!-- Add screenshots of the changes if applicable. -->

## Checklist

- [ ] I've read the
[CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md)
guidelines.
This commit is contained in:
Folke Lemaitre 2024-11-07 15:54:47 +01:00 committed by GitHub
parent 75750be1c0
commit 2f4697443c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 277 additions and 1066 deletions

View file

@ -201,6 +201,7 @@ return {
library = {
{ path = "luvit-meta/library", words = { "vim%.uv" } },
{ path = "LazyVim", words = { "LazyVim" } },
{ path = "snacks.nvim", words = { "Snacks" } },
{ path = "lazy.nvim", words = { "LazyVim" } },
},
},

View file

@ -105,7 +105,7 @@ return {
},
config = function(_, opts)
local function on_move(data)
LazyVim.lsp.on_rename(data.source, data.destination)
Snacks.rename.on_rename_file(data.source, data.destination)
end
local events = require("neo-tree.events")

View file

@ -104,7 +104,7 @@ return {
vim.api.nvim_create_autocmd("User", {
pattern = "MiniFilesActionRename",
callback = function(event)
LazyVim.lsp.on_rename(event.data.from, event.data.to)
Snacks.rename.on_rename_file(event.data.from, event.data.to)
end,
})
end,

View file

@ -108,7 +108,7 @@ return {
ft = { "markdown", "norg", "rmd", "org" },
config = function(_, opts)
require("render-markdown").setup(opts)
LazyVim.toggle.map("<leader>um", {
Snacks.toggle({
name = "Render Markdown",
get = function()
return require("render-markdown.state").enabled
@ -121,7 +121,7 @@ return {
m.disable()
end
end,
})
}):map("<leader>um")
end,
},
}

View file

@ -31,14 +31,6 @@ return {
return vim.api.nvim_win_get_config(win).relative == ""
end,
},
{
ft = "lazyterm",
title = "LazyTerm",
size = { height = 0.4 },
filter = function(buf)
return not vim.b[buf].lazyterm_cmd
end,
},
"Trouble",
{ ft = "qf", title = "QuickFix" },
{
@ -103,6 +95,7 @@ return {
end
end
-- trouble
for _, pos in ipairs({ "top", "bottom", "left", "right" }) do
opts[pos] = opts[pos] or {}
table.insert(opts[pos], {
@ -116,6 +109,22 @@ return {
end,
})
end
-- snacks terminal
for _, pos in ipairs({ "top", "bottom", "left", "right" }) do
opts[pos] = opts[pos] or {}
table.insert(opts[pos], {
ft = "snacks_terminal",
size = { height = 0.4 },
title = "%{b:snacks_terminal.id}: %{b:term_title}",
filter = function(_buf, win)
return vim.w[win].snacks_win
and vim.w[win].snacks_win.position == pos
and vim.w[win].snacks_win.relative == "editor"
and not vim.w[win].trouble_preview
end,
})
end
return opts
end,
},

View file

@ -21,7 +21,7 @@ return {
end,
})
LazyVim.toggle.map("<leader>ua", {
Snacks.toggle({
name = "Mini Animate",
get = function()
return not vim.g.minianimate_disable
@ -29,7 +29,7 @@ return {
set = function(state)
vim.g.minianimate_disable = not state
end,
})
}):map("<leader>ua")
local animate = require("mini.animate")
return {

View file

@ -14,17 +14,19 @@ return {
init = function()
vim.api.nvim_create_autocmd("FileType", {
pattern = {
"Trouble",
"alpha",
"dashboard",
"fzf",
"help",
"lazy",
"lazyterm",
"mason",
"neo-tree",
"notify",
"snacks_notif",
"snacks_terminal",
"snacks_win",
"toggleterm",
"Trouble",
"trouble",
},
callback = function()

View file

@ -4,8 +4,7 @@ return {
event = "VeryLazy",
opts = function()
local tsc = require("treesitter-context")
LazyVim.toggle.map("<leader>ut", {
Snacks.toggle({
name = "Treesitter Context",
get = tsc.enabled,
set = function(state)
@ -15,8 +14,7 @@ return {
tsc.disable()
end
end,
})
}):map("<leader>ut")
return { mode = "cursor", max_lines = 3 }
end,
}

View file

@ -8,14 +8,14 @@ return {
{
"<leader>gG",
function()
LazyVim.terminal.open({ "gitui" }, { esc_esc = false, ctrl_hjkl = false })
Snacks.terminal({ "gitui" })
end,
desc = "GitUi (cwd)",
},
{
"<leader>gg",
function()
LazyVim.terminal.open({ "gitui" }, { cwd = LazyVim.root.get(), esc_esc = false, ctrl_hjkl = false })
Snacks.terminal({ "gitui" }, { cwd = LazyVim.root.get() })
end,
desc = "GitUi (Root Dir)",
},

View file

@ -10,7 +10,48 @@ end
require("lazyvim.config").init()
-- Terminal Mappings
local function term_nav(dir)
---@param self snacks.terminal
return function(self)
return self:is_floating() and "<c-" .. dir .. ">" or vim.schedule(function()
vim.cmd.wincmd(dir)
end)
end
end
return {
{ "folke/lazy.nvim", version = "*" },
{ "LazyVim/LazyVim", priority = 10000, lazy = false, opts = {}, cond = true, version = "*" },
{
"folke/snacks.nvim",
priority = 1000,
lazy = false,
opts = function()
---@type snacks.Config
return {
toggle = { map = LazyVim.safe_keymap_set },
notifier = { enabled = not LazyVim.has("noice.nvim") },
terminal = {
win = {
keys = {
nav_h = { "<C-h>", term_nav("h"), desc = "Go to Left Window", expr = true, mode = "t" },
nav_j = { "<C-j>", term_nav("j"), desc = "Go to Lower Window", expr = true, mode = "t" },
nav_k = { "<C-k>", term_nav("k"), desc = "Go to Upper Window", expr = true, mode = "t" },
nav_l = { "<C-l>", term_nav("l"), desc = "Go to Right Window", expr = true, mode = "t" },
},
},
},
}
end,
keys = {
{
"<leader>un",
function()
Snacks.notifier.hide()
end,
desc = "Dismiss All Notifications",
},
},
},
}

View file

@ -129,8 +129,6 @@ return {
LazyVim.lsp.setup()
LazyVim.lsp.on_dynamic_capability(require("lazyvim.plugins.lsp.keymaps").on_attach)
LazyVim.lsp.words.setup(opts.document_highlight)
-- diagnostics signs
if vim.fn.has("nvim-0.10.0") == 0 then
if type(opts.diagnostics.signs) ~= "boolean" then

View file

@ -25,17 +25,17 @@ function M.get()
{ "<leader>ca", vim.lsp.buf.code_action, desc = "Code Action", mode = { "n", "v" }, has = "codeAction" },
{ "<leader>cc", vim.lsp.codelens.run, desc = "Run Codelens", mode = { "n", "v" }, has = "codeLens" },
{ "<leader>cC", vim.lsp.codelens.refresh, desc = "Refresh & Display Codelens", mode = { "n" }, has = "codeLens" },
{ "<leader>cR", LazyVim.lsp.rename_file, desc = "Rename File", mode ={"n"}, has = { "workspace/didRenameFiles", "workspace/willRenameFiles" } },
{ "<leader>cR", function() Snacks.rename.rename_file() end, desc = "Rename File", mode ={"n"}, has = { "workspace/didRenameFiles", "workspace/willRenameFiles" } },
{ "<leader>cr", vim.lsp.buf.rename, desc = "Rename", has = "rename" },
{ "<leader>cA", LazyVim.lsp.action.source, desc = "Source Action", has = "codeAction" },
{ "]]", function() LazyVim.lsp.words.jump(vim.v.count1) end, has = "documentHighlight",
desc = "Next Reference", cond = function() return LazyVim.lsp.words.enabled end },
{ "[[", function() LazyVim.lsp.words.jump(-vim.v.count1) end, has = "documentHighlight",
desc = "Prev Reference", cond = function() return LazyVim.lsp.words.enabled end },
{ "<a-n>", function() LazyVim.lsp.words.jump(vim.v.count1, true) end, has = "documentHighlight",
desc = "Next Reference", cond = function() return LazyVim.lsp.words.enabled end },
{ "<a-p>", function() LazyVim.lsp.words.jump(-vim.v.count1, true) end, has = "documentHighlight",
desc = "Prev Reference", cond = function() return LazyVim.lsp.words.enabled end },
{ "]]", function() Snacks.words.jump(vim.v.count1) end, has = "documentHighlight",
desc = "Next Reference", cond = function() return Snacks.words.is_enabled() end },
{ "[[", function() Snacks.words.jump(-vim.v.count1) end, has = "documentHighlight",
desc = "Prev Reference", cond = function() return Snacks.words.is_enabled() end },
{ "<a-n>", function() Snacks.words.jump(vim.v.count1, true) end, has = "documentHighlight",
desc = "Next Reference", cond = function() return Snacks.words.is_enabled() end },
{ "<a-p>", function() Snacks.words.jump(-vim.v.count1, true) end, has = "documentHighlight",
desc = "Prev Reference", cond = function() return Snacks.words.is_enabled() end },
}
return M._keys

View file

@ -1,39 +1,4 @@
return {
-- Better `vim.notify()`
{
"rcarriga/nvim-notify",
keys = {
{
"<leader>un",
function()
require("notify").dismiss({ silent = true, pending = true })
end,
desc = "Dismiss All Notifications",
},
},
opts = {
stages = "static",
timeout = 3000,
max_height = function()
return math.floor(vim.o.lines * 0.75)
end,
max_width = function()
return math.floor(vim.o.columns * 0.75)
end,
on_open = function(win)
vim.api.nvim_win_set_config(win, { zindex = 100 })
end,
},
init = function()
-- when noice is not enabled, install notify on VeryLazy
if not LazyVim.has("noice.nvim") then
LazyVim.on_very_lazy(function()
vim.notify = require("notify")
end)
end
end,
},
-- This is what powers LazyVim's fancy-looking
-- tabs, which include filetype icons and close buttons.
{
@ -55,9 +20,9 @@ return {
opts = {
options = {
-- stylua: ignore
close_command = function(n) LazyVim.ui.bufremove(n) end,
close_command = function(n) Snacks.bufdelete(n) end,
-- stylua: ignore
right_mouse_command = function(n) LazyVim.ui.bufremove(n) end,
right_mouse_command = function(n) Snacks.bufdelete(n) end,
diagnostics = "nvim_lsp",
always_show_bufferline = false,
diagnostics_indicator = function(_, _, diag)
@ -226,7 +191,7 @@ return {
"lukas-reineke/indent-blankline.nvim",
event = "LazyFile",
opts = function()
LazyVim.toggle.map("<leader>ug", {
Snacks.toggle({
name = "Indention Guides",
get = function()
return require("ibl.config").get_config(0).enabled
@ -234,7 +199,7 @@ return {
set = function(state)
require("ibl").setup_buffer(0, { enabled = state })
end,
})
}):map("<leader>ug")
return {
indent = {
@ -244,17 +209,19 @@ return {
scope = { show_start = false, show_end = false },
exclude = {
filetypes = {
"help",
"Trouble",
"alpha",
"dashboard",
"neo-tree",
"Trouble",
"trouble",
"help",
"lazy",
"mason",
"neo-tree",
"notify",
"snacks_notif",
"snacks_terminal",
"snacks_win",
"toggleterm",
"lazyterm",
"trouble",
},
},
}