racket-langserver icon indicating copy to clipboard operation
racket-langserver copied to clipboard

Clashes with parinfer?

Open fosskers opened this issue 3 years ago • 7 comments

Hi there, thanks for a great project.

I've hit a situation where the LSP and what I think is parinfer are getting into fights, and this is confusing the LSP. Every few minutes, the LSP seems to lose track of matched parens, and I get errors like the following that won't go away until I restart the LSP:

lsp

As you can see, there are no actual mismatched parens in the buffer. If I attempt to save the buffer in this state, the code is often reformatted very strangely (as if there had been a missing paren) and I have to manually correct everything, restart the LSP, then continue.

Do you have an idea as to what might be happening here? Thank you kindly. :pray:

fosskers avatar Apr 14 '22 22:04 fosskers

Is parinfer a LSP client? How did it provide buffer to server? It's hard to answer your question without these. And maybe magic-racket would be a nice reference?

dannypsnl avatar Apr 14 '22 23:04 dannypsnl

Is parinfer a LSP client?

It's not, but it does watch the buffer and make automatic corrections based on where parens go. I should have mentioned that I'm using Emacs (so Magic Racket is not available to me), and parinfer is well-used there.

fosskers avatar Apr 14 '22 23:04 fosskers

I think I'm lost now, does the problem come from parinfer cooperating with racket-langserver? If so, then how does it pass the buffer? I don't think racket-langserver works with a partial buffer.

And On Emacs, a choice is racket-mode.

dannypsnl avatar Apr 15 '22 00:04 dannypsnl

Ah let me clarify. I am using racket-mode, which is a "major mode", but Emacs also has "minor modes" which run alongside the majors. parinfer is such a minor mode. Its job is to guarantee that parens always match, and it will automatically rebalance parens when an opening paren is added/deleted.

To my knowledge, parinfer and racket-langserver don't directly interact. I reported the issue here because it's the LSP that's reporting the weird errors and "stalling", but there's a chance it's not solely at fault. It's also the LSP that's doing the strange reformatting based on confusion over parens, and I only notice it doing that immediately after parinfer has added/deleted parens on its own.

Did that clarify the issue?

fosskers avatar Apr 15 '22 16:04 fosskers

A comment from the Doom Emacs maintainer:

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.

fosskers avatar Apr 15 '22 16:04 fosskers

AFAIK, racket-mode doesn’t use LSP (or this library), so are you using both racket-mode and some Emacs LSP client at the same time?

jryans avatar Apr 15 '22 17:04 jryans

Yes. The full answer is that I'm using the racket module in Doom Emacs, which includes lsp-mode. It's this lsp-mode that hooks into racket-langserver when in an .rkt buffer.

fosskers avatar Apr 15 '22 17:04 fosskers