Subject: Re: bug#66726: 29.1; Eglot jdtls formatter ignored

From: João Távora <[email-masked]>
Date: Mon, 8 Jan 2024 11:37:57 +0000

On Sun, Jan 7, 2024 at 9:40 AM Cay Horstmann <[email-masked]> wrote:

> I was asked to reference the discussion on https://github.com/joaotavora/eglot/discussions/1222#discussioncomment-7683229

Yes, thank you for doing so.

> I reported that
>
> (remove-hook 'eglot-connect-hook 'eglot-signal-didChangeConfiguration)
>
> makes the formatter work. João Távora commented that this prevents Eglot from atomatically sending project-specific configuration to *any* server.
>
> I am unsure what the effects of that would be, but I gather from João's comment that it is not an acceptable solution.

It might not be acceptable for all users, yes.  It may be acceptable for you.

Here's a summary of this issue as I understand it:

1. jdtls's support for custom formatters can be achieved by passing suitable
   LSP :initializationOptions

2. According to you, jtdls's support for custom formatters _cannot_
   be achieved with LSP workspaceConfiguration.  It _has_ to use 1.

3. In jdtls, a blank LSP workspaceConfiguration request overwrites any
   settings passed in LSP initializationOptions.  This was confirmed
   by more than one user, I think.

2 and 3 dictate that, barring any changes on the jdtls side, the only
way to use custom formatters in Eglot is for Eglot to not send
LSP workspaceConfiguration to this server at all.  Has jdtls been made
aware of this conflict between 2 and 3?

You may also want to try the less intrusive:

(add-hook 'java-mode-hook (lambda ()
   (remove-hook 'eglot-connect-hook 'eglot-signal-didChangeConfiguration t))

To do it just for java-mode.  If you're using java-ts-mode, you need a similar
incantation, unless some java-base-mode exists (it exists for some Emacs
modes, not sure if Java)

João