vscode-java
vscode-java copied to clipboard
CodeAction that modifies code in an unopened file doesn't work with two spaces indentation
When I apply a CodeAction that modifies code in a file that isn't currently opened in VS Code, such as "create missing field asdf in Foo", and the file being modified is formatted to use two spaces as indentation, then the newly added content is not formatted correctly.
In order for this to happen, I don't specify any indentation settings in settings.json, and I don't add a .settings/org.eclipse.jdt.core.prefs.
Environment
- Operating System: RHEL 8
- JDK version:
- Visual Studio Code version: 1.69.2, 3b889b090b5ad5793f524b5d1d39fda662b96a2a, x64
- Java extension version: v1.10.2022080304
Steps To Reproduce
- Make a class FooA:
public class FooA {
private String prefix;
public FooA(String prefix) {
this.prefix = prefix;
}
public String getPrefix() {
return this.prefix;
}
}
- Close
FooA - Make a class FooB:
public class FooB {
private FooA fooA;
public FooB(FooA fooA) {
this.fooA = fooA;
}
public String getParameter() {
return this.fooA.parameter;
}
}
- Activate the "Create field 'parameter' in type 'FooA'" CodeAction
Current Result
FooA becomes:
public class FooA {
private String prefix;
public String parameter;
public FooA(String prefix) {
this.prefix = prefix;
}
public String getPrefix() {
return this.prefix;
}
}
Expected Result
FooA becomes:
public class FooA {
private String prefix;
public String parameter;
public FooA(String prefix) {
this.prefix = prefix;
}
public String getPrefix() {
return this.prefix;
}
}
Additional Informations
- You can reproduce this bug using other CodeActions, like the "Create method" one
- If indentation settings are set in a
settings.jsonor.settings/org.eclipse.jdt.core.prefs, the newly added content respects those settings as expected