Skip to content

fix(project): re-read cached file contents on didChangeWatchedFiles Created event - #64205

Open
erantianantha wants to merge 1 commit into
microsoft:mainfrom
erantianantha:fix/watched-files-created-stale-content
Open

fix(project): re-read cached file contents on didChangeWatchedFiles Created event#64205
erantianantha wants to merge 1 commit into
microsoft:mainfrom
erantianantha:fix/watched-files-created-stale-content

Conversation

@erantianantha

Copy link
Copy Markdown
Contributor

Fixes #64195

Summary

When workspace/didChangeWatchedFiles reports a Created (type 1) event for a file that is already loaded in the program (for example, during an atomic save where an editor writes to a temporary file and renames it over the target), snapshotFSBuilder.markDirtyFiles previously only inspected change.Changed. Consequently, s.diskFiles retained the stale cached file content and hash, causing stale diagnostics to persist indefinitely until server restart or explicit didOpen.

Changes

  1. snapshotFSBuilder.markDirtyFiles: Process change.Created in addition to change.Changed. If a created file path was already cached in s.diskFiles, reload its entry from disk via reloadEntryIfContentChanged so that updated contents and hash are reflected in the snapshot.
  2. snapshotFSBuilder.watchChangesOverlapCache: Include change.Created in cache overlap checks for excessive watch events.
  3. SnapshotFS.expandRealpathAliases: Expand node_modules symlink aliases for change.Created events as well.
  4. overlayFS.processChanges: Recompute matchesDiskText for open overlays when a WatchCreate event occurs.
  5. Added unit tests for atomic saves / create events on closed files and cached snapshot entries.

When didChangeWatchedFiles reports a Created event (such as on atomic saves via rename), existing cached entries in diskFiles were not checked or reloaded, leading to stale program contents and diagnostics. Update markDirtyFiles, watchChangesOverlapCache, and expandRealpathAliases to handle Created events for cached files.
Copilot AI balanced review requested due to automatic review settings September 8, 2026 21:54
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Sep 8, 2026
@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Sep 8, 2026

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.

🟡 Changes recommended

The unresolved save→create ordering issue can leave open overlays incorrectly marked as matching disk.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Fixes stale snapshots and diagnostics when atomic saves emit Created file-watcher events.

Changes:

  • Reloads cached files for create events.
  • Extends symlink alias and overlay handling.
  • Adds snapshot, session, and overlay regression tests.

A moderate issue remains: a queued didSave can suppress later create handling, leaving stale overlay state. The save→create batch case must be handled and tested.

File summaries
File Description
tsc/internal/project/snapshotfs.go Handles created events in snapshot caches and aliases.
tsc/internal/project/snapshotfs_test.go Tests cached-file reload behavior.
tsc/internal/project/session_test.go Tests atomic-save scenarios end to end.
tsc/internal/project/overlayfs.go Updates overlay disk-match state on creation.
tsc/internal/project/overlayfs_test.go Tests overlay handling for create events.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

}
if events.watchChanged && o == nil {
result.Changed.Add(uri)
} else if (events.watchChanged || events.created) && o != nil && !events.saved {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

LSP: file contents are not re-read when didChangeWatchedFiles reports Created (type 1) for a file already in the program

2 participants