Skip to content
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

visual studio code removes import statements on save #675

Closed
akaroml opened this issue Oct 15, 2018 · 6 comments
Closed

visual studio code removes import statements on save #675

akaroml opened this issue Oct 15, 2018 · 6 comments

Comments

@akaroml
Copy link
Contributor

akaroml commented Oct 15, 2018

Copied from microsoft/vscode-java-pack/issues/44

@viraj1994 reported that the import statements are removed on save. Here's a video of the issue:

https://drive.google.com/file/d/16bxoqj-4pA_aJAOChTpLpinpaiZCwwQf/view

@fbricon
Copy link
Collaborator

fbricon commented Oct 15, 2018

Those imports are not used. If you set "java.saveActions.organizeImports": true in your vscode settings, it's expected to see them removed.

@MarcelloPerathoner
Copy link

Those imports are not used. If you set "java.saveActions.organizeImports": true in your vscode settings, it's expected to see them removed.

Has this become the default? Because I surely did not set that one in my settings. Where else can it come from?

This is a dangerous thing because if you save with syntax errors, maybe just a curly brace too many, it will happily remove most of your imports.

@fbricon
Copy link
Collaborator

fbricon commented Nov 6, 2023

@MarcelloPerathoner sounds similar to #3370. If you have a .settings/org.eclipse.jdt.ui.prefs file with:

editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
...
sp_cleanup.organize_imports=true

Setting either to false, or deleting the prefs file should help.

@rgrunber vscode-java should probably disable JDT UI prefs support. It's a definitely a source of confusion/frustration.

@MarcelloPerathoner
Copy link

Thanks. I had both those settings. But that file was last committed 6 years ago, and I don't remember it happening before. Something must have changed in vscode lately.

@fbricon
Copy link
Collaborator

fbricon commented Nov 6, 2023

@MarcelloPerathoner yes, this is caused by eclipse-jdtls/eclipse.jdt.ls#2870

@girotomas
Copy link

girotomas commented Aug 6, 2024

I disabled my java extensions searching for @enabled java in extensions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants