56 lines
1.4 KiB
Lua
56 lines
1.4 KiB
Lua
--configure nvim-cmp for use with lsp and luasnip.
|
|
|
|
|
|
-- Add additional capabilities supported by nvim-cmp
|
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
|
|
|
|
|
|
local lspconfig = require('lspconfig')
|
|
|
|
-- Enable some language servers with the additional completion capabilities offered by nvim-cmp
|
|
local servers = { 'clangd', 'rust_analyzer', 'pyright', 'tsserver' }
|
|
for _, lsp in ipairs(servers) do
|
|
lspconfig[lsp].setup {
|
|
-- on_attach = my_custom_on_attach,
|
|
capabilities = capabilities,
|
|
}
|
|
end
|
|
|
|
-- Set completeopt to have a better completion experience
|
|
vim.o.completeopt = 'menuone,noselect'
|
|
|
|
-- nvim-cmp setup
|
|
local cmp = require 'cmp'
|
|
cmp.setup {
|
|
mapping = {
|
|
['<C-p>'] = cmp.mapping.select_prev_item(),
|
|
['<C-n>'] = cmp.mapping.select_next_item(),
|
|
['<C-d>'] = cmp.mapping.scroll_docs(-4),
|
|
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
|
['<C-Space>'] = cmp.mapping.complete(),
|
|
['<C-e>'] = cmp.mapping.close(),
|
|
['<CR>'] = cmp.mapping.confirm {
|
|
behavior = cmp.ConfirmBehavior.Replace,
|
|
select = true,
|
|
},
|
|
['<Tab>'] = function(fallback)
|
|
if cmp.visible() then
|
|
cmp.select_next_item()
|
|
else
|
|
fallback()
|
|
end
|
|
end,
|
|
['<S-Tab>'] = function(fallback)
|
|
if cmp.visible() then
|
|
cmp.select_prev_item()
|
|
else
|
|
fallback()
|
|
end
|
|
end,
|
|
},
|
|
sources = {
|
|
{ name = 'nvim_lsp' },
|
|
},
|
|
}
|