lsp.lua 2.6 KB

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