lsp.lua 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. if vim.fn.executable("node_modules/.bin/eslint") == 1 then
  11. local options = {}
  12. -- some projects have local rules, this isn't exactly generic but is good
  13. -- enough
  14. if vim.fn.isdirectory("lint-rules") == 1 then
  15. options.rulePaths = { "./lint-rules" }
  16. end
  17. nvim_lsp.eslint.setup({
  18. settings = {
  19. options = options,
  20. },
  21. handlers = {
  22. ["client/registerCapability"] = function(err, result, ctx, config)
  23. -- ignore as we can't handle any of this and it just spams the logs
  24. return vim.NIL
  25. end
  26. },
  27. on_init = function(client)
  28. -- add formatting capability, the language server registers this
  29. -- dynamically but neovim does not support that yet
  30. -- https://github.com/microsoft/vscode-eslint/pull/1307
  31. client.server_capabilities.documentFormattingProvider = true
  32. client.server_capabilities.documentRangeFormattingProvider = true
  33. end,
  34. })
  35. end
  36. if vim.fn.executable("dprint") == 1 then
  37. local version = vim.version.parse(vim.fn.system("dprint --version"))
  38. if vim.version.cmp(version, {0,45,0}) >= 0 then
  39. nvim_lsp.dprint.setup({})
  40. end
  41. end
  42. if vim.fn.executable("deno") == 1 then
  43. nvim_lsp.denols.setup({
  44. capabilities = capabilities,
  45. });
  46. else
  47. require('typescript').setup({
  48. server = {
  49. init_options = {
  50. completionDisableFilterText = true,
  51. preferences = {
  52. importModuleSpecifierPreference = 'non-relative',
  53. },
  54. },
  55. capabilities = capabilities,
  56. handlers = {
  57. ['$/typescriptVersion'] = function(err, result, ctx, config)
  58. vim.notify(string.format('Typescript %s', result.version))
  59. end
  60. },
  61. flags = {
  62. debounce_text_changes = 150,
  63. },
  64. on_init = function(client)
  65. -- mark tsserver as not having formatting available as we rely on
  66. -- eslint and dprint for that
  67. client.server_capabilities.documentFormattingProvider = false
  68. client.server_capabilities.documentRangeFormattingProvider = false
  69. end,
  70. }
  71. })
  72. end
  73. if vim.fn.executable("gopls") == 1 then
  74. nvim_lsp.gopls.setup({
  75. capabilities = capabilities,
  76. });
  77. end
  78. if vim.fn.executable("solargraph") == 1 then
  79. nvim_lsp.solargraph.setup({
  80. capabilities = capabilities,
  81. init_options = {
  82. formatting = false,
  83. }
  84. })
  85. end
  86. if vim.fn.executable("nil") == 1 then
  87. nvim_lsp.nil_ls.setup({
  88. capabilities = capabilities,
  89. });
  90. end
  91. if vim.fn.executable("jdtls") == 1 then
  92. nvim_lsp.jdtls.setup({
  93. capabilities = capabilities,
  94. handlers = {
  95. ["$/progress"] = function()
  96. -- this is quite noisy so just disable it
  97. end
  98. },
  99. });
  100. end
  101. -- custom LSP servers
  102. local configs = require('lspconfig.configs')
  103. if not configs.elvish then
  104. configs.elvish = {
  105. default_config = {
  106. cmd = {'elvish', '--lsp'},
  107. filetypes = {'elvish'},
  108. root_dir = nvim_lsp.util.root_pattern('*.elv'),
  109. settings = {},
  110. },
  111. }
  112. end
  113. nvim_lsp.elvish.setup({
  114. capabilities = capabilities,
  115. })