SaltedPiano · 2022-11-30 17:10
Hello, I'm new to using eglot + flymake. Before I used out of the box solutions like spacemacs, but I've been trying to learn more.
My problem is that it seems like the buffer eglot is using to error check my code is out of sync from the buffer I'm editing in. See the attached image for details. I'm not really sure what to do or what may be causing this. This also may be a flymake problem, but I'm not sure on how eglot+flymake play together. Any help would be appreciated.
​
[If I edit the variable name say to \\"dsavedStyles\\", then flymake reports \\"Use of undeclared identifier 'dsavedStylesalw';\\" which is still wrong, but strange](https://preview.redd.it/bzqzjfuqe43a1.png?width=1045&format=png&auto=webp&s=6fbd8b53f2a392c0ed73994319050d90d167eb84)
orzechod · 2022-11-30 17:33
for what it's worth, I noticed this too when I switched to eglot from lsp-mode a few days ago. I don't know the root cause but I've found that running `M-x eglot-reconnect` seems to reset the flymake overlay for me.
I'm on emacs 28.1 and using eglot via straight.el .
SaltedPiano · 2022-11-30 17:35
I'm using the same emacs version and straight.el. Maybe that's just a coincidence though... I also find that eglot-reconnect fixes it. That's not awful, but slightly painful.
yapfff · 2022-11-30 18:09
I also had this issue in the past, a few times per hour roughly at worst. For me it started happening (or it became more noticeable) after I moved from company to corfu for the completion UI, and I had the issue after some completion suggestion / feedback (even if I didn't select anything). I don't think it's a completion issue as the Emacs buffer was always fine, and it's the LSP server that got out of sync. As a result, as for you flymake started reporting nonsensical errors.
In my case it seems there is a time dependent behavior, and a relation to the Emacs completion system. But I never could find a way to properly reproduce the issue. I tried to look into it but it's above my Emacs-fu.
It's became very rare now after some configuration changes, so as suggested I do an eglot reconnect when it happens.
Out of curiosity, because the completion system (or its timing) seemed to have an effect in my case: is there a connection for you? What do you use as the completion UI / settings?
SaltedPiano · 2022-11-30 18:17
I'm using corfu as well! I'm not messing with timings at all though. Everything there should be the default settings.
I've noticed if the "buffer" that eglot/lsp-server is using (I'm not sure who is messing up here) gets out of sync not just flymake messes up, but so does completions. Again you are right that eglot-reconnect fixes it.
I'm beginning to wonder how eglot goes from my editing buffer to the lsp server and back. Maybe learning a bit about that might shine some light onto the issue.
yapfff · 2022-11-30 20:08
When using eglot most if not all of the completions comes from the LSP server. So if it gets out of sync then it's understandable the proposed completions are also impacted.
When I say "most if not all", it's actually all unless you tweaked your completion settings to add other sources. If you didn't change anything all the completions will be from the LSP server IIRC.
In my case I had the issue when using a simple corfu set-up, with eglot/LSP only as the source of completion candidates, which is very light. When adding other completion sources (dabbrev, yasnippet from company through cape), so adding work, then the issue almost disappeared for me. When I want back to company for a check, the user experience was much slower than with corfu, but no issue there too. Which is why I believe there is a connection to completion and timing. But it's just a guess...
I looked into the eglot code handling the forwarding of the buffer changes to the LSP server, but it's quite complex. There's some complex logic to accumulate and forward changes, but I don't know enough abour elisp and Emacs internals to deal with it. And I couldn't find a way to reproduce the issue in a deterministic way. As the issue almost disappeared for me, I let this slide to be honest. But yes, there's something not quite right somewhere for sure.
pr09eek · 2022-11-30 22:13
I've also had this issue for a while. I would suggest raising an issue in the GitHub repo of eglot. I'm also using the same combination of packages. For me, when reconnecting with the server it gives me 2 options - reconnect to the same server or restart the server. The error only disappears when I restart it or when I reload the buffer.
For me I feel like the frequency is a bit higher to let it slide. Sometimes I feel that it happens to me after every 4-5 lines of code.
yapfff · 2022-12-01 08:28
Good idea. I never did as eglot author insists on getting a clear way to reproduce the issue, and I failed here. The same actions may or may not trigger the issue. Which is why I believe something is timing related, but TBC.
Anyway, eglot author suggest opening a discussion for issue without a way to clearly reproduce, which I did:
https://github.com/joaotavora/eglot/discussions/1127
Could people having the issue go there and add some feedback? Add details if you can, or a "me too" to assess how common the issue is.
Thanks
SaltedPiano · 2022-12-01 14:22
Thanks for taking the time to put together this discussion! I'll see if I can come up with any way to reproduce it reliably and contribute it there!