redhat-developer / redhat-developer/vscode-java

Improve quick fix

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

Personne n'a encore pris cette issue.

code action enhancement
Langage dominant
TypeScript
Étoiles
2.3k
Forks
546
Merge moyen
20 h 1 min
PR mergées (30 j)
11

Description

Hi! I would like to suggest a new feature to improve the extension.

When programming in Java is a very common mistake to import the wrong class for some basic types. For example, importing java.awt.List instead of java.util.List.

In such cases, you don't have a quick fix action to solve the problem. Check the image below:

Captura de tela de 2021-02-27 14-46-28(1)

To fix this, one solution is to trigger the auto completion and choose the right type. But then, the extension will include the whole class name to avoid conflicts, because it probably assumes that you may have other classes with the same name in use on the code. Check the image below:

Captura de tela de 2021-02-27 14-52-28

So, my suggestion is to include a quick fix (and an auto completion) named "Replace by ..." where the user can choose to replace the import with another option easily. So, if I have the following code:

import java.awt.List;

private List doSomethingWithJavaAwtList(){
    // Do domething
}
private List<String> toList(String src){
    return Arrays.asList(src.split(","));
}

Then, I can position the cursor on top of List<String>, invoke the quick fix and it will present me the following options:

  • Replace misleading import by java.util.List
  • Replace misleading import by com.vendor.library.List

Selecting an option imports the right class and (if necessary) replaces other occurrences with the full qualified name. So, for the previous example, it would become:

import java.awt.List;
import java.util.List;

private java.awt.List doSomethingWithJavaAwtList(){
    // Do domething
}
private List<String> toList(String src){
    return Arrays.asList(src.split(","));
}

The suggestions given by the extension could be provided automatically based on the class name and/or provided by the user in "settings.json", globally or per project/workspace. For example:

{
    "java.configurations.misleading-imports.suggestions": {
         "List": [
              "java.util.List"
         ],
         "Connection" : [
              "java.sql.Connection"
         ]
    }
}

Also, it would be interesting to provide a feature allowing the user to quickly set a class as the preferred suggestion on the configurations. Something like this:

  • Replace misleading import by java.util.List and set as preferred replacement for this type

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

Commencez par suivre les points d’entrée quick-fix et auto-completion de l’extension pour les imports Java, puis examinez la configuration settings.json proposée pour les suggestions d’imports trompeurs. Comparez le comportement existant avec les exemples de l’issue. La réalisation doit inclure des suggestions de remplacement sélectionnables, la qualification des autres occurrences sans conflit et des remplacements préférés facultatifs.

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

Évaluation

Stack technique
java, typescript, vscode
Domaine
developer-experience, tooling
Type d'issue
Fonctionnalité
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
30/100

Recevez les nouvelles issues par e-mail

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