Features
Formatter which runs multiple formatters in sequence configured via the format-att.formatters setting
Usage
- Configure the
format-att.formatters setting in the VS Code settings (see below)
- Right click in a document and select
Format Document With... or Format Selection With...
- Either select the
Format ATT formatter to run the formatter or Configure Default Formatter... and then Format ATT to set it as the default formatter
VS Code setting format-att.formatters. Accepts a list of formatter ids or objects in the form { "formatterId": string, "languageId": string } when there are multiple languages in a single file.
Formatter ids can be found via the editor.defaultFormatter setting.
Language ids can be found via the New Untitled Text File command and clicking the Select a language link.
Examples
ESLint & Prettier
"format-att.formatters": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
TypeScript Specific
"[typescript]": {
"format-att.formatters": [
"vscode.typescript-language-features",
"esbenp.prettier-vscode"
]
}
Multi Language
"format-att.formatters": [
{ "formatterId": "vscode.typescript-language-features", "languageId": "typescript" },
{ "formatterId": "vscode.html-language-features", "languageId": "html" }
]
*note this is only required for multiple languages in a single file
Command which runs a formatter configured in the keyboard shortcuts
Usage
- Open the keyboard shortcuts json file using the
Open Keyboard Shortcuts (JSON) command
- Add a new keybinding using the
Define Keybinding button in the bottom right
- Change the
command value to format-att.format
- Add
args in the form "args": { "formatterId": string, "mode": "selection" | undefined }
- Formatter ids can be found via the
editor.defaultFormatter setting
Keyboard Shortcuts Examples
Prettier - Format Selection
{
"key": "ctrl+m ctrl+m",
"command": "format-att.format",
"when": "editorTextFocus",
"args": { "formatterId": "esbenp.prettier-vscode", "mode": "selection" }
}
Multi Formatter - Format Document
{
"key": "ctrl+m ctrl+m",
"command": "format-att.format",
"when": "editorTextFocus",
"args": { "formatterId": "unimorphic.format-att" }
}
Thanks
Thanks to the following extension that was used as inspiration
https://github.com/jota0222/MultiFormatterVSCode
License
MIT