For supported files in VSCode we get an option (when you right click on the file editor) to Format Document (ALT+SHIFT+F)
.
But unfortunately for Groovy this option is not available. And according to the VSCode community, there are no plans to implement this feature.
Is there an alternative solution available, specifically for VSCode?
There is now a Visual Studio Code extension to Lint, Format and Auto-fix Groovy and Jenkinsfiles ! :)
https://marketplace.visualstudio.com/items?itemName=NicolasVuillamy.vscode-groovy-lint
It would only be available via an extension, which you can search for in the marketplace.
Unfortunately it doesn't look like there are many extensions for Groovy at all. And if that can be considered an indication of the language's popularity, it's highly unlikely that broad support would ever be added to VS Code out of the box.
I don't know how well this works for formatting other than indentation, but I simply changed the file extension from .groovy to .js, right clicked in the file, and selected "Format Document". It fixed the indentation for me.