2022-08-23 17:56:24 +03:00
|
|
|
return function()
|
2022-08-23 22:12:01 +03:00
|
|
|
-- Setup git completion source
|
|
|
|
require("cmp_git").setup()
|
2022-08-23 17:56:24 +03:00
|
|
|
|
2022-08-23 22:12:01 +03:00
|
|
|
-- Set completeopt to have a better completion experience
|
|
|
|
vim.o.completeopt = 'menuone,noselect'
|
2022-08-23 17:56:24 +03:00
|
|
|
|
2022-08-23 22:12:01 +03:00
|
|
|
-- luasnip setup
|
|
|
|
local luasnip = require 'luasnip'
|
2022-08-23 17:56:24 +03:00
|
|
|
|
2022-08-23 22:12:01 +03:00
|
|
|
-- nvim-cmp setup
|
|
|
|
local cmp = require 'cmp'
|
2022-09-03 00:55:10 +03:00
|
|
|
if not cmp then return end
|
|
|
|
|
2022-08-23 22:12:01 +03:00
|
|
|
cmp.setup {
|
2022-09-03 00:55:10 +03:00
|
|
|
snippet = {expand = function(args) luasnip.lsp_expand(args.body) end},
|
2022-08-23 22:12:01 +03:00
|
|
|
mapping = {
|
|
|
|
['<C-p>'] = cmp.mapping.select_prev_item(),
|
|
|
|
['<C-n>'] = cmp.mapping.select_next_item(),
|
|
|
|
['<C-d>'] = cmp.mapping.scroll_docs(-4),
|
|
|
|
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
|
|
|
['<C-Space>'] = cmp.mapping.complete(),
|
|
|
|
['<C-e>'] = cmp.mapping.close(),
|
|
|
|
['<CR>'] = cmp.mapping.confirm {
|
|
|
|
behavior = cmp.ConfirmBehavior.Replace,
|
|
|
|
select = true
|
|
|
|
},
|
|
|
|
['<Tab>'] = function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_next_item()
|
|
|
|
elseif luasnip.expand_or_jumpable() then
|
|
|
|
luasnip.expand_or_jump()
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
['<S-Tab>'] = function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_prev_item()
|
|
|
|
elseif luasnip.jumpable(-1) then
|
|
|
|
luasnip.jump(-1)
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
},
|
|
|
|
sources = {
|
2022-09-03 00:01:15 +03:00
|
|
|
{name = 'buffer'}, {name = 'git'}, {name = 'luasnip'},
|
|
|
|
{name = 'nvim_lsp'}, {name = 'nvim_lua'}, {name = 'path'}
|
2022-08-23 22:12:01 +03:00
|
|
|
}
|
|
|
|
}
|
2022-08-23 17:56:24 +03:00
|
|
|
|
2022-08-23 22:12:01 +03:00
|
|
|
-- Enable autopairs when enter is processed
|
|
|
|
-- on completion
|
|
|
|
local cmp_autopairs = require 'nvim-autopairs.completion.cmp'
|
|
|
|
cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done())
|
2022-08-23 17:56:24 +03:00
|
|
|
|
2022-08-23 22:12:01 +03:00
|
|
|
-- load friendly-snippets to luasnip
|
|
|
|
require('luasnip/loaders/from_vscode').lazy_load()
|
2022-09-03 00:55:10 +03:00
|
|
|
|
|
|
|
-- Register snippet parameter navigation keybindings
|
|
|
|
local mappings = {
|
|
|
|
['<c-j>'] = {luasnip.jump(1)},
|
|
|
|
['<c-k>'] = {luasnip.jump(-1)}
|
|
|
|
}
|
|
|
|
|
|
|
|
local wk = require('which-key')
|
|
|
|
wk.register(mappings, {mode = "n"})
|
|
|
|
wk.register(mappings, {mode = "s"})
|
2022-08-23 17:56:24 +03:00
|
|
|
end
|