dotfiles/.config/nvim/lua/my/plugins/completion.lua
2024-09-03 21:05:14 +02:00

129 lines
5.0 KiB
Lua

return {
{ 'https://github.com/hrsh7th/nvim-cmp',
lazy = true,
dependencies = {
'https://github.com/hrsh7th/cmp-nvim-lsp',
'https://github.com/hrsh7th/cmp-buffer',
'https://github.com/hrsh7th/cmp-path',
'https://github.com/hrsh7th/cmp-cmdline',
{ 'https://github.com/saadparwaiz1/cmp_luasnip',
dependencies = 'https://github.com/L3MON4D3/LuaSnip',
},
'https://github.com/hrsh7th/cmp-nvim-lua',
{ 'https://github.com/uga-rosa/cmp-dictionary',
opts = {
dic = {
['gitcommit'] =
vim.fn.stdpath('config') .. '/resources/git.dict',
-- doesn't work, filetype is probably set too late
['NeogitCommitMessage'] =
vim.fn.stdpath('config') .. '/resources/git.dict',
},
},
},
'https://github.com/f3fora/cmp-spell',
{ 'https://github.com/tamago324/cmp-zsh',
opts = {
filetypes = { 'zsh', 'bash', 'sh' },
}
},
{ 'https://github.com/paopaol/cmp-doxygen',
dependencies = {
'nvim-treesitter',
'https://github.com/nvim-treesitter/nvim-treesitter-textobjects',
},
},
'https://github.com/onsails/lspkind.nvim',
},
config = function()
local cmp = require('cmp')
local luasnip = require('luasnip')
local lspkind = require('lspkind')
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
formatting = {
format = lspkind.cmp_format({
mode = "symbol_text",
maxwidth = math.floor(vim.o.columns / 2),
ellipsis_char = '',
menu = ({
buffer = "[Buffer]",
nvim_lsp = "[LSP]",
luasnip = "[LuaSnip]",
nvim_lua = "[Lua]",
latex_symbols = "[Latex]",
})
}),
},
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
luasnip.expand({})
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
luasnip.jump(-1)
else
fallback()
end
end)
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
{ name = 'nvim_lua' },
{ name = 'dictionary' },
{ name = 'zsh' },
{ name = 'doxygen' },
}, {
{ name = 'buffer' },
-- { name = 'spell' },
})
})
-- Use LSP symbols and buffer source for `/`
cmp.setup.cmdline('/', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'nvim_lsp_document_symbol' }
}, {
{ name = 'buffer' }
})
})
-- Use cmdline & path source for ':'
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
end
},
}