Repository navigation
fix: show diagnostics published before the diagnostics pass is registered - #1721
Merged
angelozerr merged 1 commit intoOct 19, 2026
Conversation
…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]>
Contributor
|
Thanks @lagergren ! |
This was referenced 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.scheduleRefreshreturned early whileLSPDiagnosticsApplier.GROUP_IDwas-1.GROUP_IDis set only when a project's highlighting pass registrar callsLSPDiagnosticsPassFactory.registerHighlightingPassFactory, which happens lazily, at the first highlighting.So diagnostics that arrived before that were stored in
OpenedDocumentbut never applied, and nothing retried:LSPDiagnosticsPassFactory.createHighlightingPassreturnsnull, so later highlighting doesn't show them.OpenedDocument.updateDiagnosticsasks 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
LSPCodeActionFixtureTestCasehad to work around it by asking the applier to refresh.Change
GROUP_IDis-1,scheduleRefreshkeeps the refresh, one per file, instead of returning.registerHighlightingPassFactorysetsGROUP_IDand then runs that project's pending refreshes.GROUP_IDand the addition of a pending refresh share one lock with the flush, so a refresh requested during registration can't be lost.LSPCodeActionFixtureTestCaseno 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:GROUP_IDto-1, as in a new session, and lets the mock server publish a diagnostic.LSPDiagnosticsPassFactory.registerHighlightingPassFactorywith a stub registrar.On unchanged
mainit fails withexpected:<[published early]> but was:<[]>. With the fix it passes.With the diagnostics stored while
GROUP_IDis still-1,WebFilterQuickFixTestpasses without the fixture workaround. Earlier today the same scenario failed onmainwithout it../gradlew check: 577 tests, 0 failures, the 3 existing skips.Related
LSPDiagnosticsApplierupdate (stale squiggle survives until the diagnostic set changes) #1665 / fix: Reschedule diagnostics refresh on modification-stamp mismatch #1666 fixed the same kind of dropped apply for a different trigger.