lsp.lua 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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',
  38. 'preferences')
  39. if helix_preferences ~= nil then
  40. preferences = vim.tbl_deep_extend('force', preferences, helix_preferences)
  41. end
  42. local function make_settings()
  43. -- we disable formatting but these are still used when performing some code
  44. -- actions
  45. local format = {
  46. indentSize = vim.bo.shiftwidth,
  47. convertTabsToSpaces = vim.o.expandtab,
  48. }
  49. return {
  50. javascript = { format = format },
  51. typescript = { format = format },
  52. }
  53. end
  54. vim.lsp.config('ts_ls', {
  55. init_options = {
  56. completionDisableFilterText = true,
  57. preferences = preferences,
  58. },
  59. settings = make_settings(),
  60. handlers = {
  61. ['$/typescriptVersion'] = function(err, result, ctx, config)
  62. vim.notify(string.format('Typescript %s', result.version))
  63. end,
  64. },
  65. on_init = function(client)
  66. -- mark tsserver as not having formatting available as we rely on
  67. -- eslint and dprint for that
  68. client.server_capabilities.documentFormattingProvider = false
  69. client.server_capabilities.documentRangeFormattingProvider = false
  70. -- we only really know our settings once we've opened a file so report
  71. -- the new formatting settings
  72. client:notify(vim.lsp.protocol.Methods.workspace_didChangeConfiguration, {
  73. settings = make_settings(),
  74. })
  75. end,
  76. })
  77. vim.lsp.enable('ts_ls')
  78. end
  79. if vim.fn.executable('gopls') == 1 then
  80. vim.lsp.enable('gopls')
  81. end
  82. if vim.fn.executable('ruby-lsp') == 1 then
  83. vim.lsp.config('ruby_lsp', {
  84. init_options = {
  85. enabledFeatures = {
  86. formatting = false,
  87. },
  88. }
  89. })
  90. vim.lsp.enable('ruby_lsp')
  91. end
  92. if vim.fn.executable('nil') == 1 then
  93. vim.lsp.enable('nil_ls')
  94. end
  95. if vim.fn.executable('jdtls') == 1 then
  96. vim.lsp.config('jdtls', {
  97. handlers = {
  98. ['$/progress'] = function()
  99. -- this is quite noisy so just disable it
  100. end
  101. },
  102. })
  103. vim.lsp.enable('jdtls')
  104. end
  105. vim.lsp.enable('lua_ls')
  106. -- custom LSP servers
  107. vim.lsp.config('elvish', {
  108. cmd = { 'elvish', '--lsp' },
  109. filetypes = { 'elvish' },
  110. settings = {},
  111. })
  112. vim.lsp.enable('elvish')