summaryrefslogtreecommitdiff
path: root/lua/lang/r.lua
blob: b05e6ee6a9f58adc3ea7906ae7e2cfefd5bac9d1 (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
local M = {}

M.config = function()
  -- R -e 'install.packages("formatR",repos = "http://cran.us.r-project.org")'
  -- R -e 'install.packages("readr",repos = "http://cran.us.r-project.org")'
  O.lang.r = {
    formatter = {
      exe = "R",
      args = {
        "--slave",
        "--no-restore",
        "--no-save",
        '-e "formatR::tidy_source(text=readr::read_file(file(\\"stdin\\")), arrow=FALSE)"',
      },
      stdin = true,
    },
  }
end

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

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

M.lint = function()
  -- TODO: implement linters (if applicable)
  return "No linters configured!"
end

M.lsp = function()
  if require("lv-utils").check_lsp_client_active "r_language_server" then
    return
  end
  -- R -e 'install.packages("languageserver",repos = "http://cran.us.r-project.org")'
  require("lspconfig").r_language_server.setup {}
end

M.dap = function()
  -- TODO: implement dap
  return "No DAP configured!"
end

return M