redhat-developer / redhat-developer/vscode-java

Inconsistency in line break "{}" formatting in Java with in VS Code

Open
#3,694 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
2.3k
Forks
546
Avg merge
20h 1m
Merged PRs (30d)
11

Description

In my VSC I have the extension called "Language support for java(TM) by red hat". The typical one that all of us who do Java have and this is self-evident. The formatter of said extension does not format correctly. Surely the formatting is taken from LLVM so there is some error or even some incorrect syntax when formatting

When I format in VSC this example code with java or java spring boot:

❌Incorrect - If I format like this, it leaves it like this
This happens on both the opening "{" and the ending "}". It seems that the extra space has no influence since the format accepts both together and extra spacing. When the correct one is the second one with the extra spacing.

Incorrect Preview
image image image
Also say the formatting of the extension also leaves it like this if the code is like this.image

3 incorrect formats accepted by the formatter have been shown. Therefore, if there is any code "in that format", the formatter will leave it that way. Only the correct one is the last one or the one made by Eclipse.
This doesn't make much sense since the code is stuck above or below or even between the curly braces "{}".

This way of formatting is not expected for those of us who work with Java. Eclipse does well in this regard.

✅ correct - This is how Eclipse does it. It doesn't matter how messy the code is. It will leave it like this:

Correct Preview
image

I have tried countless things, none of them worked.

This has worked since 2007 in eclipse. We are in 2024. As an example of a good format:
image

How do you solve this problem and get the correct form, like correct or equal to eclipse?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the brace and line-break formatting behavior in the Java VS Code extension using the examples and screenshots in the report, then compare the output with Eclipse. Trace the formatter behavior from the extension's Java formatting entry point and determine whether the discrepancy is configuration or implementation. Done means the reported layouts are normalized to the expected Eclipse-style result.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, vscode
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.