Skip to content

customEditor: fix stale cache after file deletion - #287966

Merged
Matt Bierner (mjbvz) merged 3 commits into
microsoft:mainfrom
AndyBodnar:fix/custom-editor-file-delete-278883
Jul 27, 2026
Merged

Matt Bierner (mjbvz) merged 3 commits into
microsoft:mainfrom
AndyBodnar:fix/custom-editor-file-delete-278883

Conversation

@AndyBodnar

Copy link
Copy Markdown
Contributor

Ran into a weird bug where after deleting a file that was open in a custom editor (using the fs API), I couldn't open a new file with the same name - kept getting "file not found" even though the file existed.

Turns out the custom editor model manager wasn't cleaning up its cache when files got deleted. So when you create a new file with the same name, it would find the old cached model reference pointing to a resource that no longer exists.

The fix hooks into the existing file operation handler (which already handles moves) and adds a delete case that disposes all models associated with the deleted resource. Pretty straightforward and follows the same pattern as the existing move handling.

I tested this using the repro from the issue (https://github.com/Greglar4/vscodeBugExampleRepository) and it works - delete a file, recreate it with the same name, and the custom editor opens it correctly now.

Fixes #278883

When files are deleted via the VS Code fs API, the custom editor model
manager was not cleaning up its cached references. This caused issues
where recreating a file with the same name would result in "file not
found" errors in the custom editor, even though the file exists.

The fix adds a handler for FileOperation.DELETE in CustomEditorService
that disposes all models associated with the deleted resource, ensuring
the cache is properly invalidated.
@mjbvz

Copy link
Copy Markdown
Contributor

Thanks! General approach lgtm

@mjbvz Matt Bierner (mjbvz) added this to the 1.114.0 milestone Mar 27, 2026
@alexr00 Alex Ross (alexr00) removed this from the 1.114.0 milestone Mar 30, 2026
Copilot AI review requested due to automatic review settings July 27, 2026 21:55

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.

Pull request overview

Fixes stale custom-editor models after resource deletion.

Changes:

  • Evicts models when files are deleted.
  • Adds resource-based model disposal to the manager API.
Show a summary per file
File Description
customEditors.ts Handles delete operations.
customEditor.ts Extends the model-manager interface.
customEditorModelManager.ts Removes models for deleted resources.

Review details

  • Files reviewed: 3/3 changed files
  • Comments generated: 3
  • Review effort level: Medium
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

8 participants