-
Notifications
You must be signed in to change notification settings - Fork 441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Organize imports removes valid imports in Java files with compile errors #2294
Comments
good issue |
If this is the same bug as eclipse-jdtls/eclipse.jdt.ls#1203 , it was fixed about 2 weeks ago upstream, so we should be able to just copy over the changes into our own corresponding QuickAssistProcessor class in JDT-LS. |
The above bug has been fixed in eclipse-jdtls/eclipse.jdt.ls#2003. You can also see the upstream fix at https://bugs.eclipse.org/bugs/show_bug.cgi?id=542653 . Marking this as closed as this should be part of our next release. |
@rgrunber has this really been fixed? My 1.8.0 vscode-java still removes all imports if a file as a syntax error. |
You're right. I'm still able to reproduce. I haven't investigated, but I would guess some kind of reference check is done against the static import, and if a syntax error happens in such a way as to make the AST unrecoverable, the reference is not discovered, and the import gets flagged for removal. The modification of |
Yup same issue, organise imports removes static imports from files and won't add them back again |
I don't think the fix for #2861 fixes this issue. Messing with the block definitely affects detecting the references. |
You are right. This issue can be reproduced in Eclipse and IntelliJ IDEA
You can add your favorite imports to |
Organize imports will remove imports when the references are not valid Java code anymore. This might remove "valid" imports that just happen to be unused at that moment, because there is a compile error before the reference. The references cannot be easily restored once the compile errors are fixed, e.g. manually created static imports. This is problematic in long files with many imports and
"editor.codeActionsOnSave" : ["source.organizeImports", ...]
. A typo in the "wrong" place can easily remove all your imports.Environment
Steps To Reproduce
Current Result
All "unused" imports are removed.
Expected Result
Don't remove imports when the Java file has compile errors.
The text was updated successfully, but these errors were encountered: