123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- 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,
- on_attach = on_attach,
- });
- 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,
- },
- on_attach = function(client, bufnr)
- -- 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
- on_attach(client, bufnr)
- end,
- })
- end
- if vim.fn.executable("deno") == 1 then
- nvim_lsp.denols.setup({
- capabilities = capabilities,
- on_attach = on_attach,
- });
- 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_attach = function(client, bufnr)
- -- mark tsserver as not having formatting available as we rely on
- -- eslint for that
- client.server_capabilities.documentFormattingProvider = false
- client.server_capabilities.documentRangeFormattingProvider = 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("gopls") == 1 then
- nvim_lsp.gopls.setup({
- capabilities = capabilities,
- on_attach = on_attach,
- });
- end
- if vim.fn.executable("solargraph") == 1 then
- nvim_lsp.solargraph.setup({
- capabilities = capabilities,
- on_attach = on_attach,
- init_options = {
- formatting = false,
- }
- })
- end
- if vim.fn.executable("nil") == 1 then
- nvim_lsp.nil_ls.setup({
- on_attach = on_attach,
- });
- end
- -- format on save
- local group = vim.api.nvim_create_augroup('LspFormatting', { clear = false })
- vim.api.nvim_create_autocmd('LspAttach', {
- callback = function(args)
- local bufnr = args.buf
- local client = vim.lsp.get_client_by_id(args.data.client_id)
- if client.server_capabilities.documentFormattingProvider 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 = function()
- vim.lsp.buf.format()
- end,
- })
- 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,
- on_attach = on_attach,
- })
- -- show LSP progress bar
- require('fidget').setup()
|