Run treefmt on nvim buffer save
This commit is contained in:
parent
0d6ad4b9c1
commit
4cb90679a2
1 changed files with 18 additions and 11 deletions
|
@ -45,14 +45,21 @@ require("lspconfig").terraformls.setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- require'lspconfig'.efm.setup {
|
local function has_treefmt()
|
||||||
-- on_attach = require("lsp-format").on_attach,
|
local git_root = vim.fn.systemlist("git rev-parse --show-toplevel")[1]
|
||||||
-- init_options = {documentFormatting = true},
|
if vim.v.shell_error ~= 0 then
|
||||||
-- settings = {
|
return false
|
||||||
-- languages = {
|
end
|
||||||
-- lua = {{formatCommand = "lua-format -i", formatStdin = true}},
|
local treefmt_path = git_root .. "/treefmt.nix"
|
||||||
-- nix = {{formatCommand = "nixfmt", formatStdin = true}}
|
return vim.fn.filereadable(treefmt_path) == 1
|
||||||
-- }
|
end
|
||||||
-- },
|
|
||||||
-- filetypes = {"lua", "nix"}
|
vim.api.nvim_create_autocmd("BufWritePost", {
|
||||||
-- }
|
pattern = "*",
|
||||||
|
callback = function()
|
||||||
|
if has_treefmt() then
|
||||||
|
vim.cmd("silent !treefmt > /dev/null 2>&1")
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
group = vim.api.nvim_create_augroup("TreefmtAutoformat", { clear = true }),
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in a new issue