Repository navigation
Fix custom editor not resolving for CLI-opened files at startup (#197374) - #312551
Draft
Mukunda Rao Katta (MukundaKatta) wants to merge 1 commit into
Draft
Mukunda Rao Katta (MukundaKatta) wants to merge 1 commit into
Mukunda Rao Katta (MukundaKatta) wants to merge 1 commit into
Conversation
When opening a file via CLI before any VS Code instance is running and the user has a `workbench.editorAssociations` mapping pointing to a custom editor (e.g. `"*.md": "vscode.markdown.preview.editor"`), the file would open in the default text editor instead of the custom one. `EditorResolverService.resolveEditor` snapshots the flattened editor map at the top of the call, then awaits `whenInstalledExtensionsRegistered` when the user has a non-default editor association for the resource. During that await, extensions register their custom editor contributions through the `customEditors` extension point, which mutates `_editors` and sets `_shouldReFlattenEditors`. Because the snapshot was taken before the await, subsequent lookups (`getEditor`, `findMatchingEditors`, `getAssociationsForResource`) iterated a stale map without the freshly-registered custom editor, so the resolver fell back to the default text editor. Re-flatten after the await so the new contributions are visible. Adds a regression test that registers a custom editor while the `whenInstalledExtensionsRegistered` promise is still pending and verifies the user-configured association is honored. Fixes microsoft#197374
|
This line is needed, but on a cold start it isn't enough on its own: Investigated and written in collaboration with Claudia in Claude Code. |
This branch has not been deployed
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.
Summary
Fixes #197374.
workbench.editorAssociations(e.g."*.md": "vscode.markdown.preview.editor") is not honored when a file is opened via CLI and no VS Code instance is running.Root cause
EditorResolverService.resolveEditor(src/vs/workbench/services/editor/browser/editorResolverService.ts:97-130) snapshots the flattened editor map at line 99 (this._flattenedEditors = this._flattenEditorsMap()) before awaitingwhenInstalledExtensionsRegistered(). During that await, extensions register their custom editor contributions through thecustomEditorsextension point, mutating_editorsand setting_shouldReFlattenEditors = true. Subsequent lookups (getEditor,findMatchingEditors,getAssociationsForResource) keep iterating the stale snapshot, so the freshly-registeredvscode.markdown.preview.editoris invisible and the resolver falls back to the default text editor.PR #244597 (merged Apr 2026) added the await for user-configured associations but did not re-flatten afterwards.
Fix
Re-flatten after the await. One-line addition + comment.
Files
src/vs/workbench/services/editor/browser/editorResolverService.ts(+6)src/vs/workbench/services/editor/test/browser/editorResolverService.test.ts(+83) — regression test using a controllableIExtensionServicewhosewhenInstalledExtensionsRegisteredonly resolves after a custom editor registers mid-await.Test plan
tsgo --project ./src/tsconfig.json --noEmit --skipLibCheckclean.