lukas-reineke / lsp-format.nvim

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

[Bug] Formatting occasionally changes other buffers #37

Closed akinsho closed 2 years ago

akinsho commented 2 years ago

Occasionally (unfortunately I haven't yet determined the pattern, but it might be related to when a buffer has been formatted and is still in a modified state), the formatting in a specific buffer seems not to run, but actually another open buffer is instead changed and lines from my current buffer are inserted into the other open buffer.

I appreciate this isn't a lot to go off of and tbh I've held off reporting till I noticed a pattern, but I'm stumped and don't really know why this occurs. My lsp format is pretty minimal, I've been using it as default with just the attach method in my general lsp on_attach and noticed this issue still.

I'm happy to try various things if anything comes to mind, I didn't/don't think I'm doing anything particularly unusual and I am wondering if there is a bug in nvim core that because formatting is done asynchronously in this plugin it's being exacerbated

gegoune commented 2 years ago

Apologies for 'me too' comment, but given randomness and inconsistency of that issue I felt like chiming in just to say that @akinsho is not experiencing it in isolation, might be adding some value. I too tried to figure out what's going on and could not find a pattern at all.

lukas-reineke commented 2 years ago

Looking through the code I don't see anything obvious that could cause this. I also haven't been able to reproduce it yet.

Is this happening since this week? I did some pretty big changes. Also, what LSP are you using?

lukas-reineke commented 2 years ago

I found the issue. Sorry about this.

When there were more than one LSP attached, and the first one had an error, the next LSP was getting stuck in the queue. Then got flushed on the next format call, but if that call came from a different buffer, the client attached to buffer A would get called to format buffer B

I released a fix now :rocket:

gegoune commented 2 years ago

@lukas-reineke I am not even sure if that's your plugin, but since yesterday I have noticed that content of my buffers gets duplicated. What I mean is that entire buffer gets copied and pasted at the end of the buffer making

aa
bb
cc

turn into

aa
bb
cc
aa
bb
cc

Do you think your recent changes might have caused it? I am reluctant to open new issue as I don't even know if it your plugin causing it yet.

lukas-reineke commented 2 years ago

please open a new issue and a way to reproduce if possible. At least share your config, what LSP you are using, the contents of the buffer.