dotfiles/.config/nvim/lua/plugins/lsp.lua

84 lines
2.3 KiB
Lua
Raw Normal View History

2024-07-18 12:00:39 -04:00
return {
{
2024-07-19 09:21:13 -04:00
'VonHeikemen/lsp-zero.nvim',
2024-08-30 15:56:31 -04:00
branch = 'v4.x',
2024-07-18 12:00:39 -04:00
dependencies = {
2024-07-18 13:27:24 -04:00
'neovim/nvim-lspconfig',
2024-07-19 09:21:13 -04:00
'williamboman/mason.nvim',
'williamboman/mason-lspconfig.nvim',
'hrsh7th/nvim-cmp',
'hrsh7th/cmp-nvim-lsp',
'L3MON4D3/LuaSnip',
2024-07-18 13:27:24 -04:00
},
config = function ()
2024-07-19 09:21:13 -04:00
local lsp_zero = require('lsp-zero')
2024-08-30 16:25:15 -04:00
local augroup = vim.api.nvim_create_augroup('LspFormatting', {})
local function lsp_format_on_save(bufnr)
vim.api.nvim_clear_autocmds({group = augroup, buffer = bufnr})
vim.api.nvim_create_autocmd('BufWritePre', {
group = augroup,
buffer = bufnr,
callback = function ()
vim.lsp.buf.format()
end
})
end
2024-08-30 15:56:31 -04:00
local lsp_attach = function (client, bufnr)
lsp_zero.default_keymaps({ buffer = bufnr, preserve_mappings = false })
2024-08-30 16:25:15 -04:00
lsp_format_on_save(bufnr)
2024-08-30 15:56:31 -04:00
end
lsp_zero.extend_lspconfig({
lsp_attach = lsp_attach,
})
2024-07-19 09:21:13 -04:00
require('mason').setup({})
require('mason-lspconfig').setup({
ensure_installed = {},
handlers = {
function (server_name)
if server_name == 'tsserver' then
server_name = 'ts_ls'
end
2024-07-19 09:21:13 -04:00
require('lspconfig')[server_name].setup({})
end,
},
})
2024-07-19 09:26:20 -04:00
local cmp = require('cmp')
cmp.setup({
sources = {
{name = 'nvim_lsp'},
},
mapping = {
['<C-y>'] = cmp.mapping.confirm({select = false}),
['<C-e>'] = cmp.mapping.abort(),
['<Up>'] = cmp.mapping.select_prev_item({behavior = 'select'}),
['<Down>'] = cmp.mapping.select_next_item({behavior = 'select'}),
['<C-p>'] = cmp.mapping(function()
if cmp.visible() then
cmp.select_prev_item({behavior = 'insert'})
else
cmp.complete()
end
end),
['<C-n>'] = cmp.mapping(function()
if cmp.visible() then
cmp.select_next_item({behavior = 'insert'})
else
cmp.complete()
end
end),
},
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
})
2024-07-18 13:27:24 -04:00
end
2024-07-18 12:00:39 -04:00
},
}