eclipse.jdt.ls
eclipse.jdt.ls copied to clipboard
org.eclipse.jdt.core.formatter.tabulation.* settings are ignored
I am using jdtls
with eglot in Emacs.
I have the following lines in .settings/org.eclipse.buildship.core.prefs
:
org.eclipse.jdt.core.formatter.tabulation.char=SPACE
org.eclipse.jdt.core.formatter.tabulation.size=2
But eglot-format
results in a formatted buffer with 8-space indentation, whether or not those lines are there.
I haven't tried this out yet, but I would think you need to place those JDT settings into .settings/org.eclipse.jdt.core.prefs
.
That doesn’t seem to have any effect either.
I think I found the problem. Similar to https://github.com/emacs-lsp/lsp-java/issues/318#issuecomment-783953847 .
The textDocument/formatting
& textDocument/rangeFormatting
requests take as a parameter (aside from the document itself & the range to apply) FormattingOptions
. In particular this includes :
/**
* Size of a tab in spaces.
*/
tabSize: uinteger;
/**
* Prefer spaces over tabs.
*/
insertSpaces: boolean;
So the spec expects that the client should send options for whether to use tabs/spaces and the number of spaces for a tab.
The language server then overrides tabulation.char
& tabulation.size
in the format call (because those are the options controlling that), so what you set is being ignored. I confirmed this by adding another option like org.eclipse.jdt.core.formatter.lineSplit=50
, which was respected. I just had to place a .settings/org.eclipse.jdt.core.prefs
where .settings/
was a sibling to the src
folder.
https://github.com/eclipse-jdtls/eclipse.jdt.ls/blob/395b5da0cc588844d8b43464bc6bb001aa4ff23b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/FormatterHandler.java#L154-L163
Do you know what values eglot is sending to JDT-LS ? Is there a way made available to users to set this on the emacs side ?
Unfortunately communication between eglot and jdtls is somewhat shrouded in mystery:
https://github.com/joaotavora/eglot/discussions/1222