change cmp a bit

This commit is contained in:
Thomas Ruoff
2023-07-13 10:00:40 +02:00
parent 8650623c40
commit ee49d68ad3

View File

@@ -1,61 +1,87 @@
return { return {
'hrsh7th/nvim-cmp', 'hrsh7th/nvim-cmp',
dependencies = { 'hrsh7th/cmp-nvim-lsp', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip', 'onsails/lspkind.nvim' }, dependencies = {
'L3MON4D3/LuaSnip',
'hrsh7th/cmp-nvim-lsp-signature-help',
'hrsh7th/cmp-nvim-lsp',
'hrsh7th/cmp-buffer',
'hrsh7th/cmp-path',
'saadparwaiz1/cmp_luasnip',
'hrsh7th/cmp-nvim-lua',
'windwp/nvim-autopairs',
'onsails/lspkind-nvim',
},
event = 'InsertEnter',
config = function() config = function()
local cmp = require 'cmp' local cmp = require 'cmp'
local luasnip = require 'luasnip' local lsp_kind = require 'lspkind'
local lspkind = require 'lspkind' local cmp_next = function(fallback)
if cmp.visible() then
luasnip.config.setup {} cmp.select_next_item()
elseif require('luasnip').expand_or_jumpable() then
vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-expand-or-jump', true, true, true), '')
else
fallback()
end
end
local cmp_prev = function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif require('luasnip').jumpable(-1) then
vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-jump-prev', true, true, true), '')
else
fallback()
end
end
lsp_kind.init()
cmp.setup { cmp.setup {
formatting = { window = {
format = lspkind.cmp_format { completion = cmp.config.window.bordered {
mode = 'symbol', winhighlight = 'Normal:Normal,FloatBorder:LspBorderBG,CursorLine:PmenuSel,Search:None',
maxwidth = 100,
ellipsis_char = '...',
}, },
documentation = cmp.config.window.bordered {
winhighlight = 'Normal:Normal,FloatBorder:LspBorderBG,CursorLine:PmenuSel,Search:None',
},
},
view = {
entries = 'bordered',
}, },
snippet = { snippet = {
expand = function(args) expand = function(args)
luasnip.lsp_expand(args.body) require('luasnip').lsp_expand(args.body)
end, end,
}, },
mapping = cmp.mapping.preset.insert { mapping = {
['<C-d>'] = cmp.mapping.scroll_docs(-4), ['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4), ['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete {}, ['<S-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm { ['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace, behavior = cmp.ConfirmBehavior.Replace,
select = true, select = true,
}, },
['<Tab>'] = cmp.mapping(function(fallback) ['<tab>'] = cmp_next,
if cmp.visible() then ['<down>'] = cmp_next,
cmp.select_next_item() ['<C-p>'] = cmp_prev,
elseif luasnip.expand_or_jumpable() then ['<up>'] = cmp_prev,
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 = { sources = {
{ name = 'neorg' }, { name = 'nvim_lsp_signature_help', group_index = 1 },
{ name = 'nvim_lsp' }, { name = 'luasnip', max_item_count = 5, group_index = 1 },
{ name = 'luasnip' }, { name = 'nvim_lsp', max_item_count = 20, group_index = 1 },
{ name = 'nvim_lua', group_index = 1 },
{ name = 'path', group_index = 2 },
{ name = 'buffer', keyword_length = 2, max_item_count = 5, group_index = 2 },
}, },
} }
local presentAutopairs, cmp_autopairs = pcall(require, 'nvim-autopairs.completion.cmp')
if not presentAutopairs then
return
end
cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done { map_char = { tex = '' } })
-- nvim-cmp supports additional completion capabilities, so broadcast that to servers -- nvim-cmp supports additional completion capabilities, so broadcast that to servers
local capabilities = vim.lsp.protocol.make_client_capabilities() -- local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) -- capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
end, end,
} }