ruby.lua 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. local M = {}
  2. M.config = function()
  3. O.lang.ruby = {
  4. diagnostics = {
  5. virtualtext = { spacing = 0, prefix = "" },
  6. signs = true,
  7. underline = true,
  8. },
  9. filetypes = { "rb", "erb", "rakefile", "ruby" },
  10. formatter = {
  11. exe = "rufo",
  12. args = { "-x" },
  13. stdin = true,
  14. },
  15. linters = { "ruby" },
  16. lsp = {
  17. path = DATA_PATH .. "/lspinstall/ruby/solargraph/solargraph",
  18. },
  19. }
  20. end
  21. M.format = function()
  22. O.formatters.filetype["ruby"] = {
  23. function()
  24. return {
  25. exe = O.lang.ruby.formatter.exe,
  26. args = O.lang.ruby.formatter.args,
  27. stdin = O.lang.ruby.formatter.stdin,
  28. }
  29. end,
  30. }
  31. require("formatter.config").set_defaults {
  32. logging = false,
  33. filetype = O.formatters.filetype,
  34. }
  35. end
  36. M.lint = function()
  37. require("lint").linters_by_ft = {
  38. ruby = O.lang.ruby.linters,
  39. }
  40. end
  41. M.lsp = function()
  42. if not require("lv-utils").check_lsp_client_active "sorbet" then
  43. require("lspconfig").sorbet.setup {}
  44. end
  45. if not require("lv-utils").check_lsp_client_active "solargraph" then
  46. -- If you are using rvm, make sure to change below configuration
  47. require("lspconfig").solargraph.setup {
  48. cmd = { O.lang.ruby.lsp.path, "stdio" },
  49. on_attach = require("lsp").common_on_attach,
  50. handlers = {
  51. ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
  52. virtual_text = O.lang.ruby.diagnostics.virtual_text,
  53. signs = O.lang.ruby.diagnostics.signs,
  54. underline = O.lang.ruby.diagnostics.underline,
  55. update_in_insert = true,
  56. }),
  57. },
  58. filetypes = O.lang.ruby.filetypes,
  59. }
  60. end
  61. end
  62. M.dap = function()
  63. -- gem install readapt ruby-debug-ide
  64. if O.plugin.dap.active then
  65. local dap_install = require "dap-install"
  66. dap_install.config("ruby_vsc_dbg", {})
  67. end
  68. end
  69. return M