Dotfiles/nvim/lua/plugins/code-snippets.lua
2024-02-24 20:53:17 +01:00

71 lines
1.8 KiB
Lua

return {
{
"L3MON4D3/LuaSnip",
version = "2.*",
dependencies = {
"rafamadriz/friendly-snippets",
"mireq/luasnip-snippets",
},
build = "make install_jsregexp",
config = function()
-- Setup --
require("luasnip.loaders.from_vscode").lazy_load()
require("luasnip.loaders.from_snipmate").lazy_load()
require("luasnip_snippets.common.snip_utils").setup()
end,
},
{
"hrsh7th/nvim-cmp",
dependencies = {
"L3MON4D3/LuaSnip",
"saadparwaiz1/cmp_luasnip",
"hrsh7th/cmp-nvim-lsp",
},
config = function()
-- Setup --
local cmp = require("cmp")
local luasnip = require("luasnip")
luasnip.setup({
load_ft_func = require("luasnip_snippets.common.snip_utils").load_ft_func,
ft_func = require("luasnip_snippets.common.snip_utils").ft_func,
enable_autosnippets = true,
})
-- Keybinding --
vim.keymap.set({ "i", "s" }, "<Tab>", function()
if luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
vim.api.nvim_input("<C-V><Tab>")
end
end, { silent = true })
vim.keymap.set({ "i", "s" }, "<S-Tab>", function()
luasnip.jump(-1)
end, { silent = true })
-- Setup --
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
-- Keybinding --
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = true }),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" },
}, { { name = "buffer" } }),
})
end,
},
}