cmp supporting newline

This commit is contained in:
Barak Michener 2024-08-07 15:37:47 -07:00
parent 1bbd7f5e6c
commit 9165e6dad8

View file

@ -43,68 +43,75 @@ local lspkind = require('lspkind')
cmp.setup({ cmp.setup({
snippet = { snippet = {
-- REQUIRED - you must specify a snippet engine -- REQUIRED - you must specify a snippet engine
expand = function(args) expand = function(args)
require('snippy').expand_snippet(args.body) -- For `snippy` users. require('snippy').expand_snippet(args.body) -- For `snippy` users.
-- vim.snippet.expand(args.body) -- For native neovim snippets (Neovim v0.10+) -- vim.snippet.expand(args.body) -- For native neovim snippets (Neovim v0.10+)
end, end,
}, },
formatting = { formatting = {
format = lspkind.cmp_format({ format = lspkind.cmp_format({
mode = 'symbol_text', -- show only symbol annotations mode = 'symbol_text', -- show only symbol annotations
maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters) maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters)
-- can also be a function to dynamically calculate max width such as -- can also be a function to dynamically calculate max width such as
-- maxwidth = function() return math.floor(0.45 * vim.o.columns) end, -- maxwidth = function() return math.floor(0.45 * vim.o.columns) end,
ellipsis_char = '...', -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first) ellipsis_char = '...', -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first)
show_labelDetails = true, -- show labelDetails in menu. Disabled by default show_labelDetails = true, -- show labelDetails in menu. Disabled by default
-- The function below will be called before any actual modifications from lspkind -- The function below will be called before any actual modifications from lspkind
-- so that you can provide more controls on popup customization. (See [#30](https://github.com/onsails/lspkind-nvim/pull/30)) -- so that you can provide more controls on popup customization. (See [#30](https://github.com/onsails/lspkind-nvim/pull/30))
before = function(entry, vim_item) before = function(entry, vim_item)
return vim_item return vim_item
end end
}) })
}, },
window = { window = {
-- completion = cmp.config.window.bordered(), -- completion = cmp.config.window.bordered(),
-- documentation = cmp.config.window.bordered(), -- documentation = cmp.config.window.bordered(),
}, },
preselect = cmp.PreselectMode.None, preselect = cmp.PreselectMode.None,
mapping = cmp.mapping.preset.insert { mapping = cmp.mapping.preset.insert {
['<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 {}, ['<C-Space>'] = cmp.mapping.complete {},
['<CR>'] = cmp.mapping.confirm { ["<CR>"] = cmp.mapping({
behavior = cmp.ConfirmBehavior.Replace, i = function(fallback)
select = true, if cmp.visible() and cmp.get_active_entry() then
}, cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false })
['<Tab>'] = cmp.mapping(function(fallback) else
if cmp.visible() then fallback()
cmp.select_next_item() end
--elseif luasnip.expand_or_jumpable() then end,
--luasnip.expand_or_jump() s = cmp.mapping.confirm({ select = true }),
else c = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }),
fallback() }),
end ['<Tab>'] = cmp.mapping(function(fallback)
end, { 'i', 's' }), if cmp.visible() then
['<S-Tab>'] = cmp.mapping(function(fallback) cmp.select_next_item()
if cmp.visible() then --elseif luasnip.expand_or_jumpable() then
cmp.select_prev_item() --luasnip.expand_or_jump()
--elseif luasnip.jumpable(-1) then else
--luasnip.jump(-1) fallback()
else end
fallback() end, { 'i', 's' }),
end ['<S-Tab>'] = cmp.mapping(function(fallback)
end, { 'i', 's' }), if cmp.visible() then
}, cmp.select_prev_item()
sources = cmp.config.sources({ --elseif luasnip.jumpable(-1) then
{ name = 'nvim_lsp' }, --luasnip.jump(-1)
-- { name = 'vsnip' }, -- For vsnip users. else
-- { name = 'luasnip' }, -- For luasnip users. fallback()
-- { name = 'ultisnips' }, -- For ultisnips users. end
{ name = 'snippy' }, -- For snippy users. end, { 'i', 's' }),
--}, { },
{ name = 'buffer' }, sources = cmp.config.sources({
}) { name = 'nvim_lsp' },
-- { name = 'vsnip' }, -- For vsnip users.
-- { name = 'luasnip' }, -- For luasnip users.
-- { name = 'ultisnips' }, -- For ultisnips users.
{ name = 'snippy' }, -- For snippy users.
--}, {
{ name = 'buffer' },
})
}) })