refactor: use actions

This commit is contained in:
Folke Lemaitre 2024-11-11 08:57:18 +01:00
parent 3f404079dc
commit f40a2a1faa
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
7 changed files with 100 additions and 64 deletions

View file

@ -1,3 +1,10 @@
if lazyvim_docs then
-- set to `true` to follow the main branch
-- you need to have a working rust toolchain to build the plugin
-- in this case.
vim.g.lazyvim_blink_main = false
end
return {
{
"hrsh7th/nvim-cmp",
@ -5,7 +12,8 @@ return {
},
{
"saghen/blink.cmp",
version = "*",
version = not vim.g.lazyvim_blink_main and "*",
build = vim.g.lazyvim_blink_main and "cargo build --release",
opts_extend = {
"sources.completion.enabled_providers",
"sources.compat",
@ -59,11 +67,8 @@ return {
keymap = {
preset = "enter",
["<tab>"] = {
"snippet_forward",
function()
return LazyVim.cmp.ai_accept()
end,
["<Tab>"] = {
LazyVim.cmp.map({ "snippet_forward", "ai_accept" }),
"fallback",
},
},

View file

@ -1,4 +1,8 @@
return {
-- disable builtin snippet support
{ "garymjr/nvim-snippets", enabled = false },
-- add luasnip
{
"L3MON4D3/LuaSnip",
lazy = true,
@ -19,6 +23,19 @@ return {
},
},
-- add snippet_forward action
{
"L3MON4D3/LuaSnip",
opts = function()
LazyVim.cmp.actions.snippet_forward = function()
if require("luasnip").jumpable(1) then
require("luasnip").jump(1)
return true
end
end
end,
},
-- nvim-cmp integration
{
"nvim-cmp",
@ -34,23 +51,21 @@ return {
end,
-- stylua: ignore
keys = {
{
"<tab>",
function()
return require("luasnip").jumpable(1) and "<Plug>luasnip-jump-next"
or LazyVim.cmp.ai_accept()
or "<tab>"
end,
expr = true, silent = true, mode = "i",
},
{ "<tab>", function() require("luasnip").jump(1) end, mode = "s" },
{ "<s-tab>", function() require("luasnip").jump(-1) end, mode = { "i", "s" } },
},
},
{
"garymjr/nvim-snippets",
enabled = false,
},
-- TODO: blink.cmp integration
-- blink.cmp integration
{
"saghen/blink.cmp",
optional = true,
opts = {
accept = {
expand_snippet = function(...)
return require("luasnip").lsp_expand(...)
end,
},
},
},
}