Repository navigation
Description
While fixing #1697 in #1717, I found two problems in the diagnostics path that #1717 deliberately leaves alone, because it doesn't need them changed to fix that test. Both are on main at bca8ffb.
1. An unchanged diagnostics update cancels the lazy quick fixes the editor still uses
LSPDiagnosticsForServer.update always calls toMap, even when isDiagnosticsChanged is false. toMap creates new LSPLazyCodeActions for every diagnostic and cancels the old ones, which cancels any pending textDocument/codeAction request.
When the set is unchanged, update returns false, so OpenedDocument.updateDiagnostics doesn't ask LSPDiagnosticsApplier to refresh. The editor keeps the highlights whose quick fixes use the old, cancelled objects, and the new objects go unused.
Servers commonly republish an identical set, for example after each didChange or didSave.
- Before fix: race in lazy quick-fix code actions (#1697), and two test races #1717, a cancelled request was never sent again. The quick fix stayed unavailable, or, if the request was cancelled before it was sent,
ShowIntentionsPassfailed on every run. These are the same symptoms as two of Intermittent WebFilterQuickFixTest failures in CI #1697's failure modes. In CI, though, those came from a race between parallel loads, which fix: race in lazy quick-fix code actions (#1697), and two test races #1717 fixes, not from this cancellation (see below). - With fix: race in lazy quick-fix code actions (#1697), and two test races #1717, the quick fix recovers, but each identical republish still cancels a pending request, sends it again, and replaces objects nothing uses.
To reproduce:
- Open a file with a diagnostic, and make the server's
textDocument/codeActionreply slow. - Put the caret on the diagnostic, so the quick fix starts loading.
- Publish the same diagnostics again while that request is pending.
LSPLazyCodeActionsTest.testCodeActionsLoadAgainAfterAPendingRequestWasCancelled in #1717 does this at the unit level.
Two possible fixes, depending on what the rebuild is for:
- If it has no purpose on an unchanged set, keep the existing map and its
LSPLazyCodeActionswhenisDiagnosticsChangedis false. - If it is meant to drop code actions computed for older text, after edits that leave the diagnostics as they were, it doesn't reach the editor today: the editor keeps the old objects. In that case the applier would also have to re-apply, so that the editor uses the new ones.
2. Diagnostics published before the pass factory is registered are dropped until the set changes
LSPDiagnosticsApplier.scheduleRefresh and collectDiagnostics return early while GROUP_ID == -1. GROUP_ID is set only when the project's highlighting pass registrar calls LSPDiagnosticsPassFactory.registerHighlightingPassFactory, which happens lazily, at the first highlighting.
Diagnostics that arrive before that are stored in OpenedDocument but never applied, and nothing retries. Later identical publishes don't re-apply either, for the reason in part 1. So the diagnostics stay hidden until one of these happens:
- the set changes;
- an all-features editor refresh runs (after indexing, or when a server is enabled or disabled).
This is the same kind of problem as #1665: an apply that is dropped and never retried. #1666 fixed the dropped apply after a modification-stamp mismatch, but not this early return.
In a real session the first editor's highlighting normally registers the factory long before a server answers, so this rarely shows. It does show in tests. In a fresh test JVM, connect a file and wait until its diagnostics are stored before the first highlighting: GROUP_ID is still -1, and repeated doHighlighting() calls show none of them for 30 seconds. #1717's LSPCodeActionFixtureTestCase works around this by asking the applier to refresh, as an editor feature refresh does.
A possible fix is to defer instead of dropping, so the pending refresh runs once GROUP_ID is set.
Resolved: what triggered #1697 in CI
This was an open question in the first version of this issue. It turned out not to be a second diagnostics update. Instrumented main, with WebFilterQuickFixTest repeated 150 times: every repetition had one update, and LSPLazyCodeActions.cancel() was never called.
The trigger is a race in LSPLazyCodeActions.getOrLoadCodeActions. Two highlighting passes, running in parallel, could both find no request and both load. The second load cancels the first request before it is sent. 8 repetitions loaded the same object twice, and the 2 that failed had stored the cancelled request.
#1717 serializes the check and the load. With that, the same 150 repetitions have no double loads and no failures.
Parts 1 and 2 above remain: #1717 doesn't need them changed.
Activity
fix: show diagnostics published before the diagnostics pass is regist…