nvim/lua/plugins/cmp.lua

109 lines
3.0 KiB
Lua
Raw Normal View History

return {
2022-12-31 17:43:31 +01:00
'hrsh7th/nvim-cmp',
dependencies = {
'hrsh7th/cmp-nvim-lsp',
'hrsh7th/cmp-path',
2022-12-31 17:43:31 +01:00
'hrsh7th/cmp-buffer',
'hrsh7th/cmp-calc',
2022-12-31 17:43:31 +01:00
'hrsh7th/cmp-cmdline',
'hrsh7th/cmp-nvim-lsp-signature-help',
'saadparwaiz1/cmp_luasnip',
'onsails/lspkind.nvim',
2022-12-31 17:43:31 +01:00
},
event = { 'InsertEnter', 'CmdlineEnter' },
config = function()
local cmp = require 'cmp'
local lspkind = require 'lspkind'
2022-12-31 17:43:31 +01:00
cmp.setup {
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
view = {
entries = {
name = 'custom', -- can be "custom", "wildmenu" or "native"
-- separator = ' | ',
selection_order = 'near_cursor',
},
},
-- completion = {
-- autocomplete = { 'TextChanged', 'CmdlineChanged', 'TextChangedP' },
-- -- autocomplete = false,
-- },
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
experimental = {
ghost_text = {
hl_group = { "Comment" },
},
},
mapping = cmp.mapping.preset.insert {
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end, { 'i', 's' }),
['<CR>'] = cmp.mapping.confirm { select = false },
2022-12-31 17:43:31 +01:00
},
sources = cmp.config.sources({
{ name = 'luasnip' },
{ name = 'nvim_lsp' },
{ name = 'nvim_lsp_signature_help' },
}, {
{ name = 'path' },
{ name = 'calc' },
{ name = 'buffer' },
}),
formatting = {
format = require 'lspkind'.cmp_format({
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)
-- can also be a function to dynamically calculate max width such as
-- 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)
show_labelDetails = true, -- show labelDetails in menu. Disabled by default
-- 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))
before = function(entry, vim_item)
return vim_item
end
})
},
}
cmp.setup.cmdline({ '/', '?' }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' },
},
})
2022-12-31 17:43:31 +01:00
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' },
}, {
{ name = 'cmdline' },
}),
})
end,
}