kickstart.nvim
kickstart.nvim copied to clipboard
The conform setup doesn't work for typescript react format second's files
Describe the bug
When I made the format (<space>f) for the first file that I open works ok, but if I open a second *.txs the format file doesn't work, apply a big extra indeed.
Second file with format
My setup:
{ -- Autoformat
'stevearc/conform.nvim',
event = { 'BufWritePre', 'BufNewFile' },
cmd = { 'ConformInfo' },
keys = {
{
'<leader>f',
function()
require('conform').format { async = true, lsp_format = 'fallback' }
end,
mode = '',
desc = '[F]ormat buffer',
},
},
opts = {
notify_on_error = false,
format_on_save = function(bufnr)
-- Disable "format_on_save lsp_fallback" for languages that don't
-- have a well standardized coding style. You can add additional
-- languages here or re-enable it for the disabled ones.
local disable_filetypes = { c = true, cpp = true }
local lsp_format_opt
if disable_filetypes[vim.bo[bufnr].filetype] then
lsp_format_opt = 'never'
else
lsp_format_opt = 'fallback'
end
return {
timeout_ms = 500,
lsp_format = lsp_format_opt,
}
end,
formatters_by_ft = {
lua = { 'stylua' },
-- Conform can also run multiple formatters sequentially
-- python = { "isort", "black" },
--
-- You can use 'stop_after_first' to run the first available formatter from the list
javascript = { 'prettierd', 'prettier' },
html = { 'prettier' },
typescript = { 'prettierd', 'prettier' },
typescriptrc = { 'prettierd', 'prettier' },
go = { 'gopls' },
},
},
},
{
'pmizio/typescript-tools.nvim',
dependencies = { 'nvim-lua/plenary.nvim', 'neovim/nvim-lspconfig' },
opts = {},
},
{ -- Copilotformatt
'zbirenbaum/copilot.lua',
cmd = 'Copilot',
build = ':Copilot auth',
opts = {
suggestion = { enabled = false },
panel = { enabled = false },
},
},
To Reproduce
- Open a
*.tsxfile, apply format, <space>f. - Open a second
*.tsxfile and apply the format, <space>f.
Desktop
- OS: macOS 14.6.1
- Terminal: Versión 2.14
Neovim Version
NVIM v0.10.1
Build type: Release
LuaJIT 2.1.1725453128
File type for .tsx files is typescriptreact, so to format them you can add this to your config:
typescriptreact = { 'prettierd', 'prettier', stop_after_first = true },
Actually for fix every time when this bug appear is updating the Languages in :Mason
The :ConformInfo logs
Work around provided. Closing.