lsp.lua 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. local function read_helix_config()
  11. local tinytoml = require("tinytoml")
  12. local data = vim.secure.read(".helix/languages.toml")
  13. if data ~= nil then
  14. local status, data = pcall(tinytoml.parse, data, { load_from_string = true })
  15. if status then
  16. return data
  17. end
  18. end
  19. return {}
  20. end
  21. vim.lsp.enable("bashls");
  22. vim.lsp.enable("eslint");
  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. vim.lsp.enable("dprint")
  27. end
  28. end
  29. if vim.fn.executable("deno") == 1 then
  30. vim.lsp.enable("deno");
  31. else
  32. local preferences = {
  33. importModuleSpecifierPreference = 'non-relative',
  34. -- this prevents renames from aliasing when destructuring
  35. providePrefixAndSuffixTextForRename = false,
  36. }
  37. local helix_preferences = vim.tbl_get(read_helix_config(), 'language-server', 'typescript-language-server', 'config', 'preferences')
  38. if helix_preferences ~= nil then
  39. preferences = vim.tbl_deep_extend('force', preferences, helix_preferences)
  40. end
  41. local function make_settings()
  42. -- we disable formatting but these are still used when performing some code
  43. -- actions
  44. local format = {
  45. indentSize = vim.bo.shiftwidth,
  46. convertTabsToSpaces = vim.o.expandtab,
  47. }
  48. return {
  49. javascript = { format = format },
  50. typescript = { format = format },
  51. }
  52. end
  53. vim.lsp.config("ts_ls", {
  54. init_options = {
  55. completionDisableFilterText = true,
  56. preferences = preferences,
  57. },
  58. settings = make_settings(),
  59. handlers = {
  60. ['$/typescriptVersion'] = function(err, result, ctx, config)
  61. vim.notify(string.format('Typescript %s', result.version))
  62. end,
  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. -- we only really know our settings once we've opened a file so report
  70. -- the new formatting settings
  71. client:notify(vim.lsp.protocol.Methods.workspace_didChangeConfiguration, {
  72. settings = make_settings(),
  73. })
  74. end,
  75. })
  76. vim.lsp.enable("ts_ls")
  77. end
  78. if vim.fn.executable("gopls") == 1 then
  79. vim.lsp.enable("gopls")
  80. end
  81. if vim.fn.executable("ruby-lsp") == 1 then
  82. vim.lsp.config("ruby_lsp", {
  83. init_options = {
  84. enabledFeatures = {
  85. formatting = false,
  86. },
  87. }
  88. })
  89. vim.lsp.enable("ruby_lsp")
  90. end
  91. if vim.fn.executable("nil") == 1 then
  92. vim.lsp.enable("nil_ls")
  93. end
  94. if vim.fn.executable("jdtls") == 1 then
  95. vim.lsp.config("jdtls", {
  96. handlers = {
  97. ["$/progress"] = function()
  98. -- this is quite noisy so just disable it
  99. end
  100. },
  101. })
  102. vim.lsp.enable("jdtls")
  103. end
  104. -- custom LSP servers
  105. vim.lsp.config("elvish", {
  106. cmd = {'elvish', '--lsp'},
  107. filetypes = {'elvish'},
  108. settings = {},
  109. })
  110. vim.lsp.enable("elvish")