77 lines
2.6 KiB
Lua
77 lines
2.6 KiB
Lua
return {
|
|
'hrsh7th/nvim-cmp',
|
|
dependencies = {
|
|
'hrsh7th/cmp-buffer', -- source for text in buffer
|
|
'hrsh7th/cmp-path', -- source for file system paths
|
|
'saadparwaiz1/cmp_luasnip', -- snippets source for nvim-cmp
|
|
{ 'L3MON4D3/LuaSnip', config = true }, -- snippets plugin
|
|
'onsails/lspkind.nvim', -- vs-code like pictograms
|
|
},
|
|
config = function()
|
|
local cmp = require('cmp')
|
|
local luasnip = require('luasnip')
|
|
|
|
local window_style = cmp.config.window.bordered({
|
|
winhighlight = 'Normal:Pmenu,FloatBorder:Pmenu,Search:None',
|
|
col_offset = -3,
|
|
side_padding = 0,
|
|
})
|
|
cmp.setup({
|
|
view = {
|
|
docs = { auto_open = false },
|
|
},
|
|
snippet = {
|
|
expand = function(args)
|
|
luasnip.lsp_expand(args.body) -- use luasnip engine
|
|
end,
|
|
},
|
|
window = {
|
|
completion = window_style,
|
|
documentation = window_style,
|
|
},
|
|
mapping = cmp.mapping.preset.insert({
|
|
['<C-b>'] = cmp.mapping.scroll_docs(-4),
|
|
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
|
['<C-g>'] = cmp.mapping.abort(),
|
|
['<CR>'] = cmp.mapping.confirm({ select = false }),
|
|
['<C-d>'] = cmp.mapping(function(fallback)
|
|
if cmp.visible_docs() then
|
|
cmp.close_docs()
|
|
elseif cmp.visible() then
|
|
cmp.open_docs()
|
|
else
|
|
fallback()
|
|
end
|
|
end),
|
|
}),
|
|
sources = cmp.config.sources({
|
|
{ name = 'nvim_lsp', max_item_count = 10, keyword_length = 1 },
|
|
{ name = 'luasnip', max_item_count = 10, keyword_length = 1 },
|
|
{ name = 'buffer', max_item_count = 10, keyword_length = 1 },
|
|
{ name = 'path', max_item_count = 10, keyword_length = 1 },
|
|
}),
|
|
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,
|
|
},
|
|
enabled = function()
|
|
-- disable completion in comments
|
|
local context = require('cmp.config.context')
|
|
-- keep command mode completion enabled when cursor is in a comment
|
|
if vim.api.nvim_get_mode().mode == 'c' then
|
|
return true
|
|
else
|
|
return not context.in_treesitter_capture('comment') and not context.in_syntax_group('Comment')
|
|
end
|
|
end,
|
|
})
|
|
end,
|
|
}
|