justinbarclay / parinfer-rust-mode

Simplifying how you write Lisp
https://shaunlebron.github.io/parinfer/
GNU General Public License v3.0
234 stars 17 forks source link

Clashes with `lsp-mode` and/or `racket-langserver`? #59

Open fosskers opened 2 years ago

fosskers commented 2 years ago

Hi there, thanks for this great project; it makes writing Lisps a lot more pleasureful.

I've hit a situation where some or all of racket-mode, lsp-mode, parinfer-rust-mode, and the underlying Racket LSP racket-langserver seem to be fighting. Here's the sister issue to this that I opened with the LSP.

Basically, I've noticed that sometimes following a paren change made by parinfer, the LSP thinks I have unbalanced parens. Upon save (and thus auto-reformat) the code gets reformatted by the LSP quite strangely, as if a paren had indeed been missing. The LSP then won't go back to normal operation until I restart it completely. Since this happens every few minutes, it's making the dev experience a bit jarring :laughing:

Theorizing elsewhere, peers have pointed out:

Just a hunch, but it sounds like parinfer is modifying the buffer without triggering the modification hooks lsp-mode uses to report buffer changes to the server, so the server is operating on a stale buffer. I recall that being an issue with some other editing package, but can't remember which. aggressive-indent, maybe?

and

It's not unusual to do: (let ((inhibit-modification-hooks t)) ...do the thing...) To prevent clobbering hooks or infinite recursion, but rarely are they triggered afterwards, which would resolve this issue. Using combine-change-calls or combine-after-change-calls would get around that.

Does any of this sound familiar? Thank you kindly.

justinbarclay commented 2 years ago

Hi @fosskers, I disable inhibit-modification-hooks specifically for the reason to avoid clobbering hooks or causing infinite recursion. Though, I am not sure if my use case is entirely valid.

Unfortunately my next 3 weeks are kind of full and I don't have much time to look into this. However, if you want to, you could look at https://github.com/justinbarclay/parinfer-rust-mode/blob/main/parinfer-rust-mode.el#L404 and either completely remove that line. Or wrap L404-427 in a combine-after-change-calls. If you do either of those and they work for you, I'm happy to look at a PR when I have free time again :)