It would be great to be able to run Google Java Format Tool on Save in VS Code to force consistent code style in each file of the project.
This can be achieved in Eclipse by dropping in Google Java Format Eclipse Plugin, select it as a Format tool and select to run a format tool on Save in the Eclipse project-specific settings. After that Eclipse starts to reformat all the code on each Save operation from within IDE.
However if you open this same project in VS Code it will not run format tool on each Save operation. I guess VS Code doesn't submit Save event to Eclipse JDT. It would be great if Eclipse JDT actually received and processed this event, if this is possible, so that this workflow worked.
First, format on save is enabled via the vscode preference "editor.formatOnSave": true. Files will be formatted according to the eclipse formatter settings.
Now, for the google formatter, the way I see it, vscode-java might be able to expose a new formatter implementation preference, but then the google formatter itself could be provided via a vscode extension
@fbricon Cool! "editor.formatOnSave": true is what I was actually looking for. Many thanks!
That's not working perfectly. I still get warnings when running the style check later - perhaps VS still use a default java style.
This is a working solution that I'm following: https://stackoverflow.com/a/59718005/1148069
Most helpful comment
First, format on save is enabled via the vscode preference
"editor.formatOnSave": true. Files will be formatted according to the eclipse formatter settings.Now, for the google formatter, the way I see it, vscode-java might be able to expose a new formatter implementation preference, but then the google formatter itself could be provided via a vscode extension