lsp.lua 2.7 KB

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