2023-07-12 18:39:50 +00:00
|
|
|
(let [formatter (require :formatter)
|
2023-07-19 12:48:38 +00:00
|
|
|
api vim.api]
|
|
|
|
(fn buffer-filename [] (api.nvim_buf_get_name 0))
|
2023-07-12 18:39:50 +00:00
|
|
|
|
2023-07-19 12:48:38 +00:00
|
|
|
(fn args-prettier [parser]
|
|
|
|
{:args [:--stdin-filepath (buffer-filename) :--parser parser]})
|
2023-07-13 17:57:12 +00:00
|
|
|
|
2023-07-19 12:48:38 +00:00
|
|
|
(fn args-shfmt []
|
|
|
|
(let [shiftwidth (vim.opt.shiftwidth:get)]
|
|
|
|
{:args [:-i shiftwidth]}))
|
2023-07-12 18:39:50 +00:00
|
|
|
|
2023-07-19 12:48:38 +00:00
|
|
|
(fn do-format [exe opts]
|
|
|
|
(if (= (vim.fn.executable exe) 1)
|
|
|
|
(vim.tbl_extend :keep opts {: exe})
|
|
|
|
{:exe :ls :cond #false}))
|
|
|
|
|
|
|
|
(formatter.setup {:format_on_save #(not= vim.b.nifoc_formatter_disabled 1)
|
|
|
|
:filetype {:css #(do-format :prettier (args-prettier :css))
|
|
|
|
:fennel #(do-format :fnlfmt {:args ["-"]})
|
|
|
|
:fish #(do-format :fish_indent {})
|
|
|
|
:html #(do-format :prettier
|
|
|
|
(args-prettier :html))
|
|
|
|
:javascript #(do-format :prettier
|
|
|
|
(args-prettier :javascript))
|
|
|
|
:json #(do-format :prettier
|
|
|
|
(args-prettier :json))
|
|
|
|
:sh #(do-format :shfmt (args-shfmt))
|
|
|
|
:toml #(do-format :taplo {:args [:fmt "-"]})
|
|
|
|
:typescript #(do-format :prettier
|
|
|
|
(args-prettier :typescript))
|
|
|
|
:yaml #(do-format :yamlfmt {:args [:-in]})}
|
|
|
|
:lsp [:elixirls :nil_ls]}))
|
2023-07-12 18:39:50 +00:00
|
|
|
|