Is there a way to setup formatting with Google Java Format?
Or an entirely new extension is needed which will run the jar formatter on opened file?
If so, what would be the best way to implement this as an extension, e.g running external jar?
This would be cool.
I'm looking for a way of configuring the formatter and the code organizer with similar settings to eclipse/intellij even better if I can import the files directly. Seems like this extension comes with predefined settings which cannot be changed.
The only way you can set it up currently is to save the google java format as eclipse formatter settings, in your .settings/org.eclipse.jdt.core.prefs.
I added an entry to the wiki
I've found a solution that works ok.
https://code.visualstudio.com/docs/editor/tasks
For that to work make sure java-google-format can be executed from terminal. In my case:
brew install google-java-format does the trick.tasks.json file in .vscode directory inside your workspace with necessary commands.task and finding format taskHere's my tasks.json file:
{
"version": "2.0.0",
"tasks": [
{
"label": "Run google java format",
"type": "shell",
"command": "google-java-format --replace ${file}"
}
]
}
thanks @fbricon @azdanov for the swift response
Would be nice to have this built into the extension so it can work with "format on save".
@azdanov Could you go into a bit more detail about the process you found? I am running on a Windows system what exactly is the brew program and is is that the required method to install the formatter?
There is a new _Google Java Format_ extension released a couple of months ago available in Visual Studio Marketplace whose source code is hosted on GitLab.
To make it work you need to:
download the latest version of google-java-format all-deps jar
move the jar in a folder (e.g. /opt/)
enter the full path to the jar in gjf.jarPath of your user or workspace settings as follows:
"gjf.jarPath": "/opt/google-java-format-1.9-all-deps.jar"
Most helpful comment
I've found a solution that works ok.
https://code.visualstudio.com/docs/editor/tasks
For that to work make sure
java-google-formatcan be executed from terminal. In my case:brew install google-java-formatdoes the trick.tasks.jsonfile in.vscodedirectory inside your workspace with necessary commands.taskand findingformattaskHere's my
tasks.jsonfile: