redhat-developer / redhat-developer/vscode-java

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

Ouverte
#2,613 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

bug formatter
Langage dominant
TypeScript
Étoiles
2.3k
Forks
546
Merge moyen
20 h 1 min
PR mergées (30 j)
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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

L’issue ne nomme aucun fichier d’implémentation ni aucun test. Commencez par reproduire la CodeAction dans un fichier Java fermé, avec une indentation de deux espaces et sans paramètres d’indentation explicites ; c’est terminé lorsque les champs ou méthodes nouvellement insérés utilisent l’indentation de deux espaces du fichier et correspondent au résultat attendu.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
java
Domaine
devtools
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.