Update .config/nvim/lua/plugins/lsp.lua

This commit is contained in:
Anthony Rodriguez 2024-08-14 04:16:32 +02:00
parent 833213961d
commit 4954013534

View file

@ -4,8 +4,7 @@ return {
"williamboman/mason-lspconfig.nvim", "williamboman/mason-lspconfig.nvim",
opts = { opts = {
ensure_installed = { "gopls", "lua_ls" }, ensure_installed = { "gopls", "lua_ls" },
} },
}, },
{ {
"neovim/nvim-lspconfig", "neovim/nvim-lspconfig",
@ -30,8 +29,9 @@ return {
"hrsh7th/cmp-buffer", "hrsh7th/cmp-buffer",
"hrsh7th/cmp-path", "hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline", "hrsh7th/cmp-cmdline",
"hrsh7th/cmp-vsnip", "L3MON4D3/LuaSnip",
"hrsh7th/vim-vsnip", "saadparwaiz1/cmp_luasnip",
"rafamadriz/friendly-snippets",
"hrsh7th/cmp-nvim-lsp-signature-help", "hrsh7th/cmp-nvim-lsp-signature-help",
}, },
opts = function(_, opts) opts = function(_, opts)
@ -43,42 +43,49 @@ return {
nil nil
end end
require("luasnip.loaders.from_vscode").lazy_load()
-- Setup cmp with options -- Setup cmp with options
opts.snippet = { opts.snippet = {
expand = function(args) expand = function(args)
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
end, end,
} }
local luasnip = require('luasnip')
opts.mapping = cmp.mapping.preset.insert({ opts.mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4), ['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4), ['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(), ['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(), ['<C-e>'] = cmp.mapping.abort(),
['<tab>'] = cmp.mapping(function(fallback) ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Enter key to confirm completion
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_next_item() cmp.select_next_item() -- Navigate to the next item in the list
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump() -- Expand or jump to the next snippet placeholder
elseif has_words_before() then elseif has_words_before() then
cmp.complete() cmp.complete() -- Trigger completion if a word is before the cursor
else else
fallback() fallback() -- Insert a tab character if nothing else applies
end end
end, { "i", "s" }), end, { "i", "s" }),
['<S-Tab>'] = cmp.mapping(function(fallback) ['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_prev_item() cmp.select_prev_item() -- Navigate to the previous item in the list
elseif luasnip.jumpable(-1) then
luasnip.jump(-1) -- Jump to the previous snippet placeholder
else else
fallback() fallback() -- Insert a tab character if nothing else applies
end end
end, { "i", "s" }), end, { "i", "s" }),
}) })
opts.sources = cmp.config.sources({ opts.sources = cmp.config.sources({
{ name = 'nvim_lsp' }, { name = 'nvim_lsp' },
{ name = 'vsnip' }, -- For vsnip users. { name = 'luasnip' }, -- For luasnip users.
}, { }, {
{ name = 'buffer' }, { name = 'buffer' },
{ name = 'nvim_lsp_signature_help' } { name = 'nvim_lsp_signature_help' },
}) })
return opts return opts