Skip to content

Diagnostics stop refreshing after a dropped LSPDiagnosticsApplier update (stale squiggle survives until the diagnostic set changes) #1665

Closed

Description

@bamboo

Summary

Since fa5764c, textDocument/publishDiagnostics is rendered reactively by
LSPDiagnosticsApplier.scheduleRefresh, which captures the document's modification
stamp, collects highlights off-thread, and on the UI thread SKIPS the apply when the
stamp has moved in between (applyHighlights: if (data.document.getModificationStamp() != data.modificationStamp) return;). Nothing reschedules after that skip.

OpenedDocument.updateDiagnostics only calls scheduleRefresh when
LSPDiagnosticsForServer.update(...) reports the set CHANGED
(LSPDiagnosticUtils.isDiagnosticsChanged), and DocumentContentSynchronizer never
re-applies on documentChanged.

Combined: one publish that lands while the document is still being edited is dropped,
and every following publish carrying the SAME set is treated as "unchanged" and never
re-applied. The editor keeps showing the LAST successfully applied set — which can be
an error from several edits ago — until the server's answer differs again.

Reproduction

Any server that re-validates on every didChange and offers InsertTextFormat.Snippet
completions will do. Take a configuration-style language where a property is written
as name value and a value can be a block:

  1. Type a property name with no value yet, e.g. server — the server reports
    "expected a value after property name 'server'" at the end of the line. LSP4IJ
    applies it; the squiggle shows.
  2. Accept a snippet completion that inserts a multi-line block with two tab stops, e.g.
    {\n host "$1"\n port $2\n}. LSP4IJ applies the edit and starts the inline
    template; the insertion plus per-line re-indent are several document changes in a
    row.
  3. The server publishes a new error for the half-filled block ("expected a value for
    'port'"). scheduleRefresh runs while the template is still churning the document
    → modification-stamp mismatch → apply dropped. The step-1 squiggle stays.
  4. Type into $1. Every keystroke republishes the identical "expected a value for
    'port'" → isDiagnosticsChanged is false → no refresh. The screen still shows the
    step-1 error, on a line that is now valid.
  5. Fill $2 so the document is clean. The [] publish can be dropped the same way
    (the template's own edits on finishing land in the window); afterwards every []
    is "unchanged". The step-1 error is now permanent.
  6. Type an unrelated broken line elsewhere: a NEW diagnostic arrives → "changed" →
    refresh applies → the stale one finally disappears.

With the server's LSP trace at verbose, textDocument/didChange and
textDocument/publishDiagnostics both flow correctly throughout; the server's last
payload is [] while the editor keeps showing the step-1 error. A single-line snippet
with one tab stop rarely triggers it — fewer document changes in the window — which is
why it looks like a property of "bigger" completions.

Expected

A publish that could not be applied must not be lost. The stored diagnostics
(LSPDiagnosticsForServer) are already the newest; only the RENDER is stale.

Suggested fix (either is enough)

  • In LSPDiagnosticsApplier.applyHighlights, on a modification-stamp mismatch,
    re-run scheduleRefresh(file, psiFile, document) instead of returning (the collector
    re-maps ranges against the current document; the coalesceBy already dedups, and each
    retry captures the current stamp, so it settles as soon as the document does).
  • Or track "last apply dropped" per document and have OpenedDocument.updateDiagnostics
    call scheduleRefresh when that flag is set even if update(...) returned false.

Pre-fa5764c the external annotator re-ran with the daemon on every document change, so
a missed frame healed on the next keystroke; the reactive path has no such retry.

Activity

  1. added a commit that references this issue on Sep 14, 2026
    08f48c4
  2. added
    bug
    on Sep 14, 2026
  3. added this to the 0.21.1 milestone on Sep 14, 2026
  4. self-assigned this
    on Sep 14, 2026
  5. added a commit that references this issue on Sep 14, 2026
    c7b4c1b
  6. angelozerr commented on Sep 14, 2026

    @angelozerr
    Contributor

    @bamboo I created the PR #1666

    Could you please try it by foolowing instruction at https://github.com/redhat-developer/lsp4ij#testing-the-ci-builds and give me feedback.

    Thanks!

  7. bamboo commented on Sep 14, 2026

    @bamboo
    ContributorAuthor

    That's great, @angelozerr. I just tried it and I can confirm the fix works.

    Thanks for the quick fix!

  8. angelozerr commented on Sep 14, 2026

    @angelozerr
    Contributor

    Thanks @bamboo for your review!

    I have started a nighty build https://github.com/redhat-developer/lsp4ij/actions/runs/34849726147 which will be available soon.

    And if you like LSP4IJ please add a review in JetBrains marketplace to help us to promote LSP4IJ. Thanks!

  9. added a commit that references this issue on Sep 14, 2026
    80b94d8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugdiagnostic

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions