fix(project): re-read cached file contents on didChangeWatchedFiles Created event - #64205
Open
erantianantha wants to merge 1 commit into
Open
Conversation
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.
Contributor
There was a problem hiding this comment.
🟡 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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #64195
Summary
When
workspace/didChangeWatchedFilesreports aCreated(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.markDirtyFilespreviously only inspectedchange.Changed. Consequently,s.diskFilesretained the stale cached file content and hash, causing stale diagnostics to persist indefinitely until server restart or explicitdidOpen.Changes
snapshotFSBuilder.markDirtyFiles: Processchange.Createdin addition tochange.Changed. If a created file path was already cached ins.diskFiles, reload its entry from disk viareloadEntryIfContentChangedso that updated contents and hash are reflected in the snapshot.snapshotFSBuilder.watchChangesOverlapCache: Includechange.Createdin cache overlap checks for excessive watch events.SnapshotFS.expandRealpathAliases: Expandnode_modulessymlink aliases forchange.Createdevents as well.overlayFS.processChanges: RecomputematchesDiskTextfor open overlays when aWatchCreateevent occurs.