Skip to content

fix: clear diagnostics when a document is closed - #152

Merged
jdesrosiers merged 6 commits into
hyperjump-io:mainfrom
tarunagnihotri534:fix/clear-diagnostics-on-close
Oct 13, 2026
Merged

jdesrosiers merged 6 commits into
hyperjump-io:mainfrom
tarunagnihotri534:fix/clear-diagnostics-on-close

Conversation

@tarunagnihotri534

@tarunagnihotri534 tarunagnihotri534 commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #150

What this fixes

When a document with syntax or schema errors was closed (textDocument/didClose), the server never published an empty diagnostics list ({ uri, diagnostics: [] }). Stale diagnostics could stay in the editor's Problems panel after the file was closed.

Changes

  • Handle document close: Diagnostics now subscribes to jsonDocuments.onDidClose. On close, it aborts any pending send for that document, removes its entry from pendingSends, and publishes { uri, diagnostics: [] }.
  • Prevent stale in-flight sends: sendDiagnostics is guarded so a validation that finishes after the document is closed doesn't publish diagnostics. It also skips starting validation for documents that are no longer open in jsonDocuments.
  • Tests: added src/features/diagnostics/Diagnostics.test.ts, covering:
    • closing a document with errors publishes an empty diagnostics list
    • an in-flight validation cancelled by a close doesn't publish stale diagnostics afterwards
    • closing a document with no errors, or with no pending send, doesn't throw
    • closing and then reopening a document publishes fresh diagnostics

Testing

  • New tests pass.
  • Full suite, typecheck (tsc --noEmit) and lint (oxlint src) pass.

Notes

@jdesrosiers

Copy link
Copy Markdown
Collaborator

Next time, please wait to be assigned before submitting PRs.

@jdesrosiers
jdesrosiers force-pushed the fix/clear-diagnostics-on-close branch from 3644c52 to 536081b Compare October 13, 2026 18:53

@jdesrosiers jdesrosiers left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made an improvement to the TestClient so we don't have to do the 200ms wait. I also made a couple fixes for some edge cases.

jdesrosiers and others added 5 commits October 13, 2026 11:58
The connection keeps only one handler per notification, so registering a
PublishDiagnostics handler in a test silently replaced getDiagnostics' handler.
TestClient now owns the single handler and fans out to listeners, and
onDiagnostics lets tests observe every publish for a URI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Checking only the URI let a run for a closed document through if the URI
had been reopened, cancelling the new document's validation and publishing
diagnostics for the old content.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A throwing provider left its entry in pendingSends and escaped the handler
as an unhandled rejection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Hold the schema read so the validation is guaranteed to be in flight when the
document closes, then assert the exact sequence of publishes instead of
sleeping and checking only the last one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jdesrosiers
jdesrosiers force-pushed the fix/clear-diagnostics-on-close branch from 536081b to 5c2319e Compare October 13, 2026 18:59
@jdesrosiers
jdesrosiers merged commit 1c10688 into hyperjump-io:main Oct 13, 2026
3 checks passed
@tarunagnihotri534

Copy link
Copy Markdown
Contributor Author

thankyou for merging @jdesrosiers, i got your points

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]:Diagnostics aren't cleared when a document is closed

2 participants