Skip to content

fix: LSP4IJ's Enter between braces applies only to the files of language servers, without the deprecated EnterBetweenBracesHandler - #2332

Merged
lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/enter-between-braces-only-for-language-server-files
Nov 28, 2026
Merged

lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/enter-between-braces-only-for-language-server-files

Conversation

@lagergren

@lagergren lagergren commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #1971

LSPEditorImprovementsEnterBetweenBracesHandler, LSP4IJ's workaround for IJPL-159454, no longer extends the deprecated EnterBetweenBracesHandler, which the plugin verifier reports on every release from 2024.2 to 2026.3. It works the same on all of them, without reflection. One commit, for 0.30.2.

Behaviour change

Before After
Ordered first, and extending the platform's Enter between braces, the handler split the braces of every file, before the Enter handlers that ask to run before the platform's, such as those of Kotlin, Java's Javadoc snippets and text blocks, and Groovy. It leaves the files that it doesn't fix to the platform's Enter between braces, which splits their braces where it is registered, after those handlers. The Enter of the files of language servers that it fixes doesn't change.

What the deprecated class is

In the sources of idea/242.20224.300 and idea/263.7307.200, the same in both:

  • EnterBetweenBracesHandler only overrides isApplicable of EnterBetweenBracesFinalHandler, to use the default EnterBetweenBracesDelegate instead of the one of the file's language.
  • The platform registers EnterBetweenBracesFinalHandler, which isn't deprecated, with the id EnterBetweenBracesHandler. The deprecated class isn't registered.
  • Only JSON, Kotlin and TOML have an EnterBetweenBracesDelegate of their own in 2024.2, and JavaScript too in 2026.3: no TextMate, plain text or any one.

The replacement that the deprecation names, an EnterBetweenBracesDelegate of a language, can't do what the workaround does: it rewrites the braces and their indent once the Enter is done, in postProcessEnter, for files of any language that a language server serves.

The change

  • The handler extends EnterHandlerDelegateAdapter, which isn't deprecated on 2024.2 to 2026.3.
  • On the files that it fixes, of an abstract file type or a TextMate one whose language server enables the fix, it runs a private EnterBetweenBracesFinalHandler first, as the deprecated class did. Their languages have no delegate, so the default one decides, as before. For a TextMate file it splits nothing, since its braces are in the same PSI element: the fix is postProcessEnter's, which doesn't change.
  • On any other file, it returns Continue.

It doesn't extend EnterBetweenBracesFinalHandler, whose javadoc asks not to. 2026.3 also makes the static helpers that the deprecated class uses @ApiStatus.Internal.

Tests

New EnterBetweenBracesOrderTest, on a JSON file, which has no language server in these tests, and whose braces are elements of their own:

Test Before After
testAHandlerBeforeTheEnterBetweenBracesSeesTheBracesOfAFileWithoutALanguageServerAsTheyWere: an Enter handler ordered before EnterBetweenBracesHandler records the document it sees fails: expected:<[{}]> but was:<[{\n}]>, LSP4IJ had split the braces already passes
testTheEnterBetweenTheBracesOfAFileWithoutALanguageServerSplitsThem passes passes: the platform's handler still splits them

TypeScriptEditorImprovementsTest and TypeScriptCustomLanguageServerEditorImprovementsTest test the fix itself, with it enabled and disabled, and pass unchanged.

Headless, with the counts from the JUnit XMLs:

Classes IntelliJ Tests Failures
The 15 classes of features.formatting, with the first version of the new test1 IC 2024.2, IU 2026.3 79 others 0
EnterBetweenBracesOrderTest, TypeScriptEditorImprovementsTest, TypeScriptCustomLanguageServerEditorImprovementsTest IC 2024.2 24 0
The same IU 2026.3 24 0

Not covered

  • No test runs an Enter in a Kotlin, Java or Groovy file with their own handlers, which the change lets run first. The test with a handler ordered like theirs stands in for them.

Footnotes

  1. The first version of EnterBetweenBracesOrderTest used a plain text file, whose braces are in one element, which no Enter splits, and a TextMate file, whose braces the platform doesn't split either. It failed with the old handler and the new one alike, and was rewritten. ↩

…age servers, without the deprecated EnterBetweenBracesHandler

LSPEditorImprovementsEnterBetweenBracesHandler, the workaround for IJPL-159454, extended the deprecated
EnterBetweenBracesHandler. That class only overrides the isApplicable of EnterBetweenBracesFinalHandler, which the
platform registers with the id EnterBetweenBracesHandler, so that it uses the default EnterBetweenBracesDelegate instead
of the one of the file's language. The replacement which the deprecation names, an EnterBetweenBracesDelegate of a
language, can't do what the workaround does: it rewrites the braces and their indent once the Enter is done, in
postProcessEnter.

