12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- -- only show virtual text for WARN and higher
- vim.diagnostic.config({
- virtual_text = { severity = { min = vim.diagnostic.severity.WARN } }
- })
- local nvim_lsp = require('lspconfig')
- local null_ls = require('null-ls')
- local null_ls_sources = {
- null_ls.builtins.code_actions.gitsigns,
- }
- -- enable LS / null-ls sources based on executable presence
- if vim.fn.executable("node_modules/.bin/eslint") == 1 then
- table.insert(null_ls_sources, null_ls.builtins.formatting.eslint_d)
- table.insert(null_ls_sources, null_ls.builtins.diagnostics.eslint_d)
- table.insert(null_ls_sources, null_ls.builtins.code_actions.eslint_d)
- end
- if vim.fn.executable("shellcheck") == 1 then
- table.insert(null_ls_sources, null_ls.builtins.diagnostics.shellcheck)
- table.insert(null_ls_sources, null_ls.builtins.code_actions.shellcheck)
- end
- if vim.fn.executable("deno") == 1 then
- nvim_lsp.denols.setup({
- on_attach = on_attach,
- });
- end
- if vim.fn.executable("gopls") == 1 then
- nvim_lsp.gopls.setup({
- on_attach = on_attach,
- });
- elseif vim.fn.executable("gofmt") == 1 then
- table.insert(null_ls_sources, null_ls.builtins.formatting.gofmt)
- end
- if vim.fn.executable("node_modules/.bin/tsc") == 1 then
- require('typescript').setup({
- server = {
- flags = {
- debounce_text_changes = 150,
- },
- on_attach = function(client, bufnr)
- -- mark tsserver as not having formatting available as we rely on
- -- null-ls/eslint for that and having both available makes nvim ask us
- -- which LS to use everytime we format
- client.resolved_capabilities.document_formatting = false
- client.resolved_capabilities.document_range_formatting = false
- on_attach(client, bufnr)
- -- override mappings for typescript
- local opts = { silent = true, buffer = bufnr }
- -- exclude import statements from reference search (may have false positives)
- vim.keymap.set('n', 'gr', '<cmd>Telescope lsp_references default_text=!import\\ <CR>', opts)
- end
- }
- })
- end
- if vim.fn.executable("solargraph") == 1 then
- nvim_lsp.solargraph.setup({
- on_attach = on_attach,
- init_options = {
- formatting = false,
- }
- })
- end
- local group = vim.api.nvim_create_augroup('LspFormatting', { clear = false })
- null_ls.setup({
- sources = null_ls_sources,
- on_attach = function(client, bufnr)
- -- format on save
- if client.resolved_capabilities.document_formatting then
- for key, cmd in pairs(vim.api.nvim_get_autocmds({ group = group, buffer = bufnr })) do
- vim.api.nvim_del_autocmd(cmd.id)
- end
- vim.api.nvim_create_autocmd('BufWritePre', {
- group = group,
- buffer = bufnr,
- callback = vim.lsp.buf.formatting_sync,
- })
- end
- end,
- });
- -- show LSP progress bar
- require('fidget').setup()
|