78 lines
1.9 KiB
Lua
78 lines
1.9 KiB
Lua
local M = {
|
|
'hrsh7th/nvim-cmp',
|
|
dependencies = {
|
|
'neovim/nvim-lspconfig',
|
|
'hrsh7th/cmp-nvim-lsp',
|
|
'hrsh7th/cmp-buffer',
|
|
'hrsh7th/cmp-path',
|
|
'hrsh7th/cmp-cmdline',
|
|
'windwp/nvim-autopairs',
|
|
'onsails/lspkind.nvim',
|
|
},
|
|
}
|
|
|
|
M.config = function()
|
|
local cmp = require 'cmp'
|
|
local cmp_autopairs = require 'nvim-autopairs.completion.cmp'
|
|
|
|
cmp.setup {
|
|
window = {
|
|
completion = vim.tbl_deep_extend(
|
|
'force',
|
|
cmp.config.window.bordered(),
|
|
{
|
|
winhighlight = 'Normal:Pmenu,FloatBorder:Pmenu,Search:None',
|
|
col_offset = -3,
|
|
side_padding = -0,
|
|
}
|
|
),
|
|
documentation = cmp.config.window.bordered(),
|
|
},
|
|
formatting = {
|
|
fields = { 'kind', 'abbr', 'menu' },
|
|
format = function(entry, vim_item)
|
|
local kind = require 'lspkind'.cmp_format {
|
|
mode = 'symbol_text',
|
|
maxwidth = 50,
|
|
}(entry, vim_item)
|
|
local strings = vim.split(kind.kind, '%s', { trimempty = true })
|
|
kind.kind = ' ' .. (strings[1] or '') .. ' '
|
|
kind.menu = ' (' .. (strings[2] or '') .. ')'
|
|
return kind
|
|
end
|
|
},
|
|
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(),
|
|
['<down>'] = cmp.mapping.abort(),
|
|
['<up>'] = cmp.mapping.abort(),
|
|
['<c-down>'] = cmp.mapping.select_next_item(),
|
|
['<c-up>'] = cmp.mapping.select_prev_item(),
|
|
['<tab>'] = cmp.mapping.select_next_item(),
|
|
['<s-tab>'] = cmp.mapping.select_prev_item(),
|
|
['<cr>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
|
|
}),
|
|
sources = cmp.config.sources(
|
|
{
|
|
{ name = 'nvim_lsp' },
|
|
},
|
|
{
|
|
{ name = 'buffer' },
|
|
}
|
|
),
|
|
preselect = cmp.PreselectMode.Item,
|
|
experimental = {
|
|
ghost_text = false,
|
|
},
|
|
}
|
|
|
|
cmp.event:on(
|
|
'confirm_done',
|
|
cmp_autopairs.on_confirm_done()
|
|
)
|
|
end
|
|
|
|
return M
|