`textDocument/formatting` not reported correctly in Emacs
Hi all,
In Emacs, I have to tell my LSP client (Eglot) to adjust some of the capabilities that solargraph reports (for reference, but I appreicate most here probably won't be familiar with Emacs).
In question here is textDocument/formatting's ability to dynamically register and to enable documentFormattingProvider, which the server does indeed support but claims that it does not.
I have since stopped using solargraph in favour of Ruby LSP, but I'm reporting this upstream to hopefully get a resolution :D
Hi,
It looks like Solargraph does not include documentFormattingProvider in capabilties unless the formatting option is enabled. This option is disabled by default and can be enabled via passing { ..., "formatting": true } in initializationOptions (see initializeParams).
@castwide is there a reason why we shouldn't enable the formatting option by default, and/or why documentFormattingProvider capability should be returned conditionally?
So there are three possible solutions to this issue that I can see:
- The client needs to enable formatting via
initializationOptions(current behaviour) - We enable the
formattingoption by default - We always return the
documentFormattingProvider: trueregardless offormattingoption.
That makes sense, however I was passing it in (reference) and verified the config was being passed in during init.
Looking at the file you list, it looks like it's commented out (unless it's sent another way of course), so I suspect that's the issue.
My loose understanding (as someone that hasn't written an LSP server but operates in the space of LSP clients a fair amount) documentFormattingProvider should indeed always be true as it determines if the server supports the capability rather than if it's enabled or not. When doing the actual formatting, it could check the option there maybe. There's also dynamic registration potentially.
@elken I think you're right. The fact that documentFormattingProvider is stubbed in the capability options appears to be an artifact from a version of LSP before it supported dynamic capability registration. I'll fix it for the next release.