feat: use prettier for html

This commit is contained in:
2025-11-11 21:55:48 +01:00
parent 6e3ff2a8a9
commit 6865b4f655

View File

@@ -18,9 +18,6 @@ vim.pack.add({
{ src = "https://github.com/neovim/nvim-lspconfig" }, { src = "https://github.com/neovim/nvim-lspconfig" },
{ src = "https://github.com/sainnhe/everforest" }, { src = "https://github.com/sainnhe/everforest" },
{ src = "https://github.com/nvim-lualine/lualine.nvim" }, { src = "https://github.com/nvim-lualine/lualine.nvim" },
-- currently not working, see https://github.com/laytan/tailwind-sorter.nvim/issues/114
-- { src = "https://github.com/laytan/tailwind-sorter.nvim" },
-- { src = "https://github.com/nvim-lua/plenary.nvim" }, -- required by tailwind-sorter
-- autoclosing tags -- autoclosing tags
{ src = "https://github.com/windwp/nvim-ts-autotag" }, { src = "https://github.com/windwp/nvim-ts-autotag" },
@@ -176,7 +173,16 @@ vim.lsp.config('jdtls', {
}, },
}, },
}) })
vim.lsp.enable({ "lua_ls", "gopls", "templ", "ts_ls", "tailwindcss", "bashls", "jdtls" })
vim.lsp.enable({
"lua_ls",
"gopls",
"templ",
"ts_ls",
"tailwindcss",
"bashls",
"jdtls",
})
-- Enables filtered completions for tailwindcss class names, e.g. "mt-<C-n>". -- Enables filtered completions for tailwindcss class names, e.g. "mt-<C-n>".
-- Otherwise the completion contains EVERYTHING -- Otherwise the completion contains EVERYTHING
@@ -261,19 +267,28 @@ vim.api.nvim_create_autocmd('TextYankPost', {
end, 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,
})
vim.api.nvim_create_autocmd('BufWritePre', { vim.api.nvim_create_autocmd('BufWritePre', {
desc = 'Atuformat code on save', desc = 'Autoformat code on save with lsp',
pattern = '*', pattern = '*',
callback = function() callback = function()
vim.lsp.buf.format() local filetype = vim.bo.filetype
if filetype == "html" then
return
end
vim.lsp.buf.format({ async = false })
end, end,
}) })
-- require('tailwind-sorter').setup({
-- on_save_enabled = true,
-- on_save_pattern = { '*.html' },
-- trim_spaces = false,
-- })
vim.filetype.add({ extension = { templ = "templ" } }) vim.filetype.add({ extension = { templ = "templ" } })