Skip to content

Make it clear what happens when multiple formatters for one document apply #41882

Closed

Description

@octref
  • VSCode Version: 1.19
  • OS Version: macOS 1.12.6

Recently prettier added partial Vue support, and prettier-vscode starts to register itself as a Vue formatter. When user presses format, prettier-vscode was being used (instead of the formatter in Vetur).

vuejs/vetur#658

The user should be given the choice to select a formatter for a specific language.

Activity

  1. added
    formatting
    on Jan 19, 2018
  2. jrieken commented on Jan 23, 2018

    @jrieken
    Contributor

    The user should be given the choice to select a formatter for a specific language.

    How? A formatter has no name nor any other means of identification. We can use the extension name/id but that would only work if there is just one. Worst, the choice cannot be remembered because a formatter is registered with a document selector and (in theory) every document (even of the same language*) can be formatted by a different formatter.

    We have always recommended extensions to either ship more fine-grained, e.g. have a separate formatter extension (and let the user decide by installing/uninstalling) or to add an option to enable/disable their formatter (more commonly used).

    *) A sample is remote/live edit scenarios in which your extension host knows TypeScript files on your disk (file-scheme) and other TypeScript files from somewhere else, e.g. remote-scheme which are formatted by another entity, e.g. not the TS extension

  3. added
    info-needed
    under-discussion
    and removed
    info-needed
    on Jan 23, 2018
  4. octref commented on Jan 23, 2018

    @octref
    ContributorAuthor

    prettier-vscode did add a config prettier.disableLanguages so this can be worked around. So I guess it's each extension's responsibility to make sure they don't clash with others.

    However I still think there should be some visual indication when multiple formatters are being run on the same file. Now the order they are being run seem to be random and users thought the formatters are having bugs.

    image

    I feel no one would want multiple formatters being run on the same file, with order they can't control.

  5. jrieken commented on Jan 24, 2018

    @jrieken
    Contributor

    I feel no one would want multiple formatters being run on the same file,

    We don't run multiple formatters. We pick one and use that. It's just hard to pick one, esp when formatting happens from more subtle gestures like format on paste etc

  6. octref commented on Jan 24, 2018

    @octref
    ContributorAuthor

    OK, running multiple formatter was a misunderstanding, but user not knowing which formatter getting picked isn't that good either.

    If the choice of formatter can't be given to users via a setting easily, how about showing a message like "Multiple formatter is available for this document. VS Code defaults to use xxx formatter. Please update your formatter setting if you would like to choose an alternative formatter"?

  7. jrieken commented on Jan 25, 2018

    @jrieken
    Contributor

    VS Code defaults to use xxx formatter.

    Problem is the xxx because when an extension registers multiple formatters that are only available under certain condition... It's an uncommon scenario not something we should keep in mind

  8. amatiasq commented on Feb 15, 2018

    @amatiasq

    Not sure if this is the place for this question but can't we run formatters sequentially?

  9. jrieken commented on Feb 26, 2018

    @jrieken
    Contributor

    Interesting idea A. Matías Quezada (@amatiasq)... Sequentially maybe but without restart because otherwise you might format endlessly.

  10. usernamehw commented on Mar 11, 2018

    @usernamehw
    Contributor

    How about at least adding a way to get the current formatter(extension name - the one that will be used when you execute Format Document) ?

  11. RiFi2k commented on Aug 12, 2018

    @RiFi2k

    So let me ask you this, I've read the formatting extensions best practices, understand how it works. But in the case of my extension, which formats the HTML code inside of PHP files (which is very important to a large group of people including anyone who devs WordPress).

    Now currently I register this the suggested way, but this is more of a secondary type formatting extension, but now if someone wanted to say use phpcbf to format their PHP, now the user is stuck between which to use what to do. Me personally I run a shell command on save to run my phpcbf command and everything works fine.

    My only option if I want to truly play nice would be to do something like run my formatting (because I don't consider it to be the primary) in some sort of on save hook, spawn a shell command type situation. Or I would have to add the ability to to my extension for doing everything.

    Honestly I feel like it should work more like you register your extension as a formatting OPTION for said language, then have an option for say xyz language formatting where the value is an array of the registered extensions providing the service and you can just sort/remove whatever ones you want. If someone sorts my name higher, run mine first. If I don't show up, don't run it. If nothing is set at all you could basically do what is currently happening and run them in the extension activation order. Provider extension slug is the registered name.

  12. RiFi2k commented on Aug 12, 2018

    @RiFi2k

    Just in case anyone was wondering I just changed to subscribing to onBeforeSave as to not force users to make a decision about what formatting they want more. Now it just picks up the slack and anyone could enable any other PHP extension that wants to register to the main hook.

  13. 67 remaining items

  14. iansan5653 commented on Mar 25, 2019

    @iansan5653
    Contributor

    Maybe we should have an option that lets users select an ordered list of formatters to run on save/paste?

  15. jrieken commented on Mar 25, 2019

    @jrieken
    Contributor

    Ian Sanders (@iansan5653) Ordered in the sense of 'running multiple formatters in that order'?

  16. iansan5653 commented on Mar 25, 2019

    @iansan5653
    Contributor
  17. jrieken commented on Mar 25, 2019

    @jrieken
    Contributor

    re #41882 (comment). Format on Save and format on paste will now stay enabled and they continue to pick the first formatter. Which that is is printed on the status bar (when having many to choose from).

    Also, there is now 'Format Document With...' showing quick pick and 'Format Document' selecting a provider.

  18. jrieken commented on Mar 25, 2019

    @jrieken
    Contributor

    Next revision based on insiders-feedback. Thanks everyone so far. The goal is be less breaking from the behaviour in stable and yet be more explicit about what's happening:

    Mar-25-2019 16-24-14

  19. iansan5653 commented on Mar 25, 2019

    @iansan5653
    Contributor

    Johannes Rieken (@jrieken) I think that's definitely an improvement. Quick question though - what's the definition of the first formatter?

  20. lukejagodzinski commented on Apr 8, 2019

    @lukejagodzinski

    How can I change default formatter after picking one from the list?

  21. Gama11 commented on Apr 8, 2019

    @Gama11
    Contributor

    Your settings.json should have a line like this you can modify:

    "[json]": {
    	"editor.defaultFormatter": "vscode.json-language-features"
    }

    Alternatively, right-click, "Format Document With...", "Configure Default Formatter..." (in a file with the language whose associated formatter you want to change).

  22. lukejagodzinski commented on Apr 8, 2019

    @lukejagodzinski

    Jens Fischer (@Gama11) sorry, my editor didn't refresh after update and I haven't been seeing these options (weird). Now everything works. Thanks anyway!

  23. amatiasq commented on Apr 10, 2019

    @amatiasq

    I'm using prettier with Typescript Import Sort and both are formatting my TS files on save.

    I would like TS Import sort to do it's job and then prettier to make it standard but they are running in the opposite direction and I can see the flashing of prettier and then TS Import Sort breaking the whitespaces.

  24. geri777 commented on Apr 11, 2019

    @geri777

    It would even be helpful to see which extension has registered for which file type.

  25. locked and limited conversation to collaborators on May 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

feature-requestformattingon-testplan

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions