-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
Format on Save #12449
Comments
cc @ramya-rao-a , @mattetti, @lukehoban I see that vscode-go has this which won't be needed much longer. With #239 we will add the I wanna poke your brains wrt to format on save and auto save. This is obviously a hot topic because auto-save happens while typing meaning formatting might kick in unpleasantly. Did you get feedback in that direction? Do you have ideas - like not formatting when it's auto-save and messing for your cursors? |
@HookyQR same question. How do people react to auto-save and format on save? |
Proposal is to ignore formatting when auto-save happens in an focused editor and when the edits overlap with any of the cursors - https://github.com/Microsoft/vscode/blob/joh/formatOnSave/src/vs/workbench/api/node/mainThreadSaveParticipant.ts#L124 |
@jrieken Below is an excerpt from the README for the Go extension
It is suggested to not use both together. There have been a few instances (microsoft/vscode-go#368, microsoft/vscode-go#447) which left users baffled when their code kept disappearing which was Auto Save triggering formatting that deleted unused imports or multiple new lines. Since |
@jrieken Would the new |
re #12449 (comment) - yes |
re #12449 (comment) - we now don't format on auto save |
@bpasero Can you make sure the participant is called when auto-save is true but when the user pressed |
@jrieken today all save attempts are ignored if the model is not dirty. though for this milestone I fixed another feature request where people wanted the save to go to disk even when the model is not dirty so that external file watchers get triggered (e.g. nodemon). My solution is not going through the model, but now that we have a use case for this, I can revisit that solution and make sure we go through the model even if the model is not dirty. This would then also count as a normal save and not auto save. |
I see - I was assuming cmd+s is off when auto save is on. Reality is already a lot better then I assumed. |
@jrieken yup, if auto save is on but the file is still dirty (because it was not auto saved yet), the save will still happen when manually saving by the user. So the question is: do we want format on save even when the file is not dirty and the user saves manually. |
stretch - let's wait for that request. |
@jrieken I don't recall any issues being raised with auto save and format on save both being set for my extensions. I guess most users would recognise it as a problem pretty quick and turn one of them off. |
Sorry for asking here, I didn't find this information elsewhere. How does an extension register a formatting provider for a language? I don't see it in the list of contribution points. Thanks! |
It happens in code using the |
@jrieken Sorry for reply late. i'm really busy for this several months and i'll try to fix the problem soon. |
Given the infrastructure we have built for #239 we can offer something like
files.formatOnSave
whichs mean format a document whenever we are about to save it.The text was updated successfully, but these errors were encountered: