How can I configure multiple formatters to run in a sequence on save in VSCode?
17:20 22 Aug 2019

I am working on a Haskell project that must be formatted by both:

  • stylish-haskell (for import reordering)
  • brittany (for general formatting)

I can set the single default formatter for a language:

"[haskell]": {
    "editor.defaultFormatter": "MaxGabriel.brittany"
}

or I can select one from a list using editor.action.formatDocument.multiple ("Format Document With... in the command palette).

But I need to run both of them, one after the other, on save. As of right now, I can only run the single default formatter on save. The order doesn't matter in this case, but it could in more general cases.

I've tried setting editor.defaultFormatter to a list of formatters (this didn't work, as expected) and built a local extension that calls editor.action.formatDocument.multiple with various arguments, which just brings up a drop-down list of available formatters to choose from.

How can I run both formatters sequentially on save?

visual-studio-code vscode-extensions