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

[SUGGESTION] (Java) Formatter-Support: Add clangd-format #283

Closed
NullPlane opened this issue Jun 10, 2024 · 3 comments
Closed

[SUGGESTION] (Java) Formatter-Support: Add clangd-format #283

NullPlane opened this issue Jun 10, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request ready for release

Comments

@NullPlane
Copy link

Java has no officially supported formatter. clang-format appears multiple times and may be used for java too.

{
  "command": "clang-format --style=file:C:\\somefolder\\myform.clang-format $FILENAME",
  "file_patterns": [
    "%.java$"
  ],
  "language": "java"
}

It does work flawlessly for me - stdio and -i, anyways - so for the remaining patterns idk why it should not be on the list.

@SpartanJ
Copy link
Owner

SpartanJ commented Jun 10, 2024

Edit:
Sorry, I did not know it's officially supported, I was wrong. So, yes, it's possible to add it.

A language formatting tool must understand the AST of the code, otherwise you'll encounter many issues, even if currently you did not find them it's dangerous to do it. There's no official formatter but google-java-format is by far the most widely used. The reason I did not add it in a first place is the same than any other java application, they don't distribute a single binary and expect the user to run a jar file from an unknown location, which it's problematic for our use case (I need to know where are the binaries or assets required to run the formatter). Adding the formatter manually is trivial in ecode as you already know, so for the moment I have no solution for this. jdtls does support code-formatting, if you're using it you shouldn't require anything else.
BTW: --style=file:C:\\somefolder\\myform.clang-format you don't need to do that while using clang-format, just create a file called .clang-format in your project root directory and pass --style=file and the formatter will use it.

@SpartanJ SpartanJ reopened this Jun 10, 2024
@SpartanJ SpartanJ self-assigned this Jun 10, 2024
@SpartanJ SpartanJ added the enhancement New feature or request label Jun 10, 2024
@SpartanJ
Copy link
Owner

Done

@NullPlane
Copy link
Author

Done

Beautiful.

Ya idk if this is somewhat dangerous or not but it may be mentioned. I just realized and called it out when I set it up as it might be useful.

BTW: --style=file:C:\\somefolder\\myform.clang-format you don't need to do that while using clang-format, [...]

Did that outta reflex because I assumed that if someone uses it they might have their own file or static file they have to use by employer so I thought no one would always move it everywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ready for release
Projects
None yet
Development

No branches or pull requests

2 participants