2023-09-15 18:33:00 +02:00
|
|
|
-- Add additional capabilities supported by nvim-cmp
|
|
|
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
|
|
|
|
|
|
|
local lspconfig = require "lspconfig"
|
2021-11-09 03:03:21 +01:00
|
|
|
|
2023-09-15 18:33:00 +02:00
|
|
|
-- Enable language servers with the additional completion capabilities
|
|
|
|
-- offered by nvim-cmp
|
|
|
|
local servers = {
|
|
|
|
"ansiblels",
|
|
|
|
"esbonio",
|
|
|
|
"gopls",
|
|
|
|
"pyright",
|
|
|
|
"rust_analyzer",
|
|
|
|
"texlab",
|
|
|
|
}
|
|
|
|
for _, lsp in ipairs(servers) do
|
|
|
|
lspconfig[lsp].setup({
|
|
|
|
-- on_attach = my_custom_on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
})
|
2021-11-12 01:18:09 +01:00
|
|
|
end
|
|
|
|
|
2023-09-15 18:33:00 +02:00
|
|
|
-- luasnip setup
|
|
|
|
local luasnip = require "luasnip"
|
|
|
|
|
|
|
|
-- nvim-cmp setup
|
|
|
|
local cmp = require "cmp"
|
2021-11-09 03:03:21 +01:00
|
|
|
cmp.setup({
|
2022-04-19 11:22:16 +02:00
|
|
|
snippet = {
|
|
|
|
expand = function(args)
|
|
|
|
luasnip.lsp_expand(args.body)
|
|
|
|
end,
|
|
|
|
},
|
2023-09-15 18:33:00 +02:00
|
|
|
mapping = cmp.mapping.preset.insert({
|
|
|
|
["<C-u>"] = cmp.mapping.scroll_docs(-4), -- Up
|
|
|
|
["<C-d>"] = cmp.mapping.scroll_docs(4), -- Down
|
|
|
|
-- C-b (back) C-f (forward) for snippet placeholder navigation.
|
2022-04-19 11:22:16 +02:00
|
|
|
["<C-Space>"] = cmp.mapping.complete(),
|
2023-09-15 18:33:00 +02:00
|
|
|
["<CR>"] = cmp.mapping.confirm({
|
|
|
|
behavior = cmp.ConfirmBehavior.Replace,
|
|
|
|
select = true,
|
|
|
|
}),
|
2022-04-19 11:22:16 +02:00
|
|
|
["<Tab>"] = cmp.mapping(function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_next_item()
|
|
|
|
elseif luasnip.expand_or_jumpable() then
|
|
|
|
luasnip.expand_or_jump()
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, { "i", "s" }),
|
|
|
|
["<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, { "i", "s" }),
|
2023-09-15 18:33:00 +02:00
|
|
|
}),
|
2022-04-19 11:22:16 +02:00
|
|
|
sources = {
|
|
|
|
{ name = "nvim_lsp" },
|
|
|
|
{ name = "nvim_lua" },
|
|
|
|
{ name = "luasnip" },
|
|
|
|
{
|
|
|
|
name = "buffer",
|
|
|
|
option = {
|
|
|
|
keyword_pattern = [[\k\+]],
|
|
|
|
-- Use all buffers to complete.
|
|
|
|
get_bufnrs = function()
|
|
|
|
return vim.api.nvim_list_bufs()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ name = "path" },
|
|
|
|
},
|
2021-11-09 03:03:21 +01:00
|
|
|
})
|