diff --git a/init.lua b/init.lua index bebd379..088405b 100644 --- a/init.lua +++ b/init.lua @@ -18,9 +18,6 @@ vim.pack.add({ { src = "https://github.com/neovim/nvim-lspconfig" }, { src = "https://github.com/sainnhe/everforest" }, { 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 { 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-". -- Otherwise the completion contains EVERYTHING @@ -261,19 +267,28 @@ 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, +}) vim.api.nvim_create_autocmd('BufWritePre', { - desc = 'Atuformat code on save', + desc = 'Autoformat code on save with lsp', pattern = '*', callback = function() - vim.lsp.buf.format() + local filetype = vim.bo.filetype + if filetype == "html" then + return + end + + vim.lsp.buf.format({ async = false }) end, }) --- require('tailwind-sorter').setup({ --- on_save_enabled = true, --- on_save_pattern = { '*.html' }, --- trim_spaces = false, --- }) vim.filetype.add({ extension = { templ = "templ" } })