solargraph icon indicating copy to clipboard operation
solargraph copied to clipboard

`textDocument/formatting` not reported correctly in Emacs

Open elken opened this issue 7 months ago • 3 comments

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

elken avatar May 23 '25 10:05 elken

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:

  1. The client needs to enable formatting via initializationOptions (current behaviour)
  2. We enable the formatting option by default
  3. We always return the documentFormattingProvider: true regardless of formatting option.

lekemula avatar May 24 '25 21:05 lekemula

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 avatar May 25 '25 04:05 elken

@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.

castwide avatar May 26 '25 23:05 castwide