prettier / vim-prettier

A Vim plugin for Prettier

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

solidiquis opened this issue · 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?

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

 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

commented

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.

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!

Maybe we can close this issue then?

commented

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.