ruby.lua 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. }
  17. end
  18. M.format = function()
  19. O.formatters.filetype["ruby"] = {
  20. function()
  21. return {
  22. exe = O.lang.ruby.formatter.exe,
  23. args = O.lang.ruby.formatter.args,
  24. stdin = O.lang.ruby.formatter.stdin,
  25. }
  26. end,
  27. }
  28. require("formatter.config").set_defaults {
  29. logging = false,
  30. filetype = O.formatters.filetype,
  31. }
  32. end
  33. M.lint = function()
  34. require("lint").linters_by_ft = {
  35. ruby = O.lang.ruby.linters,
  36. }
  37. end
  38. M.lsp = function()
  39. if require("lv-utils").check_lsp_client_active "solargraph" then
  40. return
  41. end
  42. -- If you are using rvm, make sure to change below configuration
  43. require("lspconfig").solargraph.setup {
  44. cmd = { DATA_PATH .. "/lspinstall/ruby/solargraph/solargraph", "stdio" },
  45. on_attach = require("lsp").common_on_attach,
  46. handlers = {
  47. ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
  48. virtual_text = O.lang.ruby.diagnostics.virtual_text,
  49. signs = O.lang.ruby.diagnostics.signs,
  50. underline = O.lang.ruby.diagnostics.underline,
  51. update_in_insert = true,
  52. }),
  53. },
  54. filetypes = O.lang.ruby.filetypes,
  55. }
  56. end
  57. M.dap = function()
  58. -- TODO: implement dap
  59. return "No DAP configured!"
  60. end
  61. return M