vim.diagnostic.config({ -- only show virtual text for WARN and higher virtual_text = { severity = { min = vim.diagnostic.severity.WARN } }, }) local capabilities = require('cmp_nvim_lsp').default_capabilities() local nvim_lsp = require('lspconfig') nvim_lsp.bashls.setup({ capabilities = capabilities, }); if vim.fn.executable("node_modules/.bin/eslint") == 1 then local options = {} -- some projects have local rules, this isn't exactly generic but is good -- enough if vim.fn.isdirectory("lint-rules") == 1 then options.rulePaths = { "./lint-rules" } end nvim_lsp.eslint.setup({ settings = { options = options, }, handlers = { ["client/registerCapability"] = function(err, result, ctx, config) -- ignore as we can't handle any of this and it just spams the logs return vim.NIL end }, on_init = function(client) -- add formatting capability, the language server registers this -- dynamically but neovim does not support that yet -- https://github.com/microsoft/vscode-eslint/pull/1307 client.server_capabilities.documentFormattingProvider = true client.server_capabilities.documentRangeFormattingProvider = true end, }) end if vim.fn.executable("dprint") == 1 then local version = vim.version.parse(vim.fn.system("dprint --version")) if vim.version.cmp(version, {0,45,0}) >= 0 then nvim_lsp.dprint.setup({}) end end if vim.fn.executable("deno") == 1 then nvim_lsp.denols.setup({ capabilities = capabilities, }); else require('typescript').setup({ server = { init_options = { completionDisableFilterText = true, preferences = { importModuleSpecifierPreference = 'non-relative', }, }, capabilities = capabilities, handlers = { ['$/typescriptVersion'] = function(err, result, ctx, config) vim.notify(string.format('Typescript %s', result.version)) end }, flags = { debounce_text_changes = 150, }, on_init = function(client) -- mark tsserver as not having formatting available as we rely on -- eslint and dprint for that client.server_capabilities.documentFormattingProvider = false client.server_capabilities.documentRangeFormattingProvider = false end, } }) end if vim.fn.executable("gopls") == 1 then nvim_lsp.gopls.setup({ capabilities = capabilities, }); end if vim.fn.executable("solargraph") == 1 then nvim_lsp.solargraph.setup({ capabilities = capabilities, init_options = { formatting = false, } }) end if vim.fn.executable("nil") == 1 then nvim_lsp.nil_ls.setup({ capabilities = capabilities, }); end if vim.fn.executable("jdtls") == 1 then nvim_lsp.jdtls.setup({ capabilities = capabilities, handlers = { ["$/progress"] = function() -- this is quite noisy so just disable it end }, }); end -- custom LSP servers local configs = require('lspconfig.configs') if not configs.elvish then configs.elvish = { default_config = { cmd = {'elvish', '--lsp'}, filetypes = {'elvish'}, root_dir = nvim_lsp.util.root_pattern('*.elv'), settings = {}, }, } end nvim_lsp.elvish.setup({ capabilities = capabilities, })