lsp.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. vim.diagnostic.config({
  2. -- only show virtual text for WARN and higher
  3. virtual_text = { severity = { min = vim.diagnostic.severity.WARN } },
  4. })
  5. local capabilities = require('cmp_nvim_lsp').default_capabilities()
  6. local nvim_lsp = require('lspconfig')
  7. if vim.fn.executable("node_modules/.bin/eslint") == 1 then
  8. local options = {}
  9. -- some projects have local rules, this isn't exactly generic but is good
  10. -- enough
  11. if vim.fn.isdirectory("lint-rules") == 1 then
  12. options.rulePaths = { "./lint-rules" }
  13. end
  14. nvim_lsp.eslint.setup({
  15. settings = {
  16. options = options,
  17. },
  18. on_attach = function(client, bufnr)
  19. -- add formatting capability, the language server registers this
  20. -- dynamically but neovim does not support that yet
  21. -- https://github.com/microsoft/vscode-eslint/pull/1307
  22. client.server_capabilities.documentFormattingProvider = true
  23. client.server_capabilities.documentRangeFormattingProvider = true
  24. on_attach(client, bufnr)
  25. end,
  26. })
  27. end
  28. if vim.fn.executable("deno") == 1 then
  29. nvim_lsp.denols.setup({
  30. capabilities = capabilities,
  31. on_attach = on_attach,
  32. });
  33. else
  34. require('typescript').setup({
  35. server = {
  36. init_options = {
  37. completionDisableFilterText = true,
  38. },
  39. capabilities = capabilities,
  40. handlers = {
  41. ['$/typescriptVersion'] = function(err, result, ctx, config)
  42. vim.notify(string.format('Typescript %s', result.version))
  43. end
  44. },
  45. flags = {
  46. debounce_text_changes = 150,
  47. },
  48. on_attach = function(client, bufnr)
  49. -- mark tsserver as not having formatting available as we rely on
  50. -- eslint for that
  51. client.server_capabilities.documentFormattingProvider = false
  52. client.server_capabilities.documentRangeFormattingProvider = false
  53. on_attach(client, bufnr)
  54. -- override mappings for typescript
  55. local opts = { silent = true, buffer = bufnr }
  56. -- exclude import statements from reference search (may have false positives)
  57. vim.keymap.set('n', 'gr', '<cmd>Telescope lsp_references default_text=!import\\ <CR>', opts)
  58. end
  59. }
  60. })
  61. end
  62. if vim.fn.executable("gopls") == 1 then
  63. nvim_lsp.gopls.setup({
  64. capabilities = capabilities,
  65. on_attach = on_attach,
  66. });
  67. end
  68. if vim.fn.executable("solargraph") == 1 then
  69. nvim_lsp.solargraph.setup({
  70. capabilities = capabilities,
  71. on_attach = on_attach,
  72. init_options = {
  73. formatting = false,
  74. }
  75. })
  76. end
  77. if vim.fn.executable("nil") == 1 then
  78. nvim_lsp.nil_ls.setup({
  79. on_attach = on_attach,
  80. });
  81. end
  82. local group = vim.api.nvim_create_augroup('LspFormatting', { clear = false })
  83. -- custom LSP servers
  84. local configs = require('lspconfig.configs')
  85. if not configs.elvish then
  86. configs.elvish = {
  87. default_config = {
  88. cmd = {'elvish', '--lsp'},
  89. filetypes = {'elvish'},
  90. root_dir = nvim_lsp.util.root_pattern('*.elv'),
  91. settings = {},
  92. },
  93. }
  94. end
  95. nvim_lsp.elvish.setup({
  96. capabilities = capabilities,
  97. on_attach = on_attach,
  98. })
  99. -- show LSP progress bar
  100. require('fidget').setup()