Repository navigation
map: preserve custom toKey and re-key on ResourceMap copy - #347344
Merged
Dmitriy Vasyura (dmitrivMS) merged 3 commits intoNov 13, 2026
Merged
Dmitriy Vasyura (dmitrivMS) merged 3 commits into
Dmitriy Vasyura (dmitrivMS) merged 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the changes to comparator handling in ResourceMap copies.
No open issues 🎉
What changed in this PR
Fixes #347343 by making ResourceMap copies preserve custom key comparison behavior and rebuild stored keys when a different comparator is supplied.
Changes:
- Inherit the source map’s
toKeyfunction when no override is provided. - Re-key entries when the comparator changes, retaining the shallow-clone fast path otherwise.
- Add regression tests for case-insensitive lookups, updates, deletion, collision handling, and source-map isolation.
| File | Description |
|---|---|
src/vs/base/test/common/map.test.ts |
Adds tests for inherited and overridden copy comparators. |
src/vs/base/common/map.ts |
Preserves the source comparator or re-keys entries using the override. |
Review effort: Balanced
Dmitriy Vasyura (dmitrivMS)
requested changes
Nov 11, 2026
Dmitriy Vasyura (dmitrivMS)
left a comment
Collaborator
There was a problem hiding this comment.
See my question in the issue.
Refactor assertions to use structured objects for testing ResourceMap behavior after copying, setting, and deleting entries. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Dmitriy Vasyura (dmitrivMS)
enabled auto-merge (squash)
November 13, 2026 03:57
Dmitriy Vasyura (dmitrivMS)
approved these changes
Nov 13, 2026
Bhavya U (bhavyaus)
approved these changes
Nov 13, 2026
Christof Marti (chrmarti)
approved these changes
Nov 13, 2026
Dmitriy Vasyura (dmitrivMS)
merged commit Nov 13, 2026
d5e53d8
into
microsoft:main
52 of 53 checks passed
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.

Fixes #347343
Summary of Changes
In
ResourceMap(src/vs/base/common/map.ts), the copy constructor (new ResourceMap(arg)) cloned the internal map (new Map(arg.map)) but defaultedthis.toKeytoResourceMap.defaultToKeyrather than inheritingarg.toKey.When
argwas initialized with a custom key comparison function (e.g.extUriIgnorePathCase.getComparisonKey):this.mapwere hashed according toarg.toKey.copy.has(uri)andcopy.get(uri)calls hashed viadefaultToKey, failing to match the internal keys.copy.set(uri, val)inserted duplicate entries underdefaultToKey.toKey(new ResourceMap(arg, newToKey)) failed to re-key existing entries.Changes:
toKey: WhentoKeyis not passed,this.toKeydefaults toarg.toKey.this.toKey !== arg.toKey, entries are re-keyed viathis.set(entry.uri, entry.value). Ifthis.toKey === arg.toKey, it maintains the fastnew Map(arg.map)shallow clone.src/vs/base/test/common/map.test.tsverifying:ResourceMap - clone preserves custom toKeyResourceMap - clone with new toKey re-keys entries