2022-08-15 01:29:31 +02:00
|
|
|
local cmp = require('cmp')
|
|
|
|
local luasnip = require('luasnip')
|
2023-08-06 18:32:20 +02:00
|
|
|
local lspkind = require('lspkind')
|
2022-08-08 11:07:10 +02:00
|
|
|
|
2022-08-15 01:29:31 +02:00
|
|
|
if cmp and luasnip then
|
|
|
|
cmp.setup({
|
|
|
|
snippet = {
|
|
|
|
expand = function(args)
|
|
|
|
luasnip.lsp_expand(args.body)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
window = {
|
|
|
|
completion = cmp.config.window.bordered(),
|
|
|
|
documentation = cmp.config.window.bordered(),
|
|
|
|
},
|
2023-08-06 18:32:20 +02:00
|
|
|
formatting = {
|
|
|
|
format = lspkind.cmp_format({
|
|
|
|
mode = "symbol_text",
|
2024-01-04 23:15:15 +01:00
|
|
|
maxwidth = math.floor(vim.o.columns / 2),
|
2023-08-06 18:32:20 +02:00
|
|
|
ellipsis_char = '…',
|
|
|
|
menu = ({
|
|
|
|
buffer = "[Buffer]",
|
|
|
|
nvim_lsp = "[LSP]",
|
|
|
|
luasnip = "[LuaSnip]",
|
|
|
|
nvim_lua = "[Lua]",
|
|
|
|
latex_symbols = "[Latex]",
|
|
|
|
})
|
|
|
|
}),
|
|
|
|
},
|
2022-08-15 01:29:31 +02:00
|
|
|
mapping = cmp.mapping.preset.insert({
|
|
|
|
['<S-PageUp>'] = cmp.mapping.scroll_docs(-4),
|
|
|
|
['<S-PageDown>'] = cmp.mapping.scroll_docs(4),
|
|
|
|
['<C-Space>'] = cmp.mapping.complete(),
|
|
|
|
['<C-e>'] = cmp.mapping.abort(),
|
|
|
|
['<Left>'] = cmp.mapping.abort(),
|
|
|
|
['<CR>'] = cmp.mapping.confirm({ select = false }),
|
|
|
|
['<Tab>'] = cmp.mapping(function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_next_item()
|
|
|
|
elseif luasnip.expandable() then
|
2022-11-05 17:24:21 +01:00
|
|
|
luasnip.expand({})
|
2022-08-15 01:29:31 +02:00
|
|
|
elseif luasnip.expand_or_jumpable() then
|
|
|
|
luasnip.expand_or_jump()
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end),
|
|
|
|
['<S-Tab>'] = cmp.mapping(function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_prev_item()
|
|
|
|
elseif luasnip.jumpable(-1) then
|
2022-08-20 03:11:14 +02:00
|
|
|
luasnip.jump(-1)
|
2022-08-15 01:29:31 +02:00
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
}),
|
|
|
|
sources = cmp.config.sources({
|
|
|
|
{ name = 'nvim_lsp' },
|
|
|
|
{ name = 'luasnip' },
|
2022-09-09 06:24:18 +02:00
|
|
|
{ name = 'nvim_lua' },
|
|
|
|
{ name = 'dictionary' },
|
2022-09-09 06:13:49 +02:00
|
|
|
{ name = 'zsh' },
|
2022-09-09 06:50:11 +02:00
|
|
|
{ name = 'doxygen' },
|
2022-08-15 01:29:31 +02:00
|
|
|
}, {
|
|
|
|
{ name = 'buffer' },
|
2022-09-14 05:44:04 +02:00
|
|
|
-- { name = 'spell' },
|
2022-08-12 19:54:40 +02:00
|
|
|
})
|
2022-08-15 01:29:31 +02:00
|
|
|
})
|
2022-08-08 11:07:10 +02:00
|
|
|
|
2022-11-05 17:24:21 +01:00
|
|
|
-- Use LSP symbols and buffer source for `/`
|
2022-08-15 01:29:31 +02:00
|
|
|
cmp.setup.cmdline('/', {
|
|
|
|
mapping = cmp.mapping.preset.cmdline(),
|
2022-09-09 06:00:48 +02:00
|
|
|
sources = cmp.config.sources({
|
|
|
|
{ name = 'nvim_lsp_document_symbol' }
|
|
|
|
}, {
|
2022-08-15 01:29:31 +02:00
|
|
|
{ name = 'buffer' }
|
2022-09-09 06:00:48 +02:00
|
|
|
})
|
2022-08-15 01:29:31 +02:00
|
|
|
})
|
2022-08-13 21:28:42 +02:00
|
|
|
|
2022-08-15 01:29:31 +02:00
|
|
|
-- Use cmdline & path source for ':'
|
|
|
|
cmp.setup.cmdline(':', {
|
|
|
|
mapping = cmp.mapping.preset.cmdline(),
|
|
|
|
sources = cmp.config.sources({
|
|
|
|
{ name = 'path' }
|
|
|
|
}, {
|
|
|
|
{ name = 'cmdline' }
|
2022-08-13 21:28:42 +02:00
|
|
|
})
|
2022-08-15 01:29:31 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
require('cmp_dictionary').setup({
|
|
|
|
dic = {
|
|
|
|
['gitcommit'] =
|
2024-01-04 23:16:24 +01:00
|
|
|
vim.fn.stdpath('config') .. '/resources/git.dict',
|
2022-09-09 06:24:18 +02:00
|
|
|
-- doesn't work, filetype is probably set too late
|
|
|
|
['NeogitCommitMessage'] =
|
2024-01-04 23:16:24 +01:00
|
|
|
vim.fn.stdpath('config') .. '/resources/git.dict',
|
2022-08-15 01:29:31 +02:00
|
|
|
}
|
|
|
|
})
|
2022-08-20 03:11:14 +02:00
|
|
|
|
|
|
|
-- add jump maps for select mode
|
|
|
|
local map = require('my.functions').map
|
|
|
|
map('s', '<Tab>', function() luasnip.jump(1) end)
|
|
|
|
map('s', '<S-Tab>', function() luasnip.jump(-1) end)
|
2022-09-09 06:13:49 +02:00
|
|
|
|
|
|
|
require('cmp_zsh').setup({
|
|
|
|
filetypes = { 'zsh', 'bash', 'sh' }
|
|
|
|
})
|
2022-08-15 01:29:31 +02:00
|
|
|
end
|