redhat-developer / redhat-developer/vscode-java

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

未关闭
#2,613 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug formatter
主要语言
TypeScript
星标
2.3k
派生
546
平均合并
20 小时 1 分钟
30 天内合并 PR
11

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

该 issue 未指定任何实现文件或测试。首先,在一个使用两个空格缩进且未设置显式缩进选项的已关闭 Java 文件上复现 CodeAction;当新插入的字段或方法使用该文件的两个空格缩进,并与预期结果一致时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
java
领域
devtools
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。