vim-prettier icon indicating copy to clipboard operation
vim-prettier copied to clipboard

Autoformat on save not working for .ts and .tsx files.

Open solidiquis opened this issue 4 years ago • 6 comments

First of all, I really appreciate all the hard-work that went into this amazing plugin, as it has made my life at work tremendously easier.

Issue: Autosave works just fine on .js files, but not .ts and .tsx files.

Here are some of my configurations from my .vimrc:

call plug#begin('~/.vim/plugged')

    " TypeScript
    Plug 'leafgarland/typescript-vim'

    " CoffeeScript
    Plug 'kchmck/vim-coffee-script'
    
    " JavaScript
    Plug 'pangloss/vim-javascript'
    Plug 'maxmellon/vim-jsx-pretty'

    " Prettifier
    Plug 'prettier/vim-prettier', {
      \ 'do': 'yarn install',
      \ 'for': ['javascript', 'typescript'] }
call plug#end()


" vim-prettier
let g:prettier#autoformat = 1
let g:prettier#autoformat_require_pragma = 0

Manually calling the command :Prettier works just fine, but unfortunately I can't get that to run automatically on save. Any ideas?

solidiquis avatar Jan 24 '21 00:01 solidiquis

For anyone else experiencing this issue, here is my hacky fix: autocmd BufWritePre *.tsx,*.ts Prettier

solidiquis avatar Jan 24 '21 00:01 solidiquis

 Plug 'prettier/vim-prettier', {
      \ 'do': 'yarn install',
      \ 'for': ['javascript', 'typescript', 'typescriptreact', 'javascriptreact'] }

I think you also need to include typescriptreact and javascriptreact in your plug begin. You might need to reinstall vim-prettier to install these missing plugins

yzia2000 avatar Feb 01 '21 06:02 yzia2000

I confirm that adding javascriptreact and typescriptreact solved the problem for me.

Was this changed recently? Because I never had those before and .tsx always worked fine for me.

Maybe this should be mentioned in the documentation; I was pulling my hair out trying to figure out why it stopped working.

pdfrod avatar Mar 04 '21 15:03 pdfrod

I confirm that adding javascriptreact and typescriptreact solved the problem for me.

Was this changed recently? Because I never had those before and .tsx always worked fine for me.

Maybe this should be mentioned in the documentation; I was pulling my hair out trying to figure out why it stopped working.

Worked like a charm. Thank you!

bwilytsch avatar Jan 31 '22 09:01 bwilytsch

Maybe we can close this issue then?

yzia2000 avatar Feb 02 '22 08:02 yzia2000

The VSCode integration repo has a helpful list of supported languages. Can we add something similar to vim-prettier's documentation? As it is, it's not obvious at all how to make it work for .jsx / .tsx files.

pdfrod avatar Feb 03 '22 22:02 pdfrod