redhat-developer / redhat-developer/vscode-java
CodeAction that modifies code in an unopened file doesn't work with two spaces indentation
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.3k
- Forks
- 546
- Avg merge
- 20h 1m
- Merged PRs (30d)
- 11
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no implementation files or tests. First reproduce the CodeAction on a closed Java file using two-space indentation and no explicit indentation settings; done means newly inserted fields or methods use the file's two-space indentation, matching the expected result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100