neoclide/coc-prettier

Quick :w reverts last change when used with `pretter-eslint`

pjg opened this issue · 10 comments

pjg commented

I make a change and quickly hit the combination for :w. What happens is that my change is reverted and shortly after pretter runs and "Formatted by prettier" message is being displayed.

It's hard to diagnose as it might be the result of my config/plugins/etc. but I was unable to trace it. I only know this happens after I tried switching to prettier-eslint.

When showing command debug for prettier I can see the newText is incorrect, with the reverted change.

I ran into the same issue, not sure if this is just a COC issue or this is a COC issue that's only surfaced for coc-prettier - but I was able to git bisect and it looks like this started happening with this commit: neoclide/coc.nvim@9c54590.

Here's a minimal vimrc I was able to reproduce this with (along with having coc-prettier installed and coc.preferences.formatOnSaveFiletypes set for the filetype I'm using):

call plug#begin()
Plug 'neoclide/coc.nvim', {'commit': '9c54590c', 'do': 'yarn install --frozen-lockfile'}
call plug#end()

noremap <silent> <C-s> <Esc>:write<CR>
noremap! <silent> <C-s> <Esc>:write<CR>

And here's what the issue looks like for me when using this vimrc, where you can see me delete a line and then it be re-added when Prettier runs. I'm hitting dd<C-s> several times rapidly to cause this; it seems like this only occurs when an edit and then a write occur in very quick succession.

coc_bug.mp4

I was able to work around this though by just pinning COC to the parent commit of the commit that introduced the issue, like this: bobwhitelock/dotfiles@44a749b

Any ideas @chemzqm?

I'm seeing the same issue. It was hard to diagnose because the delay needed to ensure a good save is pretty short. I thought that it might be some sort of plugin conflict or the result of my becoming more comfortable in vim (and therefore typing faster).

It has become enough of a problem that I finally decided to diagnose with a minimal install and .vimrc.

If I type dd and then sdf in quick succession, the line is deleted, but then it reappears as soon as prettier runs. If I run those two commands with ~500ms between them, they work as expected.

Similarly, if I type u and sdf in quick succession, the undo executes, but is then reverted when prettier runs.

~/.vimrc:

call plug#begin('~/.vim/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()

inoremap df <ESC>
noremap sdf <ESC>:w<CR>
inoremap sdf <ESC>:w<CR>

~/.vim/coc-settings.json:

{
  "coc.preferences.formatOnSaveFiletypes": ["scss"],
}

I can confirm the problem. Steps to reproduce for me:

  • Have prettier configured to run on file save
  • In a .tsx file, insert multiple new lines by keeping the enter key pressed
  • Go back to command mode with <ESC> then immediately type :w

File gets messed up.

It happens frequently enough that I cannot use the plugin because of it. :(

Might be fixed by neoclide/coc.nvim@4a1cc23, try latest coc.nvim

Looks like this is fixed the issue for me, thanks @chemzqm!

Open another issue with :CocInfo if you still experience this bug.

Seems to work for me as well, thx @chemzqm!

pjg commented

This is now fixed. Thank you @chemzqm!

Fixed for me too, thanks @chemzqm!

Fixed it for me too! Thanks