Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org.eclipse.jdt.core.formatter.tabulation.* settings are ignored #2942

Open
rybesh opened this issue Nov 2, 2023 · 4 comments
Open

org.eclipse.jdt.core.formatter.tabulation.* settings are ignored #2942

rybesh opened this issue Nov 2, 2023 · 4 comments

Comments

@rybesh
Copy link

rybesh commented Nov 2, 2023

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.

@rgrunber
Copy link
Contributor

rgrunber commented Nov 3, 2023

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.

@rybesh
Copy link
Author

rybesh commented Nov 3, 2023

That doesn’t seem to have any effect either.

@rgrunber
Copy link
Contributor

rgrunber commented Nov 6, 2023

I think I found the problem. Similar to emacs-lsp/lsp-java#318 (comment) .

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.

Integer tabSize = options.getTabSize();
if (tabSize != null) {
int tSize = tabSize.intValue();
if (tSize > 0) {
eclipseOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, Integer.toString(tSize));
}
}
boolean insertSpaces = options.isInsertSpaces();
eclipseOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, insertSpaces ? JavaCore.SPACE : JavaCore.TAB);
return eclipseOptions;

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 ?

@rybesh
Copy link
Author

rybesh commented Nov 15, 2023

Unfortunately communication between eglot and jdtls is somewhat shrouded in mystery:

joaotavora/eglot#1222

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants