diff options
author | Angelo Fallaria <ba.fallaria@gmail.com> | 2024-02-13 11:41:25 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-12 19:41:25 -0800 |
commit | a34b66f9a4a8f4fb8e270ebfa9c8836fdb8381c1 (patch) | |
tree | c3ba449131054a05e900fd8eb8cb43b331701eb4 /lua/conform/formatters | |
parent | c0e0e80f0c233cb3a249f719a44324c660163a3f (diff) |
feat: add ReScript formatter (#293)
Diffstat (limited to 'lua/conform/formatters')
-rw-r--r-- | lua/conform/formatters/rescript-format.lua | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lua/conform/formatters/rescript-format.lua b/lua/conform/formatters/rescript-format.lua new file mode 100644 index 0000000..806b380 --- /dev/null +++ b/lua/conform/formatters/rescript-format.lua @@ -0,0 +1,40 @@ +-- The formatter expects one of [.res | .resi | .ml | .mli] passed as +-- the value to the '-stdin' argument. +local valid_extensions = { + res = true, + resi = true, + ml = true, + mli = true, +} + +local default_extension = "res" + +---@type conform.FileFormatterConfig +return { + meta = { + url = "https://rescript-lang.org/", + description = "The built-in ReScript formatter.", + }, + command = "rescript", + args = function(self, ctx) + local extension = vim.fn.fnamemodify(ctx.filename, ":e") + + local is_invalid_extension = valid_extensions[extension] == nil + if is_invalid_extension then + extension = default_extension + end + + return { + "format", + "-stdin", + "." .. extension, + } + end, + stdin = true, + + require_cwd = true, + cwd = require("conform.util").root_file({ + "rescript.json", + "bsconfig.json", + }), +} |