mirror of
https://github.com/iofq/nvim.nix.git
synced 2026-01-23 08:55:16 -06:00
98 lines
2.7 KiB
Lua
98 lines
2.7 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,
|
|
},
|
|
experimental = {
|
|
native_menu = false,
|
|
ghost_text = true,
|
|
},
|
|
mapping = cmp.mapping.preset.insert {
|
|
['<C-j>'] = cmp.mapping.scroll_docs(-4),
|
|
['<C-k>'] = cmp.mapping.scroll_docs(4),
|
|
['<C-Space>'] = cmp.mapping.complete(),
|
|
['<esc>'] = cmp.mapping.abort(),
|
|
['<CR>'] = cmp.mapping.confirm { select = true }, -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
|
|
},
|
|
sources = cmp.config.sources({
|
|
{ name = 'nvim_lsp' },
|
|
{ name = 'luasnip' },
|
|
}, {
|
|
{ name = 'buffer' },
|
|
}),
|
|
}
|
|
|
|
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 = '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-K>', function()
|
|
if ls.expand_or_jumpable() then
|
|
ls.expand_or_jump()
|
|
end
|
|
end, { silent = true })
|
|
|
|
vim.keymap.set({ 'i', 's' }, '<C-J>', 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 })
|
|
|
|
--------------------
|
|
-- Snippets --
|
|
--------------------
|
|
local fmta = require('luasnip.extras.fmt').fmta
|
|
ls.add_snippets('go', {
|
|
ls.snippet('ie', fmta('if err != nil {\n\treturn <err>\n}', { err = ls.insert_node(1, 'err') })),
|
|
})
|
|
end,
|
|
},
|
|
}
|