-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
Allow editor.codeActionsOnSave for autoSave afterDelay #200881
Comments
cc @jrieken I think originally we wanted to disable code actions on auto save after delay to prevent altering the editor while you are typing in the editor. But I am easy to relax this, as a customer of auto save after delay, I would not mind to experiment with running formatter for example, maybe with a new setting, off by default. |
I still believe that this isn't a good idea. There is the aspect of no synchronisation point, e.g formatting or code actions happen as you type, but worst is that save after delay often happens in the presence syntax errors (something that's less likely with manual save or editor switch) and tools, like eslint, perform very poorly in such cases, effectively destroying your sources. |
But isn't the point of code actions to remove errors before saving - like there is errors that code actions can fix and there are some that make code actions create more errors... |
Yeah, maybe I misunderstand what the goal is here. I can tell from my use case: I often end up not being able to push my changes to Git because the file is not formatted. Then I have to manually save the file to trigger formatting on save. If formatting would run as part of auto save (after delay), this would not happen. I would be happy to try this out if possible from a new setting. I think @alexdima had another scenario with organising imports, maybe he can comment as well. |
My understanding is that we add new save hooks like "save on git stage". Tho, save on focus change is covering almost all of those cases. It's only annoying when opening the command palette because I usually don't want to save then |
I believe in @alexdima's case, he had manually added some imports in a mostly empty file, continued to type further down and the code actions on save (which had been enabled for auto saves after delay) deleted the imports since they had been unused. The potential here could be something along the lines of allowing actions to be run on auto save after delay when there are no errors (when "files.autoSaveWhenNoErrors": true), but not super married to the idea though, just wanted to gauge how people felt about it 👍 |
If I understand things correctly, configuring I would like the possibility to have files saved with a delay and code actions executed automatically on focus change. I don't see why code actions must execute automatically only during save. Maybe a different way to think of it is that automatic code actions can be triggered by save but can be triggered also by other triggers, like focus change. |
@justschen can we get more details info about which codeAction is making saving sucks? I would be helpful to provide a command to trigger codeActions, but not trigger save. |
@tjx666 see some of the comments talked about here! #221625 tldr: It's likely that the extension causing this is however, if you'd like to trigger code actions independently (ie, throught keybinding), you can run code actions via |
The above PR is as follows: Will trigger code actions for organize imports when the following conditions are applied:
note: will still be triggered when We basically match the behavior of cc. @alexdima |
cc. @bpasero @alexdima
From another conversation:
ATM, code actions on save already work for auto saves on focus change and window change, but not on auto saves. With the addition of being able to configure
autoSave
more granularly, can maybe consider adding back allowing code actions to run on auto save if the delay is significant enough.Additional things to consider:
The text was updated successfully, but these errors were encountered: