From 17b3d146d4a0287d562b6dc411c05b60bebc9d48 Mon Sep 17 00:00:00 2001 From: hwu Date: Mon, 1 Sep 2025 22:04:19 -0400 Subject: [PATCH] add toggle auto format add auto closing html tags --- lua/custom/plugins/formatting.lua | 21 ++++++++++++++++----- lua/custom/plugins/tstools.lua | 14 ++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 lua/custom/plugins/tstools.lua diff --git a/lua/custom/plugins/formatting.lua b/lua/custom/plugins/formatting.lua index 4fda24a1..d58b9d14 100644 --- a/lua/custom/plugins/formatting.lua +++ b/lua/custom/plugins/formatting.lua @@ -1,6 +1,16 @@ return { 'stevearc/conform.nvim', event = { 'BufReadPre', 'BufNewFile' }, + keys = { + { + 'tf', + function() + vim.g.disable_autoformat = not vim.g.disable_autoformat + end, + mode = '', + desc = 'Toggle Format On Save', + }, + }, config = function() local conform = require 'conform' @@ -20,11 +30,12 @@ return { liquid = { 'prettier' }, lua = { 'stylua' }, }, - format_on_save = { - lsp_fallback = true, - async = false, - timeout_ms = 1000, - }, + format_on_save = function(bufnr) + if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then + return + end + return { timeout_ms = 1000, lsp_format = 'fallback' } + end, } end, } diff --git a/lua/custom/plugins/tstools.lua b/lua/custom/plugins/tstools.lua new file mode 100644 index 00000000..216c7929 --- /dev/null +++ b/lua/custom/plugins/tstools.lua @@ -0,0 +1,14 @@ +return { + 'pmizio/typescript-tools.nvim', + dependencies = { 'nvim-lua/plenary.nvim', 'neovim/nvim-lspconfig' }, + config = function() + require('typescript-tools').setup { + settings = { + jsx_close_tag = { + enable = true, + filetypes = { 'javascriptreact', 'typescriptreact', 'javascript' }, + }, + }, + } + end, +}