You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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?
If you do turn Auto Save on, you may also want to turn format-on-save off ("go.formatOnSave": "false"), so that it is not triggered while typing
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.
Long time users of the extension do not use this combination due to the exact same issue.
Since files.autosave is off by default, it was safe for go.formatOnSave to be on by default as per microsoft/vscode-go#253. The same issue has some feedback about this combination of settings.
Benjamin Pasero (@bpasero) Can you make sure the participant is called when auto-save is true but when the user pressed cmd+s explicitly? In would be good if that doesn't count as auto save but explicit save.
Johannes Rieken (@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.
Johannes Rieken (@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.
Johannes Rieken (@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 registerXYZFormattingEditProvider-functions. That's more or less how you get into the Format Code action and we invoke that when saving
Activity
jrieken commentedon Sep 22, 2016
cc Ramya Rao (@ramya-rao-a) , Matt Aimonetti (@mattetti), Luke Hoban (@lukehoban) I see that vscode-go has this which won't be needed much longer. With #239 we will add the
onWillSaveTextDocumentevent and with this isse we will utilise our new infrastructure to format on save.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?
jrieken commentedon Sep 22, 2016
re #12449 (comment)
Hooky (@HookyQR) same question. How do people react to auto-save and format on save?
jrieken commentedon Sep 22, 2016
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
ramya-rao-a commentedon Sep 22, 2016
Johannes Rieken (@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.
Long time users of the extension do not use this combination due to the exact same issue.
Since
files.autosaveis off by default, it was safe forgo.formatOnSaveto be on by default as per microsoft/vscode-go#253. The same issue has some feedback about this combination of settings.ramya-rao-a commentedon Sep 22, 2016
Johannes Rieken (@jrieken) Would the new
files.formatOnSaveformat all files duringSave All? There is a feature ask for the same in Go extension microsoft/vscode-go#279jrieken commentedon Sep 23, 2016
re #12449 (comment) - yes
formatOnSavewill work together withSave Alldon't run formatOnSave when auto saved, #12449
jrieken commentedon Sep 23, 2016
re #12449 (comment) - we now don't format on auto save
rename setting to 'editor.formatOnSave', #12449
jrieken commentedon Sep 23, 2016
Benjamin Pasero (@bpasero) Can you make sure the participant is called when auto-save is true but when the user pressed
cmd+sexplicitly? In would be good if that doesn't count as auto save but explicit save.bpasero commentedon Sep 23, 2016
Johannes Rieken (@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.
jrieken commentedon Sep 23, 2016
I see - I was assuming cmd+s is off when auto save is on. Reality is already a lot better then I assumed.
bpasero commentedon Sep 23, 2016
Johannes Rieken (@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.
jrieken commentedon Sep 23, 2016
stretch - let's wait for that request.
HookyQR commentedon Sep 24, 2016
Johannes Rieken (@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.
daviwil commentedon Oct 11, 2016
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!
jrieken commentedon Oct 11, 2016
It happens in code using the
registerXYZFormattingEditProvider-functions. That's more or less how you get into theFormat Codeaction and we invoke that when savingLonefy commentedon Nov 22, 2016
Johannes Rieken (@jrieken) Sorry for reply late. i'm really busy for this several months and i'll try to fix the problem soon.