Skip to content

Invalidate cached TS responses after document reopen - #347028

Merged
Dirk Bäumer (dbaeumer) merged 1 commit into
microsoft:mainfrom
sameerihs:invalidate-reopened-document-cache
Nov 10, 2026
Merged

Dirk Bäumer (dbaeumer) merged 1 commit into
microsoft:mainfrom
sameerihs:invalidate-reopened-document-cache

Conversation

@sameerihs

Copy link
Copy Markdown
Contributor

Fixes #347026

A reopened document can have the same URI and version as an earlier document while containing different text. Match cached TypeScript responses by weak document identity and version so old navigation-tree results cannot satisfy the reopened document's request. Same-document cache hits remain, without strongly retaining closed documents.

A cache regression and a real-extension vscode.executeDocumentSymbolProvider regression fail before the fix. The selected suite passes 15 tests with one existing skip; extension compilation, web typechecking and targeted ESLint pass.

An independent comparison with installed 1.145.2 uses its packaged TypeScript extension and observes actual document closure and a distinct reopened version-1 document. Stable returns original while the public editor text contains updated; patched main returns updated. Neither run deletes/recreates the file.

Copilot AI balanced review requested due to automatic review settings November 9, 2026 16:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block the fix for stale TypeScript cache results when documents are reopened.

No open issues 🎉

What changed in this PR

Fixes #347026 by preventing the TypeScript response cache from reusing stale results when a document is closed and reopened with the same URI and version but different content.

Changes:

  • Matches cached responses by weak document identity and version, preserving same-document cache hits without strongly retaining closed documents.
  • Adds cache-level and document-symbol regressions covering document closure, external edits, and reopening.
File Description
extensions/​typescript-language-features/​src/​tsServer/​cachedResponse.ts Replaces URI matching with weak document identity matching.
extensions/​typescript-language-features/​src/​test/​unit/​cachedResponse.test.ts Tests cache invalidation when a document is reopened.
extensions/​typescript-language-features/​src/​test/​smoke/​documentSymbol.test.ts Tests that document symbols reflect external edits after reopening.

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the fix addressing stale TypeScript document symbols after externally edited files are reopened.

No open issues 🎉

Review effort: Balanced

@dbaeumer
Dirk Bäumer (dbaeumer) merged commit 19b7e37 into microsoft:main Nov 10, 2026
52 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.147.0 milestone Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants