Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Java Format #419

Closed
azdanov opened this issue Jan 24, 2018 · 9 comments
Closed

Google Java Format #419

azdanov opened this issue Jan 24, 2018 · 9 comments
Labels

Comments

@azdanov
Copy link

azdanov commented Jan 24, 2018

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?

@ddcprg
Copy link

ddcprg commented Jan 26, 2018

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.

@fbricon
Copy link
Collaborator

fbricon commented Jan 26, 2018

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.

@fbricon
Copy link
Collaborator

fbricon commented Jan 26, 2018

I added an entry to the wiki

@azdanov
Copy link
Author

azdanov commented Jan 26, 2018

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:

  • Installing via brew install google-java-format does the trick.
  • Create a tasks.json file in .vscode directory inside your workspace with necessary commands.
  • Run from vscode command palette by running task and finding format task

Here's my tasks.json file:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Run google java format",
      "type": "shell",
      "command": "google-java-format --replace ${file}"
    }
  ]
}

@ddcprg
Copy link

ddcprg commented Jan 26, 2018

thanks @fbricon @azdanov for the swift response

@garymm
Copy link

garymm commented Dec 23, 2019

Would be nice to have this built into the extension so it can work with "format on save".

@power-5000
Copy link

@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?

@lackovic
Copy link

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:

  1. download the latest version of google-java-format all-deps jar

  2. move the jar in a folder (e.g. /opt/)

  3. 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"
    

@mamilic
Copy link

mamilic commented Jan 5, 2024

You can try new extension which can be found here.
https://marketplace.visualstudio.com/items?itemName=mmilic.java-google-format

It works without any hustle, there is no configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants