1-- lspconfig 2 3--- underline errors rather than highlight 4vim.lsp.handlers['textDocument/publishDiagnostics'] = vim.lsp.with( 5 vim.lsp.diagnostic.on_publish_diagnostics, { 6 underline = true, 7 ---virtual_text = true, 8 signs = true, 9 update_in_insert = true, 10 float = true, 11 } 12) 13 14-- Use an on_attach function to only map the following keys 15-- after the language server attaches to the current buffer 16On_attach = function(client, bufnr) 17 vim.keymap.set('n', 'K', vim.lsp.buf.hover, { desc = 'Hover' }) 18 vim.keymap.set('n', 'gd', vim.lsp.buf.definition, { desc = 'Goto definition' }) 19 vim.keymap.set('n', '[d', vim.diagnostic.goto_next, { desc = 'Goto next issue' }) 20 vim.keymap.set('n', ']d', vim.diagnostic.goto_prev, { desc = 'Goto prev issue' }) 21 vim.keymap.set('n', '<leader>ci', vim.lsp.buf.implementation, { desc = 'Goto implementation' }) 22 vim.keymap.set('n', '<leader>ct', vim.lsp.buf.type_definition, { desc = 'Goto type definition' }) 23 vim.keymap.set('n', '<leader>cr', vim.lsp.buf.references, { desc = 'Show references' }) 24 vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, { desc = 'Code action' }) 25 vim.keymap.set('n', '<leader>cR', vim.lsp.buf.rename, { desc = 'Rename' }) 26 vim.keymap.set('n', '<leader>cf', function() vim.lsp.buf.format { async = true } end, { desc = 'Format' }) 27 vim.keymap.set('n', '<leader>ce', vim.diagnostic.open_float, { desc = 'Get error' }) 28end 29 30-- Add additional capabilities supported by nvim-cmp 31Capabilities = vim.tbl_deep_extend('force', 32 vim.lsp.protocol.make_client_capabilities(), 33 require('cmp_nvim_lsp').default_capabilities() 34) 35Capabilities.workspace.didChangeWatchedFiles.dynamicRegistration = false 36 37local lspconfig = require('lspconfig') 38 39-- Enable some language servers with the additional completion capabilities offered by nvim-cmp 40local servers = { 'nixd', 'ocamllsp', 'clangd', 'rust_analyzer', 'pyright', 'gopls', 'typst_lsp', 'hls' } 41for _, lsp in ipairs(servers) do 42 lspconfig[lsp].setup { 43 on_attach = On_attach, 44 capabilities = Capabilities, 45 } 46end 47 48lspconfig['lua_ls'].setup { 49 on_attach = On_attach, 50 capabilities = Capabilities, 51 settings = { 52 Lua = { 53 runtime = { 54 -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) 55 version = 'LuaJIT', 56 }, 57 diagnostics = { 58 -- Get the language server to recognize the `vim` global 59 globals = { 'vim' }, 60 }, 61 workspace = { 62 -- Make the server aware of Neovim runtime files 63 library = vim.api.nvim_get_runtime_file('', true), 64 checkThirdParty = false, 65 }, 66 -- Do not send telemetry data containing a randomized but unique identifier 67 telemetry = { 68 enable = false, 69 }, 70 }, 71 }, 72} 73 74lspconfig['nixd'].setup { 75 settings = { 76 nixd = { 77 formatting = { 78 command = { "nixfmt" }, 79 }, 80 }, 81 }, 82} 83 84-- wrapper around lspconfig['ltex-ls'] with support for hide false positive 85require('ltex-ls').setup { 86 on_attach = On_attach, 87 capabilities = Capabilities, 88 use_spellfile = false, 89 filetypes = { 'markdown', 'latex', 'tex', 'bib', 'plaintext', 'mail', 'gitcommit', 'typst' }, 90 settings = { 91 ltex = { 92 flags = { debounce_text_changes = 300 }, 93 language = 'en-GB', 94 sentenceCacheSize = 2000, 95 disabledRules = { 96 ['en-GB'] = { 97 'MORFOLOGIK_RULE_EN_GB', 98 'OXFORD_SPELLING_Z_NOT_S', 99 }, 100 }, 101 }, 102 }, 103}