lsp.lua 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. vim.diagnostic.config({
  2. -- only show virtual text for WARN and higher
  3. virtual_text = { severity = { min = vim.diagnostic.severity.WARN } },
  4. })
  5. vim.lsp.config("*", {
  6. flags = {
  7. debounce_text_changes = 250,
  8. }
  9. })
  10. vim.lsp.enable("bashls");
  11. vim.lsp.enable("eslint");
  12. if vim.fn.executable("dprint") == 1 then
  13. local version = vim.version.parse(vim.fn.system("dprint --version"))
  14. if vim.version.cmp(version, {0,45,0}) >= 0 then
  15. vim.lsp.enable("dprint")
  16. end
  17. end
  18. if vim.fn.executable("deno") == 1 then
  19. vim.lsp.enable("deno");
  20. else
  21. local function make_settings()
  22. -- we disable formatting but these are still used when performing some code
  23. -- actions
  24. local format = {
  25. indentSize = vim.bo.shiftwidth,
  26. convertTabsToSpaces = vim.o.expandtab,
  27. }
  28. return {
  29. javascript = { format = format },
  30. typescript = { format = format },
  31. }
  32. end
  33. vim.lsp.config("ts_ls", {
  34. init_options = {
  35. completionDisableFilterText = true,
  36. preferences = {
  37. importModuleSpecifierPreference = 'non-relative',
  38. -- this prevents renames from aliasing when destructuring
  39. providePrefixAndSuffixTextForRename = false,
  40. },
  41. },
  42. settings = make_settings(),
  43. handlers = {
  44. ['$/typescriptVersion'] = function(err, result, ctx, config)
  45. vim.notify(string.format('Typescript %s', result.version))
  46. end,
  47. },
  48. on_init = function(client)
  49. -- mark tsserver as not having formatting available as we rely on
  50. -- eslint and dprint for that
  51. client.server_capabilities.documentFormattingProvider = false
  52. client.server_capabilities.documentRangeFormattingProvider = false
  53. -- we only really know our settings once we've opened a file so report
  54. -- the new formatting settings
  55. client:notify(vim.lsp.protocol.Methods.workspace_didChangeConfiguration, {
  56. settings = make_settings(),
  57. })
  58. end,
  59. })
  60. vim.lsp.enable("ts_ls")
  61. end
  62. if vim.fn.executable("gopls") == 1 then
  63. vim.lsp.enable("gopls")
  64. end
  65. if vim.fn.executable("ruby-lsp") == 1 then
  66. vim.lsp.config("ruby_lsp", {
  67. init_options = {
  68. enabledFeatures = {
  69. formatting = false,
  70. },
  71. }
  72. })
  73. vim.lsp.enable("ruby_lsp")
  74. end
  75. if vim.fn.executable("nil") == 1 then
  76. vim.lsp.enable("nil_ls")
  77. end
  78. if vim.fn.executable("jdtls") == 1 then
  79. vim.lsp.config("jdtls", {
  80. handlers = {
  81. ["$/progress"] = function()
  82. -- this is quite noisy so just disable it
  83. end
  84. },
  85. })
  86. vim.lsp.enable("jdtls")
  87. end
  88. -- custom LSP servers
  89. vim.lsp.config("elvish", {
  90. cmd = {'elvish', '--lsp'},
  91. filetypes = {'elvish'},
  92. settings = {},
  93. })
  94. vim.lsp.enable("elvish")