nvim.nix/nvim/lua/plugins/completion.lua
2024-08-22 03:30:25 -05:00

90 lines
2.5 KiB
Lua

return {
{
'hrsh7th/nvim-cmp',
event = 'VeryLazy',
dependencies = {
'hrsh7th/cmp-buffer',
'hrsh7th/cmp-cmdline',
'hrsh7th/cmp-path',
'hrsh7th/cmp-nvim-lsp',
'ray-x/cmp-treesitter',
'L3MON4D3/LuaSnip',
'saadparwaiz1/cmp_luasnip',
},
config = function()
local cmp = require('cmp')
cmp.setup {
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert {
['<C-u>'] = cmp.mapping.scroll_docs(-4),
['<C-d>'] = cmp.mapping.scroll_docs(4),
['<C-n>'] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Insert },
['<C-p>'] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Insert },
['<C-Space>'] = cmp.mapping.confirm {
select = true,
behavior = cmp.SelectBehavior.Insert
},
},
sources = cmp.config.sources({
{ name = 'nvim_lsp', keyword_length = 1 },
{ name = 'luasnip' },
{ name = 'buffer' },
{ name = 'path' },
{ name = 'treesitter', keyword_length = 3 },
}),
}
cmp.setup.cmdline({ '/', '?' }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' },
},
})
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' },
{ name = 'buffer' },
{ name = 'cmdline' },
}),
matching = { disallow_symbol_nonprefix_matching = false },
})
end,
},
{
'L3MON4D3/LuaSnip',
event = 'VeryLazy',
dependencies = { 'rafamadriz/friendly-snippets' },
config = function()
local ls = require('luasnip')
ls.config.set_config {
history = true,
updateevents = 'TextChanged, TextChangedI',
}
require('luasnip.loaders.from_vscode').lazy_load()
vim.keymap.set({ 'i', 's' }, '<C-J>', function()
if ls.expand_or_jumpable() then
ls.expand_or_jump()
end
end, { silent = true })
vim.keymap.set({ 'i', 's' }, '<C-K>', function()
if ls.jumpable(-1) then
ls.jump(-1)
end
end, { silent = true })
vim.keymap.set({ 'i', 's' }, '<C-L>', function()
if ls.choice_active() then
ls.change_choice(1)
end
end, { silent = true })
end,
},
}