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

M.config = function()
  O.lang.terraform = {
    formatter = {
      exe = "terraform",
      args = { "fmt" },
      stdin = false,
    },
  }
end

M.format = function()
  O.formatters.filetype["hcl"] = {
    function()
      return {
        exe = O.lang.terraform.formatter.exe,
        args = O.lang.terraform.formatter.args,
        stdin = not (O.lang.terraform.formatter.stdin ~= nil),
      }
    end,
  }
  O.formatters.filetype["tf"] = O.formatters.filetype["hcl"]

  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 "terraformls" then
    return
  end

  require("lspconfig").terraformls.setup {
    cmd = { DATA_PATH .. "/lspinstall/terraform/terraform-ls", "serve" },
    on_attach = require("lsp").common_on_attach,
    filetypes = { "tf", "terraform", "hcl" },
  }
end

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

return M