redhat-developer / redhat-developer/vscode-java
Improve quick fix
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.3k
- Forks
- 546
- Avg merge
- 20h 1m
- Merged PRs (30d)
- 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:

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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the extension's quick-fix and auto-completion entry points for Java imports, then review the proposed settings.json configuration for misleading-import suggestions. Compare the existing behavior with the examples in the issue. Done should include selectable replacement suggestions, conflict-safe qualification of other occurrences, and optional preferred replacements.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, typescript, vscode
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100