Skip to content

fix: show diagnostics published before the diagnostics pass is registered - #1721

Merged
angelozerr merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/diagnostics-before-pass-registration
Oct 19, 2026
Merged

angelozerr merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/diagnostics-before-pass-registration

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

This fixes part 2 of #1719. Diagnostics that a server publishes before the first highlighting are now shown, instead of being dropped until the set changes.

Problem

LSPDiagnosticsApplier.scheduleRefresh returned early while LSPDiagnosticsApplier.GROUP_ID was -1. GROUP_ID is set only when a project's highlighting pass registrar calls LSPDiagnosticsPassFactory.registerHighlightingPassFactory, which happens lazily, at the first highlighting.

So diagnostics that arrived before that were stored in OpenedDocument but never applied, and nothing retried:

  • In editor mode, LSPDiagnosticsPassFactory.createHighlightingPass returns null, so later highlighting doesn't show them.
  • OpenedDocument.updateDiagnostics asks for a refresh only when the set changes, so a republished, identical set doesn't show them either.

This is the same kind of problem as #1665, an apply that is dropped and never retried. #1666 fixed it for a modification-stamp mismatch, but not for this early return.

Why this is a fix

Per PublishDiagnostics, "Diagnostics notifications are sent from the server to the client to signal results of validation runs", and "Newly pushed diagnostics always replace previously pushed diagnostics". A server only has to push again "when a file changes". A pushed set therefore stays current until the server replaces it, and a client that drops it shows nothing for that file in the meantime.

In a real session the first editor's highlighting usually registers the pass factory before a server answers. A fast server, or files restored at startup, can still publish first, and tests hit this regularly. #1717's LSPCodeActionFixtureTestCase had to work around it by asking the applier to refresh.

