Vscode-java: Feature Request: Reformat all the code with Google Java Format tool on Save

Created on 23 Feb 2018  路  3Comments  路  Source: redhat-developer/vscode-java

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.

enhancement formatter

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

All 3 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sfariaNG picture sfariaNG  路  3Comments

roben picture roben  路  4Comments

danielcalvogonzalez picture danielcalvogonzalez  路  3Comments

jcjolley picture jcjolley  路  3Comments

yaohaizh picture yaohaizh  路  4Comments