Browse Source

terraform formatter

christianchiarulli 4 years ago
parent
commit
ef44a4f3c6
2 changed files with 23 additions and 1 deletions
  1. 16 0
      ftplugin/tf.lua
  2. 7 1
      lua/default-config.lua

+ 16 - 0
ftplugin/tf.lua

@@ -1,3 +1,19 @@
+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,
+}
+
 if require("lv-utils").check_lsp_client_active "terraformls" then
   return
 end

+ 7 - 1
lua/default-config.lua

@@ -259,7 +259,13 @@ O = {
         "typescriptreact",
       },
     },
-    terraform = {},
+    terraform = {
+      formatter = {
+        exe = "terraform",
+        args = { "fmt" },
+        stdin = false,
+      },
+    },
     tsserver = {
       -- @usage can be 'eslint' or 'eslint_d'
       linter = "",