Change

  • While GROUP_ID is -1, scheduleRefresh keeps the refresh, one per file, instead of returning.
  • registerHighlightingPassFactory sets GROUP_ID and then runs that project's pending refreshes.
  • The check of GROUP_ID and the addition of a pending refresh share one lock with the flush, so a refresh requested during registration can't be lost.
  • LSPCodeActionFixtureTestCase no longer needs, or carries, the refresh workaround from fix: race in lazy quick-fix code actions (#1697), and two test races #1717.

Validation

  • New LSPDiagnosticsApplierTest:

    1. Sets GROUP_ID to -1, as in a new session, and lets the mock server publish a diagnostic.
    2. Waits until it is stored, and checks that nothing is shown.
    3. Calls LSPDiagnosticsPassFactory.registerHighlightingPassFactory with a stub registrar.
    4. Requires the diagnostic to be shown.

    On unchanged main it fails with expected:<[published early]> but was:<[]>. With the fix it passes.

  • With the diagnostics stored while GROUP_ID is still -1, WebFilterQuickFixTest passes without the fixture workaround. Earlier today the same scenario failed on main without it.

  • ./gradlew check: 577 tests, 0 failures, the 3 existing skips.

Related

…ered

Part 2 of redhat-developer#1719. LSPDiagnosticsApplier.scheduleRefresh returned early while
GROUP_ID was -1. GROUP_ID is set only when a project's highlighting pass
registrar calls LSPDiagnosticsPassFactory.registerHighlightingPassFactory, at
the first highlighting. Diagnostics published before that were stored but
never applied, and nothing applied them later. The editor pass doesn't, and
OpenedDocument only asks for a refresh when the set changes. LSP has a
pushed set replace the previous one, and a server only pushes again when the
file changes.

While GROUP_ID is -1, the refresh is now kept, one per file. The factory
runs the project's pending refreshes after it sets GROUP_ID. The GROUP_ID
check and the addition of a pending refresh share one lock with the flush,
so a refresh requested during registration cannot be lost.

LSPCodeActionFixtureTestCase no longer asks the applier to refresh. redhat-developer#1717
added that workaround for this problem.

Validation:
- New LSPDiagnosticsApplierTest sets GROUP_ID to -1, lets the mock publish
  a diagnostic, and waits until it is stored. It then calls
  registerHighlightingPassFactory with a stub registrar, and requires the
  diagnostic to be shown. On unchanged main it fails with
  "expected:<[published early]> but was:<[]>"; with the fix it passes.
- With the diagnostics stored while GROUP_ID is still -1,
  WebFilterQuickFixTest passes without the fixture workaround. It failed in
  that scenario on main without the workaround.
- ./gradlew check: 577 tests, 0 failures, 3 existing skips.

Signed-off-by: Marcus Lagergren <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 34901b25-866b-451f-9310-fd003996559f
📥 Commits

Reviewing files that changed from the base of the PR and between 20df566 and 49a419f.

📒 Files selected for processing: 4
  • src/main/java/com/redhat/devtools/lsp4ij/features/diagnostics/LSPDiagnosticsApplier.java
  • src/main/java/com/redhat/devtools/lsp4ij/features/diagnostics/LSPDiagnosticsPassFactory.java
  • src/test/java/com/redhat/devtools/lsp4ij/features/diagnostics/LSPDiagnosticsApplierTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/fixtures/LSPCodeActionFixtureTestCase.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.

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Diagnostics published before highlighting is initialized now appear in editor highlights once initialization completes.
  • Tests
    • Added coverage for diagnostics that arrive before highlighting is registered.
    • Updated diagnostic-highlighting retry behavior in test fixtures.

The diagnostics applier now queues refresh requests made before a highlighting pass is registered. Pass registration applies the queued requests. A regression test covers diagnostics published before registration, and the fixture retry loop no longer schedules explicit refreshes.

Changes: Diagnostic refresh handling

Layer / File(s) Summary
Queue and apply pending refreshes
src/main/java/com/redhat/devtools/lsp4ij/features/diagnostics/LSPDiagnosticsApplier.java, src/main/java/com/redhat/devtools/lsp4ij/features/diagnostics/LSPDiagnosticsPassFactory.java
When GROUP_ID is unset, the applier queues callbacks by file identity. After the pass factory assigns the group ID, it applies the queued callbacks.
Verify early diagnostics are highlighted
src/test/java/com/redhat/devtools/lsp4ij/features/diagnostics/LSPDiagnosticsApplierTest.java, src/test/java/com/redhat/devtools/lsp4ij/fixtures/LSPCodeActionFixtureTestCase.java
The new test checks that diagnostics published before pass registration appear after registration. The fixture retry loop no longer schedules explicit refreshes.

Priority: ⬇️ Low

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

Change: Bug fix

Suggested reviewers: angelozerr

Merge Risk: ⚪ Minimal · up to 49a41

The change is mergeable after normal checks; no outstanding defect was established.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly states that the change shows diagnostics published before diagnostics pass registration.
Description check Passed The description directly explains the early diagnostic publication problem, the pending-refresh fix, the tests, and validation results.
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.
  • Fix all pre-merge checks with AI

Warning

CI annotation context is incomplete: annotation collection unavailable or limited

Comment @coderabbitai help to get the list of available commands.

@angelozerr angelozerr added bug Something isn't working diagnostic labels Oct 19, 2026
@angelozerr angelozerr added this to the 0.21.1 milestone Oct 19, 2026
@angelozerr angelozerr moved this to In Progress in Java Tooling Oct 19, 2026
@angelozerr

Copy link
Copy Markdown
Contributor

Thanks @lagergren !

@angelozerr
angelozerr merged commit 523f397 into redhat-developer:main Oct 19, 2026
7 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Java Tooling Oct 19, 2026
angelozerr pushed a commit that referenced this pull request Oct 20, 2026
…stics

testDiagnosticsPublishedBeforeThePassIsRegisteredAreShown (#1721) failed twice on main on macOS
with "expected:<[published early]> but was:<[]>". OpenedDocument.updateDiagnostics stores the
diagnostics and only then requests their refresh. The test waited for the stored diagnostics, so
it could register the pass factory before the refresh was requested: nothing was pending, and the
refresh came afterwards as an ordinary background one, after the test's single event dispatch.

LSPDiagnosticsApplier.hasPendingRefreshes() (@testonly) says whether a refresh waits for GROUP_ID.
The test waits for it before registering the pass factory, so it always checks the case it is
about, and afterwards waits until the diagnostics are shown. No production behavior changes.

Validation, with OpenedDocument.updateDiagnostics locally made to sleep a second between storing
the diagnostics and requesting their refresh: the test on main fails as on CI, and the changed
test passes; both pass without the delay. With #1721's fix reverted, the changed test fails ("the
refresh must wait for the pass"). ./gradlew check: 595 tests, 0 failures, the 3 existing skips.
@lagergren
lagergren deleted the fix/diagnostics-before-pass-registration branch October 26, 2026 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working diagnostic

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants