return { -- Autocompletion { 'hrsh7th/nvim-cmp', event = 'InsertEnter', config = function() local cmp = require('cmp') cmp.setup({ sources = { {name = 'nvim_lsp'}, }, mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.complete(), [''] = cmp.mapping.select_prev_item(cmp_select), [''] = cmp.mapping.select_next_item(cmp_select), [''] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true, }), [''] = cmp.mapping.abort(), }), snippet = { expand = function(args) vim.snippet.expand(args.body) end, }, }) end }, -- LSP { 'neovim/nvim-lspconfig', cmd = 'LspInfo', event = {'BufReadPre', 'BufNewFile'}, dependencies = { {'hrsh7th/cmp-nvim-lsp'}, }, 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.buffer, remap = false } vim.keymap.set('n', 'gd', function() vim.lsp.buf.definition() end, opts) vim.keymap.set('n', 'k', function() vim.lsp.buf.hover() end, opts) vim.keymap.set('n', 'r', function() vim.lsp.buf.rename() end, opts) vim.keymap.set('n', 'a', function() vim.lsp.buf.code_action() end, opts) vim.keymap.set('n', 'gr', function() vim.lsp.buf.references() end, opts) vim.keymap.set('n', 'd', function() vim.diagnostic.open_float() end, opts) vim.keymap.set('n', '[d', function() vim.diagnostic.goto_prev() end, opts) vim.keymap.set('n', ']d', function() vim.diagnostic.goto_next() end, opts) vim.keymap.set('n', 'Q', function() vim.diagnostic.set_qflist() end, opts) vim.keymap.set('n', 'F', function() vim.lsp.buf.format() end, opts) end, }) local lsp = require('lspconfig') -- require('lspconfig').gleam.setup({}) -- require('lspconfig').ocamllsp.setup({}) lsp.rust_analyzer.setup({ settings = { ["rust-analyzer"] = { procMacro = { enable = true, ignored = { leptos_macro = { "server" }, }, }, cargo = { allFeatures = true, }, } } }) -- Workaround for rust_analzyer issue for _, method in ipairs({ 'textDocument/diagnostic', 'workspace/diagnostic' }) do local default_diagnostic_handler = vim.lsp.handlers[method] vim.lsp.handlers[method] = function(err, result, context, config) if err ~= nil and err.code == -32802 then return end return default_diagnostic_handler(err, result, context, config) end end end, } }