nvim: Start integrating treefmt
This commit is contained in:
parent
d97ba0b62b
commit
4a80ad30fa
3 changed files with 49 additions and 8 deletions
|
@ -160,6 +160,8 @@
|
||||||
config.treefmt.build.devShell
|
config.treefmt.build.devShell
|
||||||
config.pre-commit.devShell
|
config.pre-commit.devShell
|
||||||
];
|
];
|
||||||
|
|
||||||
|
TREEFMT_CONFIG_FILE = config.treefmt.build.configFile;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,39 @@
|
||||||
(let [formatter (require :formatter)
|
(let [M {}
|
||||||
api vim.api]
|
formatter (require :formatter)
|
||||||
|
api vim.api
|
||||||
|
toml (require :toml)
|
||||||
|
treefmt-config-file vim.env.TREEFMT_CONFIG_FILE
|
||||||
|
treefmt-formatters {}]
|
||||||
|
(fn read-file [file]
|
||||||
|
(with-open [f (io.open file :rb)]
|
||||||
|
(f:read :*all)))
|
||||||
|
|
||||||
|
(fn add-option [opts addable]
|
||||||
|
(table.insert opts addable)
|
||||||
|
opts)
|
||||||
|
|
||||||
|
(fn remove-option [opts removeable]
|
||||||
|
(let [new-opts []]
|
||||||
|
(each [i v (ipairs opts)]
|
||||||
|
(when (not= v removeable) (table.insert new-opts v)))
|
||||||
|
new-opts))
|
||||||
|
|
||||||
|
(when (not= treefmt-config-file nil)
|
||||||
|
(let [cfg (toml.parse (read-file treefmt-config-file))]
|
||||||
|
(when (not= cfg.formatter.fnlfmt nil)
|
||||||
|
(set treefmt-formatters.fnlfmt
|
||||||
|
{:exe cfg.formatter.fnlfmt.command
|
||||||
|
:args (-> cfg.formatter.fnlfmt.options (remove-option :--fix)
|
||||||
|
(add-option "-"))}))
|
||||||
|
(when (not= cfg.formatter.shfmt nil)
|
||||||
|
(set treefmt-formatters.shfmt
|
||||||
|
{:exe cfg.formatter.shfmt.command
|
||||||
|
:args (remove-option cfg.formatter.shfmt.options :-w)}))
|
||||||
|
(when (not= cfg.formatter.yamlfmt nil)
|
||||||
|
(set treefmt-formatters.yamlfmt
|
||||||
|
{:exe cfg.formatter.yamlfmt.command
|
||||||
|
:args (add-option cfg.formatter.yamlfmt.options :-in)}))))
|
||||||
|
|
||||||
(fn buffer-filename [] (api.nvim_buf_get_name 0))
|
(fn buffer-filename [] (api.nvim_buf_get_name 0))
|
||||||
|
|
||||||
(fn args-prettier [parser]
|
(fn args-prettier [parser]
|
||||||
|
@ -10,9 +44,14 @@
|
||||||
{:args [:-i shiftwidth]}))
|
{:args [:-i shiftwidth]}))
|
||||||
|
|
||||||
(fn do-format [exe opts]
|
(fn do-format [exe opts]
|
||||||
|
(let [treefmt-formatter (. treefmt-formatters exe)]
|
||||||
|
(if (not= treefmt-formatter nil)
|
||||||
|
treefmt-formatter
|
||||||
(if (= (vim.fn.executable exe) 1)
|
(if (= (vim.fn.executable exe) 1)
|
||||||
(vim.tbl_extend :keep opts {: exe})
|
(vim.tbl_extend :keep opts {: exe})
|
||||||
{:exe :ls :cond #false}))
|
{:exe :ls :cond #false}))))
|
||||||
|
|
||||||
|
(fn M.treefmt-based-formatters [] treefmt-formatters)
|
||||||
|
|
||||||
(formatter.setup {:format_on_save #(not= vim.b.nifoc_formatter_disabled 1)
|
(formatter.setup {:format_on_save #(not= vim.b.nifoc_formatter_disabled 1)
|
||||||
:filetype {:css #(do-format :prettier (args-prettier :css))
|
:filetype {:css #(do-format :prettier (args-prettier :css))
|
||||||
|
@ -29,5 +68,5 @@
|
||||||
:typescript #(do-format :prettier
|
:typescript #(do-format :prettier
|
||||||
(args-prettier :typescript))
|
(args-prettier :typescript))
|
||||||
:yaml #(do-format :yamlfmt {:args [:-in]})}
|
:yaml #(do-format :yamlfmt {:args [:-in]})}
|
||||||
:lsp [:elixirls :nil_ls]}))
|
:lsp [:elixirls :nil_ls]})
|
||||||
|
M)
|
||||||
|
|
|
@ -15,7 +15,7 @@ in
|
||||||
withRuby = false;
|
withRuby = false;
|
||||||
withPython3 = false;
|
withPython3 = false;
|
||||||
|
|
||||||
extraLuaPackages = luaPkgs: with luaPkgs; [ jsregexp readline ];
|
extraLuaPackages = luaPkgs: with luaPkgs; [ jsregexp lua-toml readline ];
|
||||||
|
|
||||||
extraPackages = with pkgs; [
|
extraPackages = with pkgs; [
|
||||||
git
|
git
|
||||||
|
|
Loading…
Reference in a new issue