Skip to content

map: preserve custom toKey and re-key on ResourceMap copy - #347344

Merged
Dmitriy Vasyura (dmitrivMS) merged 3 commits into
microsoft:mainfrom
ShakilUrRehman21:fix/resourcemap-copy-tokey
Nov 13, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 3 commits into
microsoft:mainfrom
ShakilUrRehman21:fix/resourcemap-copy-tokey

Conversation

@ShakilUrRehman21

Copy link
Copy Markdown
Contributor

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 defaulted this.toKey to ResourceMap.defaultToKey rather than inheriting arg.toKey.

When arg was initialized with a custom key comparison function (e.g. extUriIgnorePathCase.getComparisonKey):

  • All copied keys in this.map were hashed according to arg.toKey.
  • Subsequent copy.has(uri) and copy.get(uri) calls hashed via defaultToKey, failing to match the internal keys.
  • Calling copy.set(uri, val) inserted duplicate entries under defaultToKey.
  • Providing an explicit new toKey (new ResourceMap(arg, newToKey)) failed to re-key existing entries.

Changes:

  1. Preserve toKey: When toKey is not passed, this.toKey defaults to arg.toKey.
  2. Re-key when comparator changes: If this.toKey !== arg.toKey, entries are re-keyed via this.set(entry.uri, entry.value). If this.toKey === arg.toKey, it maintains the fast new Map(arg.map) shallow clone.
  3. Tests: Added unit tests in src/vs/base/test/common/map.test.ts verifying:
    • ResourceMap - clone preserves custom toKey
    • ResourceMap - clone with new toKey re-keys entries
Copilot AI balanced review requested due to automatic review settings November 10, 2026 13:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 toKey function 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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my question in the issue.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

An unresolved test-style nit flags repetitive map-test assertions that are harder to read and maintain than the repository-recommended snapshot-style comparisons.

1 open issue

Review effort: Max

Comment thread src/vs/base/test/common/map.test.ts Resolved
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>
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit d5e53d8 into microsoft:main Nov 13, 2026
52 of 53 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.147.0 milestone Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

7 participants