terraform.lua 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. local M = {}
  2. M.config = function()
  3. O.lang.terraform = {
  4. formatter = {
  5. exe = "terraform",
  6. args = { "fmt" },
  7. stdin = false,
  8. },
  9. lsp = {
  10. path = DATA_PATH .. "/lspinstall/terraform/terraform-ls",
  11. },
  12. }
  13. end
  14. M.format = function()
  15. O.formatters.filetype["hcl"] = {
  16. function()
  17. return {
  18. exe = O.lang.terraform.formatter.exe,
  19. args = O.lang.terraform.formatter.args,
  20. stdin = O.lang.terraform.formatter.stdin,
  21. tempfile_prefix = ".formatter",
  22. }
  23. end,
  24. }
  25. O.formatters.filetype["tf"] = O.formatters.filetype["hcl"]
  26. require("formatter.config").set_defaults {
  27. logging = false,
  28. filetype = O.formatters.filetype,
  29. }
  30. end
  31. M.lint = function()
  32. -- TODO: implement linters (if applicable)
  33. return "No linters configured!"
  34. end
  35. M.lsp = function()
  36. if require("lv-utils").check_lsp_client_active "terraformls" then
  37. return
  38. end
  39. require("lspconfig").terraformls.setup {
  40. cmd = { O.lang.terraform.lsp.path, "serve" },
  41. on_attach = require("lsp").common_on_attach,
  42. filetypes = { "tf", "terraform", "hcl" },
  43. }
  44. end
  45. M.dap = function()
  46. -- TODO: implement dap
  47. return "No DAP configured!"
  48. end
  49. return M