Skip to content

fix: clear stale custom editor model entry on rejection#304815

Open
yogeshwaran-c wants to merge 2 commits intomicrosoft:mainfrom
yogeshwaran-c:fix/custom-editor-stale-error-model
Open

fix: clear stale custom editor model entry on rejection#304815
yogeshwaran-c wants to merge 2 commits intomicrosoft:mainfrom
yogeshwaran-c:fix/custom-editor-stale-error-model

Conversation

@yogeshwaran-c
Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

When a custom text editor fails to open because the backing file doesn't exist (e.g., the file URI is passed to vscode.open before the file is created), the model promise is stored in CustomEditorModelManager._references in a rejected state. On subsequent attempts to reopen the same custom editor (even after the file is created), tryRetain() returns the same rejected promise, causing the editor to perpetually show "The editor could not be opened because the file was not found." — even clicking "Try Again" doesn't help.

Closes #268301

What is the new behavior?

When a model promise rejects, the entry is automatically removed from the references map via a .catch() handler. This allows the next attempt to open the custom editor to create a fresh model, which will succeed if the file now exists.

Additional context

The fix adds a .catch() handler in the add() method that cleans up the rejected entry from _references. This is safe because:

  • The .catch() only fires on rejection, so successful models are unaffected
  • If the entry was already removed by disposeAllModelsForView or the tryRetain dispose callback, Map.delete is a no-op
  • The counter-based reference tracking in tryRetain will naturally decrement when callers handle the rejection

When removing manual folding ranges with an empty selection (cursor
only), find and remove only the innermost manual folding range
containing the cursor, rather than all manual ranges that intersect
with the cursor line. This allows users to precisely remove a specific
manual range without losing outer manual ranges in a nested hierarchy.

For non-empty selections, the existing behavior of removing all manual
ranges intersecting the selection is preserved.

Closes microsoft#212599
When a custom editor model promise rejects (e.g., because the file
was not found), the rejected promise remains cached in the model
manager's reference map. On subsequent attempts to open the same
custom editor, tryRetain returns the same rejected promise, causing
the editor to always show the original error even if the underlying
file now exists.

Fix by attaching a catch handler that removes the entry from the
references map when the model promise rejects. This allows the next
open attempt to create a fresh model.

Fixes microsoft#268301
@vs-code-engineering vs-code-engineering Bot added this to the 1.114.0 milestone Mar 25, 2026
@mjbvz mjbvz modified the milestones: 1.114.0, On Deck Mar 26, 2026
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.

Custom editor retains previous error on reopen even when it no longer applies

2 participants