redhat-developer / redhat-developer/vscode-java
Improve quick fix
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- TypeScript
- Star
- 2.3k
- Fork
- 546
- Merge trung bình
- 20 giờ 1 phút
- Pull request đã merge (30 ngày)
- 11
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách truy vết các điểm vào quick-fix và auto-completion của extension dành cho các import Java, sau đó xem lại cấu hình settings.json được đề xuất cho các gợi ý về import gây hiểu nhầm. So sánh hành vi hiện có với các ví dụ trong issue. Phần hoàn thành cần bao gồm các gợi ý thay thế có thể chọn, việc định danh đầy đủ các lần xuất hiện khác theo cách an toàn trước xung đột và các thay thế ưu tiên tùy chọn.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- java, typescript, vscode
- Lĩnh vực
- developer-experience, tooling
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 30/100