typescript-tools.nvim
typescript-tools.nvim copied to clipboard
[Question] How to prevent keeping history of changes (undo list) made by TSTools* commands?
Currently I have a setup to format and run TSToolsSortImports command when saving the buffer but the changes made by TSToolsSortImports are added in the undo list. Is it possible to prevent that?
The command gets executed with vim.cmd api:
vim.cmd 'TSToolsSortImports'
I've tried with the sync argument and using undojoin but nothing worked.
this is the current setup I have:
return {
'stevearc/conform.nvim',
opts = {
notify_on_error = true,
format_on_save = function(bufnr)
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
return
end
local lsp_format_opt
local disable_filetypes = { c = true, cpp = true }
if disable_filetypes[vim.bo[bufnr].filetype] then
lsp_format_opt = 'never'
else
lsp_format_opt = 'fallback'
end
-- Javascript/Typescript: Sort imports
for _, value in ipairs { 'javascript', 'typescript', 'javascripteract', 'typescriptreact' } do
if vim.bo[bufnr].filetype == value then
vim.cmd 'TSToolsSortImports'
-- attempt 1
-- vim.cmd.undojoin()
-- vim.cmd 'TSToolsSortImports'
-- attempt 2
-- vim.cmd.undojoin()
-- vim.cmd 'TSToolsSortImports sync'
end
end
return { timeout_ms = 500, lsp_format = lsp_format_opt }
end,
formatters_by_ft = {
lua = { 'stylua' },
yaml = { 'prettierd' },
html = { 'prettierd' },
css = { 'prettierd' },
javascript = { 'prettierd' },
typescript = { 'prettierd' },
javascriptreact = { 'prettierd' },
typescriptreact = { 'prettierd' },
},
},
}
I really need something like this as well, its why i had to just disable format on save completely :(
none of the usual tricks seem to be working, not sure why