return { { 'williamboman/mason.nvim', lazy = false, opts = {}, }, -- Autocompletion { 'hrsh7th/nvim-cmp', event = 'InsertEnter', dependencies = { { "L3MON4D3/LuaSnip" }, { 'hrsh7th/cmp-nvim-lsp' }, -- Required { 'hrsh7th/cmp-buffer' }, -- Optional { 'hrsh7th/cmp-path' }, -- Optional { 'saadparwaiz1/cmp_luasnip' }, -- Optional { 'hrsh7th/cmp-nvim-lua' }, -- Optional }, config = function() local cmp = require('cmp') local luasnip = require("luasnip") local cmp_select = { behavior = cmp.SelectBehavior.Select } cmp.setup({ sources = cmp.config.sources({ { name = 'nvim_lsp' }, { name = 'luasnip' }, { name = 'path' }, { name = 'buffer' }, { name = 'nvim_lua' }, }, { { name = 'buffer' }, }), completion = { completeopt = 'menu,menuone,noinsert' }, mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.select_prev_item(cmp_select), [''] = cmp.mapping.select_next_item(cmp_select), [""] = cmp.mapping.complete(), [''] = cmp.mapping.select_next_item(cmp_select), [''] = nil, [""] = cmp.mapping({ i = function(fallback) -- and cmp.get_selected_entry() if cmp.visible() then cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }) else fallback() end end, s = cmp.mapping.confirm({ select = true }), c = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }), }), }), experimental = { ghost_text = true }, snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, }) end }, -- LSP { 'neovim/nvim-lspconfig', cmd = { 'LspInfo', 'LspInstall', 'LspStart' }, event = { 'BufReadPre', 'BufNewFile' }, dependencies = { { 'hrsh7th/cmp-nvim-lsp' }, { 'williamboman/mason.nvim' }, { 'williamboman/mason-lspconfig.nvim' }, { "L3MON4D3/LuaSnip" } }, init = function() -- Reserve a space in the gutter -- This will avoid an annoying layout shift in the screen vim.opt.signcolumn = 'yes' end, config = function() local lsp_defaults = require('lspconfig').util.default_config -- Add cmp_nvim_lsp capabilities settings to lspconfig -- This should be executed before you configure any language server lsp_defaults.capabilities = vim.tbl_deep_extend( 'force', lsp_defaults.capabilities, require('cmp_nvim_lsp').default_capabilities() ) -- LspAttach is where you enable features that only work -- if there is a language server active in the file vim.api.nvim_create_autocmd('LspAttach', { desc = 'LSP actions', callback = function(event) local opts = { buffer = event.buf } vim.keymap.set('n', 'K', 'lua vim.lsp.buf.hover()', opts) vim.keymap.set('n', 'gd', 'lua vim.lsp.buf.definition()', opts) vim.keymap.set('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) vim.keymap.set('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) vim.keymap.set('n', 'go', 'lua vim.lsp.buf.type_definition()', opts) vim.keymap.set('n', 'gr', 'lua vim.lsp.buf.references()', opts) vim.keymap.set('n', 'gs', 'lua vim.lsp.buf.signature_help()', opts) vim.keymap.set('n', 'rn', 'lua vim.lsp.buf.rename()', opts) vim.keymap.set({ 'n', 'x' }, 'ft', 'lua vim.lsp.buf.format({async = true})', opts) vim.keymap.set('n', '', 'lua vim.lsp.buf.code_action()', opts) end, }) require('mason-lspconfig').setup({ ensure_installed = { 'tailwindcss', 'ts_ls', 'texlab', 'pyright', 'ltex', 'jsonls' }, handlers = { -- this first function is the "default handler" -- it applies to every language server without a "custom handler" function(server_name) require('lspconfig')[server_name].setup({}) end, } }) end } }