redhat-developer / redhat-developer/vscode-java

CodeAction that modifies code in an unopened file doesn't work with two spaces indentation

Open
#2,613 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug formatter
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
  1. Make a class FooA:
public class FooA {
  private String prefix;

  public FooA(String prefix) {
    this.prefix = prefix;
  }

  public String getPrefix() {
    return this.prefix;
  }
}
  1. Close FooA
  2. Make a class FooB:
public class FooB {
  private FooA fooA;

  public FooB(FooA fooA) {
    this.fooA = fooA;
  }

  public String getParameter() {
    return this.fooA.parameter;
  }
}
  1. 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.json or .settings/org.eclipse.jdt.core.prefs, the newly added content respects those settings as expected

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.