Formatting with Neoformat

I’ve been revamping my neovim setup to switch from coc to the neovim lsp. I found that the neoformat plugin was working better than the lsp formatting for most languages, but it doesn’t support Rescript out of the box. If anyone else is in this situation, the fix is to create the file ~/.config/nvim/autoload/neoformat/formatters/rescript.vim as follows:

function! neoformat#formatters#rescript#enabled() abort
    return ['rescript']
endfunction

function! neoformat#formatters#rescript#rescript() abort
    return {
        \ 'exe': 'rescript',
        \ 'args': ['format', '-stdin', '.res'],
        \ 'stdin': 1,
        \ 'try_node_exe': 1,
        \ }
endfunction
5 Likes

I’m curious what’s the problem with lsp formatting?

I didn’t try it with Rescript; I was having troubles with pyright and typescript, so I switched to neoformat across the board.

1 Like