summaryrefslogtreecommitdiff
path: root/lua/lang/ruby.lua
blob: 8b3b1a76f83065a66ecb2dbde79941400a06392f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
local M = {}

M.config = function()
  O.lang.ruby = {
    diagnostics = {
      virtualtext = { spacing = 0, prefix = "" },
      signs = true,
      underline = true,
    },
    filetypes = { "rb", "erb", "rakefile", "ruby" },
    formatter = {
      exe = "rufo",
      args = { "-x" },
      stdin = true,
    },
    linters = { "ruby" },
  }
end

M.format = function()
  O.formatters.filetype["ruby"] = {
    function()
      return {
        exe = O.lang.ruby.formatter.exe,
        args = O.lang.ruby.formatter.args,
        stdin = O.lang.ruby.formatter.stdin,
      }
    end,
  }

  require("formatter.config").set_defaults {
    logging = false,
    filetype = O.formatters.filetype,
  }
end

M.lint = function()
  require("lint").linters_by_ft = {
    ruby = O.lang.ruby.linters,
  }
end

M.lsp = function()
  if not require("lv-utils").check_lsp_client_active "sorbet" then
    require("lspconfig").sorbet.setup {}
  end

  if not require("lv-utils").check_lsp_client_active "solargraph" then
    -- If you are using rvm, make sure to change below configuration
    require("lspconfig").solargraph.setup {
      cmd = { DATA_PATH .. "/lspinstall/ruby/solargraph/solargraph", "stdio" },
      on_attach = require("lsp").common_on_attach,
      handlers = {
        ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
          virtual_text = O.lang.ruby.diagnostics.virtual_text,
          signs = O.lang.ruby.diagnostics.signs,
          underline = O.lang.ruby.diagnostics.underline,
          update_in_insert = true,
        }),
      },
      filetypes = O.lang.ruby.filetypes,
    }
  end
end

M.dap = function()
  -- gem install readapt ruby-debug-ide
  if O.plugin.dap.active then
    local dap_install = require "dap-install"
    dap_install.config("ruby_vsc_dbg", {})
  end
end

return M