Skip to content

Conversation

@AndyBodnar
Copy link

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.
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.

Deleting files with vscode fs api can cause contributed custom text editors to not be able to open subsequent files with the same name

2 participants