2023-04-15 15:47:38 +02:00
|
|
|
return {
|
2022-12-31 17:43:31 +01:00
|
|
|
'hrsh7th/nvim-cmp',
|
2023-01-01 19:36:00 +01:00
|
|
|
-- lazy = false,
|
2022-12-31 17:43:31 +01:00
|
|
|
dependencies = {
|
2023-01-01 19:36:00 +01:00
|
|
|
{ 'honza/vim-snippets' },
|
|
|
|
{ 'dcampos/nvim-snippy' },
|
|
|
|
{ 'dcampos/cmp-snippy' },
|
2022-12-31 17:43:31 +01:00
|
|
|
'hrsh7th/cmp-nvim-lsp',
|
|
|
|
'hrsh7th/cmp-buffer',
|
|
|
|
'hrsh7th/cmp-cmdline',
|
|
|
|
'hrsh7th/cmp-path',
|
2023-04-15 15:47:38 +02:00
|
|
|
'windwp/nvim-autopairs',
|
2022-12-31 17:43:31 +01:00
|
|
|
},
|
2023-01-19 17:06:59 +01:00
|
|
|
event = { 'InsertEnter', 'CmdlineEnter' },
|
2023-04-08 23:47:10 +02:00
|
|
|
version = false,
|
2023-04-15 15:47:38 +02:00
|
|
|
config = function()
|
|
|
|
local cmp = require 'cmp'
|
|
|
|
local utils = require 'config.utils'
|
2022-12-31 17:43:31 +01:00
|
|
|
|
2023-04-15 15:47:38 +02:00
|
|
|
cmp.setup {
|
|
|
|
-- enabled = function()
|
|
|
|
-- return vim.api.nvim_buf_get_option(0, 'buftype') ~= 'prompt' or require('cmp_dap').is_dap_buffer()
|
|
|
|
-- end,
|
|
|
|
view = {
|
|
|
|
entries = {
|
|
|
|
name = 'custom', -- can be "custom", "wildmenu" or "native"
|
|
|
|
-- separator = ' | ',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
completion = {
|
|
|
|
autocomplete = { 'TextChanged', 'CmdlineChanged', 'TextChangedP' },
|
|
|
|
-- autocomplete = false,
|
|
|
|
},
|
|
|
|
snippet = {
|
|
|
|
expand = function(args)
|
|
|
|
require('snippy').expand_snippet(args.body)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
window = {
|
|
|
|
completion = cmp.config.window.bordered(),
|
|
|
|
documentation = cmp.config.window.bordered(),
|
|
|
|
},
|
|
|
|
experimental = {
|
|
|
|
ghost_text = true,
|
|
|
|
},
|
|
|
|
formatting = {
|
|
|
|
fields = { 'abbr', 'kind', 'menu' },
|
|
|
|
format = function(_, item)
|
|
|
|
local ELLIPSIS_CHAR = '…'
|
2023-06-19 11:33:42 +02:00
|
|
|
local MAX_LABEL_WIDTH = 25
|
|
|
|
item.kind = string.format('%s', item.kind) -- This concatonates the icons with the name of the item kind
|
2022-12-31 17:43:31 +01:00
|
|
|
|
2023-04-15 15:47:38 +02:00
|
|
|
local label = item.abbr
|
|
|
|
local truncated_label = vim.fn.strcharpart(label, 0, MAX_LABEL_WIDTH)
|
|
|
|
if truncated_label ~= label then
|
|
|
|
item.abbr = truncated_label .. ELLIPSIS_CHAR
|
|
|
|
end
|
|
|
|
return item
|
|
|
|
end,
|
2022-12-31 17:43:31 +01:00
|
|
|
},
|
2023-04-15 15:47:38 +02:00
|
|
|
mapping = {
|
|
|
|
['<C-k>'] = cmp.mapping.select_prev_item(),
|
|
|
|
['<C-j>'] = cmp.mapping.select_next_item(),
|
|
|
|
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
|
|
|
|
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
|
|
|
|
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
|
|
|
|
['<C-e>'] = cmp.mapping {
|
|
|
|
i = cmp.mapping.abort(),
|
|
|
|
c = cmp.mapping.close(),
|
|
|
|
},
|
|
|
|
['<CR>'] = cmp.mapping.confirm { select = true },
|
|
|
|
['<Tab>'] = cmp.mapping(function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_next_item { behavior = cmp.SelectBehavior.Select }
|
|
|
|
elseif require('snippy').can_expand_or_advance() then
|
|
|
|
require('snippy').expand_or_advance()
|
|
|
|
elseif utils.has_words_before() then
|
|
|
|
cmp.complete()
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, { 'i', 's' }),
|
2023-04-09 12:42:41 +02:00
|
|
|
|
2023-04-15 15:47:38 +02:00
|
|
|
['<S-Tab>'] = cmp.mapping(function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_prev_item { behavior = cmp.SelectBehavior.Insert }
|
|
|
|
elseif require('snippy').can_jump(-1) then
|
|
|
|
require('snippy').previous()
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, { 'i', 's' }),
|
2022-12-31 17:43:31 +01:00
|
|
|
},
|
2023-04-15 15:47:38 +02:00
|
|
|
sources = {
|
|
|
|
{ name = 'nvim_lsp' },
|
|
|
|
{ name = 'snippy' },
|
|
|
|
{ name = 'path' },
|
|
|
|
{ name = 'buffer' },
|
|
|
|
},
|
|
|
|
}
|
|
|
|
cmp.setup.cmdline(':', {
|
2023-06-21 17:01:29 +02:00
|
|
|
completion = { autocomplete = { 'TextChanged', 'CmdlineChanged', 'TextChanged' } },
|
2023-04-15 15:47:38 +02:00
|
|
|
mapping = cmp.mapping.preset.cmdline(),
|
|
|
|
sources = {
|
|
|
|
{ name = 'cmdline' },
|
|
|
|
},
|
|
|
|
-- view = {
|
|
|
|
-- entries = { name = 'wildmenu', separator = ' · ' },
|
|
|
|
-- },
|
|
|
|
})
|
2022-12-31 17:43:31 +01:00
|
|
|
|
2023-06-21 17:01:29 +02:00
|
|
|
-- cmp.setup.cmdline('/', {
|
|
|
|
-- sources = {
|
|
|
|
-- { name = 'buffer' },
|
|
|
|
-- },
|
|
|
|
-- view = {
|
|
|
|
-- entries = { name = 'wildmenu', separator = ' · ' },
|
|
|
|
-- },
|
|
|
|
-- })
|
2022-12-31 17:43:31 +01:00
|
|
|
|
2023-06-21 17:01:29 +02:00
|
|
|
-- cmp.setup.filetype({ 'dap-repl', 'dapui_watches', 'dapui_hover' }, {
|
|
|
|
-- sources = {
|
|
|
|
-- { name = 'dap' },
|
|
|
|
-- },
|
|
|
|
-- })
|
2023-01-19 17:06:59 +01:00
|
|
|
|
2023-04-15 15:47:38 +02:00
|
|
|
local npairs = require 'nvim-autopairs'
|
|
|
|
npairs.setup {
|
|
|
|
check_ts = true, -- treesitter integration
|
|
|
|
fast_wrap = {
|
|
|
|
map = '<C-e>',
|
|
|
|
highlight = 'Search',
|
|
|
|
highlight_grey = 'Comment',
|
|
|
|
},
|
|
|
|
map_c_w = true,
|
|
|
|
-- disable_filetype = { "TelescopePrompt" },
|
|
|
|
}
|
2022-12-31 17:43:31 +01:00
|
|
|
|
2023-04-15 15:47:38 +02:00
|
|
|
local cmp_autopairs = require 'nvim-autopairs.completion.cmp'
|
|
|
|
cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done {})
|
|
|
|
end,
|
|
|
|
}
|