kickstart.nvim icon indicating copy to clipboard operation
kickstart.nvim copied to clipboard

The conform setup doesn't work for typescript react format second's files

Open hendridg opened this issue 1 year ago • 2 comments

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

image

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

  1. Open a *.tsx file, apply format, <space>f.
  2. Open a second *.tsx file 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

hendridg avatar Oct 03 '24 14:10 hendridg

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 },

VlaDexa avatar Oct 08 '24 02:10 VlaDexa

Actually for fix every time when this bug appear is updating the Languages in :Mason

image
The :ConformInfo logs
image

hendridg avatar Oct 10 '24 14:10 hendridg

Work around provided. Closing.

feoh avatar Oct 30 '24 19:10 feoh