vscode-java icon indicating copy to clipboard operation
vscode-java copied to clipboard

Java Formatter settings are not used

Open Artur- opened this issue 2 years ago • 7 comments

If I open the flow-server project from https://github.com/vaadin/flow/tree/main/flow-server

and have Eclipse formatter settings set to use https://raw.githubusercontent.com/vaadin/flow/main/eclipse/VaadinJavaConventions.xml which defines <setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="4"/> image

then when I open e.g. the HandlerHelperTest.java file, VS Code shows "Spaces: 8" in the bottom bar and formatting the file changes it to use indentation of 8 spaces instead of 4

The settings file should be fine because when I go back to command line and run mvn formatter:format in the project, the indentation is changed back to 4 spaces.

Environment
  • Operating System: macOs Ventura
  • JDK version: 17
  • Visual Studio Code version: 1.76.2
  • Java extension version: 1.16.0
Steps To Reproduce
  1. See above
Current Result

File is not formatted according to given settings

Expected Result

File is formatted according to given settings

Artur- avatar Mar 23 '23 15:03 Artur-

are you using editorconfig in your project?

CsCherrYY avatar Mar 24 '23 00:03 CsCherrYY

No .editorconfig file as far as I can see

Artur- avatar Mar 24 '23 07:03 Artur-

If I select "Ident Using Spaces", I see this image

Why would the "current" tab size differ from the default?

Some files in the project show "Spaces: 8" and other files seem to use the default and show "Spaces: 4"

Artur- avatar Apr 01 '23 07:04 Artur-

Why would the "current" tab size differ from the default?

The default tab size should be configured via VS Code setting editor.tabSize. As for the current tab size, you can check VS Code setting editor.detectIndentation, if it's set, VS Code will auto detect the indentation of your current file and show it.

CsCherrYY avatar Apr 03 '23 02:04 CsCherrYY

Thanks! Now it works as expected when I turned of editor.detectIndentation.

But does it not kind of defeat the purpose of having formatter settings defined, if they are not used by default for incorrectly formatted files?

Artur- avatar Apr 03 '23 05:04 Artur-

Agree. Currently as for indentation settings, vscode-java will pick VS Code ones rather than the specific settings in profile. That would be not suitable since most users want to specific indentation settings within a project via a profile, we should fix it.

CsCherrYY avatar Apr 03 '23 05:04 CsCherrYY

any update?

slowhigh avatar May 30 '25 06:05 slowhigh