Vscode-java: Code fixes force tabs for indentation

Created on 10 Jun 2018  路  6Comments  路  Source: redhat-developer/vscode-java

When using a java code fixes, the extension forces tabs into a 4-Space indentation workspace

Environment
  • Operating System: Windows 10 1803 (RS5) Insider Preview
  • JDK version: 1.8.172
  • Visual Studio Code version: 0.25.0-insider
  • Java extension version: 0.26.0
Steps To Reproduce
  1. Set workspace to space indentation
  2. let the extension implement an interface
Current Result

Injects tabs

Expected Result

adheres to user->workspace-settings

bug content-assist formatter prioritP2

Most helpful comment

Ok so that's interesting. Code snippets (like ctor) are indented with tabs, but vscode fixes the indentation on-the-fly, according to its preferences.
However CompletionItems are indented according to the project's .settings/org.eclipse.jdt.core.prefs, so implementing an interface's methods would have the server use the eclipse indentation settings, but vscode doesn't correct it when applying the changes, contrary to snippets. @aeschli is this intentional?

Anyways, @MeikTranel, one way to mitigate the problem is to add this to your project's .settings/org.eclipse.jdt.core.prefs:

org.eclipse.jdt.core.formatter.tabulation.char=space
org.eclipse.jdt.core.formatter.tabulation.size=4

All 6 comments

Ok so that's interesting. Code snippets (like ctor) are indented with tabs, but vscode fixes the indentation on-the-fly, according to its preferences.
However CompletionItems are indented according to the project's .settings/org.eclipse.jdt.core.prefs, so implementing an interface's methods would have the server use the eclipse indentation settings, but vscode doesn't correct it when applying the changes, contrary to snippets. @aeschli is this intentional?

Anyways, @MeikTranel, one way to mitigate the problem is to add this to your project's .settings/org.eclipse.jdt.core.prefs:

org.eclipse.jdt.core.formatter.tabulation.char=space
org.eclipse.jdt.core.formatter.tabulation.size=4

@fbricon What you said is exactly what sparked my confusion with the title.
First i thought it was regular code snippets but then i found out it was actually only the fixes rioting.

Aren't code fixes a language server thing?

I logged an issue for vscode on this issue.

On the language side, @fbricon Which setting should be honor? If we honer eclipse setting, there is nothing left to do.

Fixed with #617, thanks to @jdneo. Nice work!

This issue persists when the fix is triggered in a different file from where the fix is applied.

For example when in a class Foo I try to call a non-existing method on an object of class Bar, and trigger the fix to implement the new method in Bar, the new method uses tabs for indentation, whereas my setting prescribes spaces. (With the same settings, it _does_ correctly indent with spaces for implementing interfaces in the same file, as in @MeikTranel's example.)

I hope I made myself clear, and would happily elaborate if anything was unclear.

Cheers!

Was this page helpful?
0 / 5 - 0 ratings