Files
dotfiles/config/nvim/lua/plugins/cmp.lua

108 lines
3.1 KiB
Lua

return {
-- Autocompletion
-- https://github.com/hrsh7th/nvim-cmp
{
'hrsh7th/nvim-cmp',
event = 'InsertEnter',
dependencies = {
'hrsh7th/cmp-nvim-lsp',
'L3MON4D3/LuaSnip',
'saadparwaiz1/cmp_luasnip',
-- Adds other completion capabilities.
-- nvim-cmp does not ship with all sources by default. They are split
-- into multiple repos for maintenance purposes.
'hrsh7th/cmp-nvim-lsp',
'hrsh7th/cmp-path',
'onsails/lspkind.nvim',
{
'zbirenbaum/copilot-cmp',
dependencies = {
{
'zbirenbaum/copilot.lua',
cmd = 'Copilot',
build = ':Copilot setup',
event = { 'InsertEnter', 'LspAttach' },
fix_pairs = true,
opts = {
suggestion = { enabled = false },
panel = { enabled = false },
filetypes = {
markdown = true,
help = true,
},
},
}
},
config = function()
require('copilot_cmp').setup()
end,
},
},
config = function()
local cmp = require 'cmp'
local luasnip = require 'luasnip'
local lspkind = require 'lspkind'
luasnip.config.setup {}
cmp.setup {
formatting = {
format = lspkind.cmp_format {
mode = 'symbol',
min_width = 40,
max_width = 100,
symbol_map = {
Copilot = ''
},
},
},
view = {
entries = 'native',
},
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert {
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
-- Manually trigger a completion from nvim-cmp.
-- Generally you don't need this, because nvim-cmp will display
-- completions whenever it has completion options available.
['<C-Space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
},
sources = {
-- Copilot Source
{ name = 'copilot', group_index = 2 },
-- Other Sources
{ name = 'nvim_lsp', group_index = 2 },
{ name = 'path', group_index = 2 },
{ name = 'luasnip', group_index = 2 },
},
}
end,
},
}