redhat-developer / vscode-java

Java Language Support for Visual Studio Code
Eclipse Public License 2.0
2.07k stars 429 forks source link

Java formatter ignores org.eclipse.jdt.core.formatter.tabulation.size and uses editor's 'tab size' when calculating line split #3513

Open theswordsmahin opened 6 months ago

theswordsmahin commented 6 months ago

Java formatter ignores org.eclipse.jdt.core.formatter.tabulation.size and uses editor's 'tab size' when calculating how lines should be split. This makes it difficult for users to use their preferred indentation size without throwing off source control history diffs.

Environment
Steps To Reproduce

Relevant settings:

If I have a line that is 121 characters, the formatter will wrap appropriately. However, if someone else has their tab size:2, the total line length is calculated to be less than 120, and thus will unwrap the lines wich throws off the file history diffs.

Current Result

Line split is calculated based on VS Code's tab size setting, instead of the formatter's tabulation.size

Expected Result

Line split should be calculated based on the tabulation.size setting, to allow users to have their preferred tab size within VS Code

rgrunber commented 6 months ago

I think similar issues have been filed in the past. I explained the situation in https://github.com/eclipse-jdtls/eclipse.jdt.ls/issues/2942#issuecomment-1794029285 . Basically the language server has to choose between the JDT setting and the VS Code setting. Since the protocol implies the client is responsible for the setting, the language server let's the client's setting take priority. Current workaround is https://github.com/redhat-developer/vscode-java/issues/672#issuecomment-431623541 .

Also a similar issue filed in https://github.com/redhat-developer/vscode-java/issues/672 .

I think we could just introduce a setting to determine whether the client setting should override the formatter, where they clash.

theswordsmahin commented 6 months ago

My apologies, I did attempt to see if there was already a pre-existing issue but missed those.

I think we could just introduce a setting to determine whether the client setting should override the formatter, where they clash.

That would be awesome for sure, in the meantime can set the workspace settings to hard-code the tab size for everyone, as indicated in the referenced comment. Thanks for taking the time!

snjeza commented 6 months ago

@theswordsmahin You can try to set the java.format.tabSize property.

theswordsmahin commented 6 months ago

The settings editor shows that as an unknown configuration setting for me, tried it anyways but it didn't seem to work.

Did you mean

    "[java]":{
        "editor.insertSpaces": true,
        "editor.detectIndentation": false,
        "editor.tabSize": 4,
    },

Or is there another place that option takes effect?

snjeza commented 6 months ago

Did you mean

You are right. Sorry.