redhat-developer / redhat-developer/vscode-java
Improve quick fix
还没有人认领这个 Issue。
- 主要语言
- TypeScript
- 星标
- 2.3k
- 派生
- 546
- 平均合并
- 20 小时 1 分钟
- 30 天内合并 PR
- 11
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先跟踪扩展针对 Java imports 的 quick-fix 和 auto-completion 入口点,然后检查针对误导性 import 建议的 settings.json 配置提案。将现有行为与 issue 中的示例进行比较。完成内容应包括可选择的替换建议、以避免冲突的方式限定其他出现位置,以及可选的首选替换。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java, typescript, vscode
- 领域
- developer-experience, tooling
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 30/100