SpartanJ / ecode

Lightweight multi-platform code editor designed for modern hardware with a focus on responsiveness and performance.
MIT License
940 stars 13 forks source link

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

Closed NullPlane closed 4 months ago

NullPlane commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

Done

NullPlane commented 5 months ago

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.