customEditor: fix stale cache after file deletion #287966
Open
+21
−0
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.
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