Skip to content

Unchanged diagnostics updates cancel the editor's quick-fix requests, and diagnostics published before the first highlighting are not shown #1719

Closed

Description

@lagergren

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.

To reproduce:

  1. Open a file with a diagnostic, and make the server's textDocument/codeAction reply slow.
  2. Put the caret on the diagnostic, so the quick fix starts loading.
  3. 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 LSPLazyCodeActions when isDiagnosticsChanged is 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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions