redhat-developer / redhat-developer/vscode-java
Improve quick fix
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 2.3k
- Forks
- 546
- Ø Merge
- 20 Std. 1 Min.
- Gemergte PRs (30 T.)
- 11
Beschreibung
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:

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:

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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie damit, die quick-fix- und auto-completion-Einstiegspunkte der Erweiterung für Java-Imports nachzuverfolgen, und prüfen Sie anschließend die vorgeschlagene settings.json-Konfiguration für Vorschläge zu irreführenden Imports. Vergleichen Sie das bestehende Verhalten mit den Beispielen im Issue. Als erledigt sollte gelten, dass auswählbare Ersetzungsvorschläge, eine konflikt sichere Qualifizierung anderer Vorkommen und optionale bevorzugte Ersetzungen enthalten sind.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java, typescript, vscode
- Bereich
- developer-experience, tooling
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 30/100