Apex Prettier runs slower than most other formatters. In some cases formatting will not succeed because VS Code will time out the operation after 500ms. In order to ensure Apex code has enough time to format your documents we recommend changing the VS Code settings as follows.
{
"editor.formatOnSaveTimeout": 5000
}
Production ready:
https://github.com/dangmai/prettier-plugin-apex
and note this is recommended by SF themselves but with some special config to allow for longer build time of Apex:
https://developer.salesforce.com/tools/vscode/en/user-guide/prettier/