diff --git a/init.lua b/init.lua index 088405b..bac8b95 100644 --- a/init.lua +++ b/init.lua @@ -18,6 +18,7 @@ vim.pack.add({ { src = "https://github.com/neovim/nvim-lspconfig" }, { src = "https://github.com/sainnhe/everforest" }, { src = "https://github.com/nvim-lualine/lualine.nvim" }, + { src = "https://github.com/stevearc/conform.nvim" }, -- autoclosing tags { src = "https://github.com/windwp/nvim-ts-autotag" }, @@ -267,29 +268,22 @@ vim.api.nvim_create_autocmd('TextYankPost', { end, }) -vim.api.nvim_create_autocmd('BufWritePost', { - desc = 'Autoformat code on safe with prettier', - pattern = '*.html', - callback = function() - local filepath = vim.fn.expand('%:p') - vim.fn.system({ 'npx', 'prettier', '--write', filepath }) - vim.cmd('edit!') - end, +require("conform").setup({ + formatters_by_ft = { + html = { "prettier" }, + }, + default_format_opts = { + lsp_format = "fallback", + }, }) vim.api.nvim_create_autocmd('BufWritePre', { - desc = 'Autoformat code on save with lsp', + desc = 'Autoformat code on save', pattern = '*', - callback = function() - local filetype = vim.bo.filetype - if filetype == "html" then - return - end - - vim.lsp.buf.format({ async = false }) + callback = function(args) + require("conform").format({ bufnr = args.buf }) end, }) - vim.filetype.add({ extension = { templ = "templ" } })