LSP code actions introduce a ^M on windows (tsserver)

Hello,

Code actions using tsserver on windows introduce ^M (carriage return) at the end line. I know this is due to how unix and dos file formats handle new lines differently.
image

I have tried changing fileformat in vim between unix and dos, but I was not able to fix it.

Can anyone point me in the right direction, I’m probably being really dumb or missing something obvious.

I have not tested other lsp servers, it’s possible this could be related to tsserver.

Thanks in advance.

1 Like

I’m getting this same issue… did you ever find a fix?

I started to wrap my format function with this
in my lsp config section
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'g<space>', '<cmd>call RunLSPFormatter()<cr>', opts)

The wrapper

function! RunLSPFormatter()
    " Format file if its not markdown
    if &ft != 'markdown'
        lua vim.lsp.buf.formatting_seq_sync()
    endif

    " Remove ^M
    execute "%s/\r//ge"

    " Save file if it changed
    silent! up!
endfunction