Skip to content

refactor: replace java-parser with tree-sitter#811

Merged
jtkiesel merged 1 commit intojhipster:mainfrom
jtkiesel:refactor/tree-sitter
Mar 8, 2026
Merged

refactor: replace java-parser with tree-sitter#811
jtkiesel merged 1 commit intojhipster:mainfrom
jtkiesel:refactor/tree-sitter

Conversation

@jtkiesel
Copy link
Contributor

@jtkiesel jtkiesel commented Mar 1, 2026

What changed with this PR:

Major refactor to replace java-parser with tree-sitter. The tree structure of the tree-sitter Java grammar more closely resembles estree's, which makes it considerably easier to port logic from Prettier's JS printer (which made it easy to fix #307 and #777).

Because the parsed tree doesn't end up with real nodes for every single production of the JLS (it seems to use "virtual" node types in many cases), the trees are much shorter/simpler, which results in noticeable performance improvements, both in formatting speed and in memory usage (~26% faster). This results in fixing #806, and also seemingly eliminating the performance issues from the addition of an embed function that was seen in #795, so ought to make that feature possible as well.

Another benefit to tree-sitter is its automatic error recovery. In this PR, I don't leverage it (the parser will still throw an error if the file contains any syntax errors), but in the future we could successfully format the majority of a file, even if it contains syntax errors such as incomplete code.

Relative issues or prs:

Closes #307
Closes #777
Closes #806

@jtkiesel jtkiesel force-pushed the refactor/tree-sitter branch 4 times, most recently from e3b1598 to e71d000 Compare March 2, 2026 00:50
@DanielFran DanielFran added $$ bug-bounty $$ https://www.jhipster.tech/bug-bounties/ $200 labels Mar 2, 2026
@jtkiesel jtkiesel force-pushed the refactor/tree-sitter branch 9 times, most recently from e00afcb to 809acc5 Compare March 8, 2026 06:20
@jtkiesel jtkiesel marked this pull request as ready for review March 8, 2026 17:40
@jtkiesel jtkiesel force-pushed the refactor/tree-sitter branch from 809acc5 to 3a8f73e Compare March 8, 2026 19:13
@jtkiesel jtkiesel merged commit f2db071 into jhipster:main Mar 8, 2026
6 checks passed
@jtkiesel jtkiesel deleted the refactor/tree-sitter branch March 8, 2026 19:31
@DanielFran
Copy link
Member

@jtkiesel You might need to review the readme:
{11105DA4-53AC-49FD-B90D-F11B5CC679F2}

Also Changelog might require some updates:
{A1FCE27C-557B-4767-9836-EB8DF2B1C2D8}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

$$ bug-bounty $$ https://www.jhipster.tech/bug-bounties/ $200

Projects

None yet

Development

Successfully merging this pull request may close these issues.

heap out of memory No linebreak at single variables Unnecessary indent in short operator

2 participants