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
"source.organizeImports" shouldn't remove my unused imports #36085
Comments
I would love this feature. It really helps if we have a parameter to decide if we want vscode to remove or not the unused imports. I have many problems when I am coding and then suddenly the import disappear. The solution is: all the time I have to add the import again or I have to add another third party plugin to control my imports instead of using the vscode functionality. |
We definitively need an option to grey out unused imports vs removing them. Here’s my use case. When I temporarily disable code blocks, the related imports are removed if not used elsewhere in the code. When I re-enable them, the imports are gone and the code is broken. |
@RyanCavanaugh, is there a fix for this aside from disabling |
It happens to me all the time... And worse, I have a habit of saving every line of writing, so I often import, save, write the code I'm going to use that import... This is terrible for me ... I have to "fight the IDE" to program the way I'm used to... |
Just found this via microsoft/vscode#89263 - also was just bitten by this:
Two suggestions here:
|
@karlhorky I am no longer using organize because of this. In fact I am using it manually sometimes, when I have finished all changes to the file. It would be nice if there were two separate features, one to organize and one to remove. People who just want to remove unused imports and / or people who want to organize imports. |
I will close this issue because the problem is with vscode and not with typescript. |
@RyanCavanaugh would it be possible to get an option / separate function for this? Or if not, what would you like to see with "more feedback"? I guess this would be a pretty important issue for a lot of developers... |
For an example of a user story why a setting would be critical to some users, here's what we've been running into: Bootcamp students at @upleveled are beginners - they are learning how to code for the first time. It is very helpful for them to have tools that help them with best practices, such as auto saving, code formatting, auto sorting and import combining tools. If they use |
I think the following may be a suitable plan, which will still keep those happy who appreciate this removal behavior:
It would also make the behavior of the option more explicit. |
I think something even more explicit than this would be |
FWIW I discovered this already exists under a slightly different name: {
"key": "shift+ctrl+r",
"command": "editor.action.sourceAction",
"args": {
"kind": "source.removeUnused",
"apply": "first"
}
}, |
Note that |
Ohh was this just released in VS Code 1.57?
"editor.codeActionsOnSave": {
"source.sortImports": true
} https://code.visualstudio.com/updates/v1_57#_sort-imports-source-action |
@yardz if you test this out and it addresses your wish, maybe you can close this issue? |
|
@karlhorky Sorry for the delay, I wasn't following and missed the notification. I just tested it and it really works. |
I have noticed that switching to Anyone else seeing this? |
@sjc5 I'm not seeing that on my end. Unused imports are still showing as unused and vice versa. |
I guess I should raise a new issue about an import type being removed when working with Flow, but I don't even like Flow, so... yeah just using "source.sortImports" instead of organizeImports will be good enough. |
Search Terms
source.organizeImports, remove unused imports, don't remove unused imports
Suggestion
When i put "source.organize Imports" in "editor.codeActionsOnSave" it removes my unused imports. It would be interesting to have a parameter for it to just organize but not remove.
Use Cases
Many developers save their files all the time, often without even realizing it. This feature is very interesting but ends up "disturbing" who has this habit.
If you can pass a few more configuration parameters (like not removing unused imports or not removing space between imports) this feature would be better taken advantage of.
The text was updated successfully, but these errors were encountered: