Skip to content

Format on Save #12449

Closed
Closed

Description

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.

Activity

  1. added
    feature-request
    on Sep 22, 2016
  2. jrieken commented on Sep 22, 2016

    @jrieken
    ContributorAuthor

    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 onWillSaveTextDocument event 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?

  3. jrieken commented on Sep 22, 2016

    @jrieken
    ContributorAuthor

    re #12449 (comment)

    Hooky (@HookyQR) same question. How do people react to auto-save and format on save?

  4. jrieken commented on Sep 22, 2016

    @jrieken
    ContributorAuthor

    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

  5. ramya-rao-a commented on Sep 22, 2016

    @ramya-rao-a
    Contributor

    Johannes Rieken (@jrieken) Below is an excerpt from the README for the Go extension

    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.

  6. ramya-rao-a commented on Sep 22, 2016

    @ramya-rao-a
    Contributor

    Johannes Rieken (@jrieken) Would the new files.formatOnSave format all files during Save All ? There is a feature ask for the same in Go extension microsoft/vscode-go#279

  7. jrieken commented on Sep 23, 2016

    @jrieken
    ContributorAuthor

    re #12449 (comment) - yes formatOnSave will work together with Save All

  8. jrieken commented on Sep 23, 2016

    @jrieken
    ContributorAuthor

    re #12449 (comment) - we now don't format on auto save

  9. jrieken commented on Sep 23, 2016

    @jrieken
    ContributorAuthor

    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.

  10. bpasero commented on Sep 23, 2016

    @bpasero
    Contributor

    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.

  11. jrieken commented on Sep 23, 2016

    @jrieken
    ContributorAuthor

    I see - I was assuming cmd+s is off when auto save is on. Reality is already a lot better then I assumed.

  12. bpasero commented on Sep 23, 2016

    @bpasero
    Contributor

    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.

  13. jrieken commented on Sep 23, 2016

    @jrieken
    ContributorAuthor

    stretch - let's wait for that request.

  14. HookyQR commented on Sep 24, 2016

    @HookyQR
    Contributor

    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.

  15. daviwil commented on Oct 11, 2016

    @daviwil
    Contributor

    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!

  16. jrieken commented on Oct 11, 2016

    @jrieken
    ContributorAuthor

    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

  17. Lonefy commented on Nov 22, 2016

    @Lonefy

    Johannes Rieken (@jrieken) Sorry for reply late. i'm really busy for this several months and i'll try to fix the problem soon.

  18. locked and limited conversation to collaborators on Nov 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

feature-request

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions