
Those steps are essentially "run a command on save", and it turns out someone has already written an extension! emeraldwalk/vscode-runonsave reads Visual Studio Code settings, matches files on a regular expression, and then runs a user-supplied command. After about 10 minutes into the exercise, I realized that this plugin was going to be quite dumb: Search for the command TypeScript: Restart TS Server (even if your file is JavaScript). To make sure these settings kick in for your project, you’ll want to: Open a JavaScript or TypeScript file (it doesn’t matter which).

I started down the path of writing my own Visual Studio Code plugin to run google-java-format as a formatter. Reloading VS Code for Changes to Take Effect. I also stumbled across Dev-Snippets/vscode-google-java-format-provider, which seemed promising, but I was unable to get it to register as a formatter (and I am not the only one). Worse, it modified things like license headers, rendering them invalid.

While this does change the default format of the code, in my testing it did not match the output of running google-java-format directly from the command line. Use the navigation File > Preferences > Settings.

This is usually the last option by default in the menu. This seemed like a great fit, since I am already using RedHat's Java Language Support. Auto format code in Visual Studio Code on save using Prettier Step 1: Install Prettier extension. This will instruct the editor to use the "GoogleStyle" when formatting code instead of the built-in style.
