lukas-reineke / lsp-format.nvim

A wrapper around Neovims native LSP formatting.
559 stars 27 forks source link

Fix a racing condition #71 #72

Closed zhou13 closed 1 year ago

zhou13 commented 1 year ago

There is a racing condition (#71) when I

  1. make some changes to the buffer
  2. save the file and trigger the format
  3. make some edits again
  4. save the file again
  5. If the format process from 2 finished after 4, the buffer will be updated with the result from 2, overriding my edit from 3.

This PR fixed the racing condition in #71 by checking to not run two formaters at the same time.

lukas-reineke commented 1 year ago

Thanks, and sorry I took so long to look at this, I had some time off.

I'm not sure if this is the best way to fix the problem. request returns a request id that can be used to cancel the in flight request. So if a user saves the file again while the first request is not done yet, the plugin should cancel the first request. And the plugin can also keep track of the last request id to only allow results from that one.

zhou13 commented 1 year ago

Thank you for the feedback. Keeping track of requests would be a more efficient way to implement this. However, I have been using my branch with some slow formaters for a while and am quite satisfied. I probably won't have enough momentum to make another implementation in the near future.

lukas-reineke commented 1 year ago

:+1: all good. I'll have a go at this when I have some time