The handler now extends EnterHandlerDelegateAdapter, and runs a private EnterBetweenBracesFinalHandler first on the
files that it fixes, as the deprecated class did: the files of language servers, of an abstract file type or a
TextMate one, whose language server enables the fix. No language of these files has an EnterBetweenBracesDelegate in
2024.2 to 2026.3, so the default one decides, as before, and their Enter doesn't change. It splits no braces of a
TextMate file, whose braces are in the same element: the fix is postProcessEnter's.

Ordered first, and extending the platform's handler, it also split the braces of every other file, before the Enter
handlers that ask to run before the platform's, such as those of Kotlin, Java and Groovy. It now leaves those files to
the platform's handler, which splits their braces where it is registered.

The new EnterBetweenBracesOrderTest records what an Enter handler ordered before the platform's sees in a JSON file,
which has no language server there: it saw the braces split already, and sees them as they were now. The platform's
handler still splits them.

Part of redhat-developer#1971
@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved pressing Enter between braces in supported files when smart indent is enabled, preserving the expected brace layout and indentation.
    • Verified brace splitting in JSON files without a language server.

The Enter-between-braces handler now uses conditional delegation instead of extending the platform handler. Tests check brace splitting in a JSON file without a language server and verify the order in which handlers see the braces.

Changes: Enter Between Braces Handling

Layer / File(s) Summary
Conditional handler delegation
src/main/java/com/redhat/devtools/lsp4ij/features/formatting/LSPEditorImprovementsEnterBetweenBracesHandler.java
The handler extends EnterHandlerDelegateAdapter and delegates to EnterBetweenBracesFinalHandler when the supported-file, smart-indent, and feature-flag conditions are met. Otherwise, it continues through the delegate chain.
Brace splitting and handler-order tests
src/test/java/com/redhat/devtools/lsp4ij/features/formatting/EnterBetweenBracesOrderTest.java
Tests check that Enter splits braces in a JSON file without a language server, that an earlier handler sees {} before the split, and that the resulting layout and caret position match the assertions.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: scwells72

Merge Risk: Minimal · up to 745ec

This change stops the Enter-between-braces handler from extending a deprecated platform class, so files not handled by the language-server fix keep the platform's normal handler ordering. No concrete merge-blocking risk was found, and the tests cover the changed ordering behavior.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: LSP4IJ's Enter-between-braces fix now applies only to language-server files and no longer extends the deprecated EnterBetweenBracesHandler. This matches the changed su…
Description check Passed The description explains the motivation (plugin verifier warnings for the deprecated EnterBetweenBracesHandler), the behavior change, the new handler structure, and the new EnterBetweenBracesOrderTest…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: LSP4IJ's Enter-between-braces fix now applies only to language-server files and no longer extends the deprecated EnterBetweenBracesHandler. This matches the changed superclass and the new Continue path for other files. The title is long (130 characters) but is specific and accurate.

Full details: Description check

Explanation

The description explains the motivation (plugin verifier warnings for the deprecated EnterBetweenBracesHandler), the behavior change, the new handler structure, and the new EnterBetweenBracesOrderTest with its test results. It is directly related to the changeset.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 17caf5ce-f081-464e-9b61-99563e3e4c8d
Commits

Reviewing files that changed from the base of the PR and between 0fd429a and 745ec0b.

Files selected for processing: 2

  • src/main/java/com/redhat/devtools/lsp4ij/features/formatting/LSPEditorImprovementsEnterBetweenBracesHandler.java
  • src/test/java/com/redhat/devtools/lsp4ij/features/formatting/EnterBetweenBracesOrderTest.java

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@lagergren lagergren added the debt label Nov 28, 2026
@codecov

codecov Bot commented Nov 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 58.66%. Comparing base (55f8b05) to head (745ec0b).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...SPEditorImprovementsEnterBetweenBracesHandler.java 90.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2332      +/-   ##
==========================================
+ Coverage   58.65%   58.66%   +0.01%     
==========================================
  Files         849      849              
  Lines       36709    36719      +10     
  Branches     5766     7609    +1843     
==========================================
+ Hits        21530    21541      +11     
+ Misses      12179    12177       -2     
- Partials     3000     3001       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lagergren lagergren added this to the 0.30.2 milestone Nov 28, 2026
@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

1 similar comment
@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren
lagergren merged commit 7c6d061 into redhat-developer:main Nov 28, 2026
11 checks passed
@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Action not completed

Pull request is closed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant