1
0

lsp.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. nvim_lsp.bashls.setup({
  8. capabilities = capabilities,
  9. });
  10. nvim_lsp.eslint.setup({
  11. capabilities = capabilities,
  12. });
  13. if vim.fn.executable("dprint") == 1 then
  14. local version = vim.version.parse(vim.fn.system("dprint --version"))
  15. if vim.version.cmp(version, {0,45,0}) >= 0 then
  16. nvim_lsp.dprint.setup({})
  17. end
  18. end
  19. if vim.fn.executable("deno") == 1 then
  20. nvim_lsp.denols.setup({
  21. capabilities = capabilities,
  22. });
  23. else
  24. require('typescript').setup({
  25. server = {
  26. init_options = {
  27. completionDisableFilterText = true,
  28. preferences = {
  29. importModuleSpecifierPreference = 'non-relative',
  30. -- this prevents renames from aliasing when destructuring
  31. providePrefixAndSuffixTextForRename = false,
  32. },
  33. },
  34. capabilities = capabilities,
  35. handlers = {
  36. ['$/typescriptVersion'] = function(err, result, ctx, config)
  37. vim.notify(string.format('Typescript %s', result.version))
  38. end
  39. },
  40. flags = {
  41. debounce_text_changes = 150,
  42. },
  43. on_init = function(client)
  44. -- mark tsserver as not having formatting available as we rely on
  45. -- eslint and dprint for that
  46. client.server_capabilities.documentFormattingProvider = false
  47. client.server_capabilities.documentRangeFormattingProvider = false
  48. end,
  49. }
  50. })
  51. end
  52. if vim.fn.executable("gopls") == 1 then
  53. nvim_lsp.gopls.setup({
  54. capabilities = capabilities,
  55. });
  56. end
  57. if vim.fn.executable("solargraph") == 1 then
  58. nvim_lsp.solargraph.setup({
  59. capabilities = capabilities,
  60. init_options = {
  61. formatting = false,
  62. }
  63. })
  64. end
  65. if vim.fn.executable("nil") == 1 then
  66. nvim_lsp.nil_ls.setup({
  67. capabilities = capabilities,
  68. });
  69. end
  70. if vim.fn.executable("jdtls") == 1 then
  71. nvim_lsp.jdtls.setup({
  72. capabilities = capabilities,
  73. handlers = {
  74. ["$/progress"] = function()
  75. -- this is quite noisy so just disable it
  76. end
  77. },
  78. });
  79. end
  80. -- custom LSP servers
  81. local configs = require('lspconfig.configs')
  82. if not configs.elvish then
  83. configs.elvish = {
  84. default_config = {
  85. cmd = {'elvish', '--lsp'},
  86. filetypes = {'elvish'},
  87. root_dir = nvim_lsp.util.root_pattern('*.elv'),
  88. settings = {},
  89. },
  90. }
  91. end
  92. nvim_lsp.elvish.setup({
  93. capabilities = capabilities,
  94. })