diff --git a/src/vs/base/common/map.ts b/src/vs/base/common/map.ts index 132b8f79e65..b45efcf3784 100644 --- a/src/vs/base/common/map.ts +++ b/src/vs/base/common/map.ts @@ -741,13 +741,17 @@ interface ResourceMapKeyFn { (resource: URI): string; } +class ResourceMapEntry { + constructor(readonly uri: URI, readonly value: T) { } +} + export class ResourceMap implements Map { private static readonly defaultToKey = (resource: URI) => resource.toString(); readonly [Symbol.toStringTag] = 'ResourceMap'; - private readonly map: Map; + private readonly map: Map>; private readonly toKey: ResourceMapKeyFn; /** @@ -774,12 +778,12 @@ export class ResourceMap implements Map { } set(resource: URI, value: T): this { - this.map.set(this.toKey(resource), value); + this.map.set(this.toKey(resource), new ResourceMapEntry(resource, value)); return this; } get(resource: URI): T | undefined { - return this.map.get(this.toKey(resource)); + return this.map.get(this.toKey(resource))?.value; } has(resource: URI): boolean { @@ -802,30 +806,32 @@ export class ResourceMap implements Map { if (typeof thisArg !== 'undefined') { clb = clb.bind(thisArg); } - for (let [index, value] of this.map) { - clb(value, URI.parse(index), this); + for (let [_, entry] of this.map) { + clb(entry.value, entry.uri, this); } } - values(): IterableIterator { - return this.map.values(); + *values(): IterableIterator { + for (let entry of this.map.values()) { + yield entry.value; + } } *keys(): IterableIterator { - for (let key of this.map.keys()) { - yield URI.parse(key); + for (let entry of this.map.values()) { + yield entry.uri; } } *entries(): IterableIterator<[URI, T]> { - for (let tuple of this.map.entries()) { - yield [URI.parse(tuple[0]), tuple[1]]; + for (let entry of this.map.values()) { + yield [entry.uri, entry.value]; } } *[Symbol.iterator](): IterableIterator<[URI, T]> { - for (let item of this.map) { - yield [URI.parse(item[0]), item[1]]; + for (let [, entry] of this.map) { + yield [entry.uri, entry.value]; } } } diff --git a/src/vs/base/test/common/map.test.ts b/src/vs/base/test/common/map.test.ts index fc0f1fc0034..633749fba96 100644 --- a/src/vs/base/test/common/map.test.ts +++ b/src/vs/base/test/common/map.test.ts @@ -1189,6 +1189,25 @@ suite('Map', () => { assert.strictEqual(map.get(windowsFile), 'true'); assert.strictEqual(map.get(uncFile), 'true'); }); + + test('ResourceMap - files (ignorecase, BUT preservecase)', function () { + const map = new ResourceMap(uri => extUriIgnorePathCase.getComparisonKey(uri)); + + const fileA = URI.parse('file://some/filea'); + const fileAUpper = URI.parse('file://SOME/FILEA'); + + map.set(fileA, 1); + assert.strictEqual(map.get(fileA), 1); + assert.strictEqual(map.get(fileAUpper), 1); + assert.deepStrictEqual(Array.from(map.keys()).map(String), [fileA].map(String)); + assert.deepStrictEqual(Array.from(map), [[fileA, 1]]); + + map.set(fileAUpper, 1); + assert.strictEqual(map.get(fileA), 1); + assert.strictEqual(map.get(fileAUpper), 1); + assert.deepStrictEqual(Array.from(map.keys()).map(String), [fileAUpper].map(String)); + assert.deepStrictEqual(Array.from(map), [[fileAUpper, 1]]); + }); }); diff --git a/src/vs/workbench/api/common/extHostDiagnostics.ts b/src/vs/workbench/api/common/extHostDiagnostics.ts index 00038bd692d..bacfe4bdd80 100644 --- a/src/vs/workbench/api/common/extHostDiagnostics.ts +++ b/src/vs/workbench/api/common/extHostDiagnostics.ts @@ -16,13 +16,12 @@ import { ResourceMap } from 'vs/base/common/map'; import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions'; import { IExtHostFileSystemInfo } from 'vs/workbench/api/common/extHostFileSystemInfo'; import { IExtUri } from 'vs/base/common/resources'; -import { SkipList } from 'vs/base/common/skipList'; export class DiagnosticCollection implements vscode.DiagnosticCollection { readonly #proxy: MainThreadDiagnosticsShape | undefined; readonly #onDidChangeDiagnostics: Emitter; - readonly #data: SkipList; + readonly #data: ResourceMap; private _isDisposed = false; @@ -34,7 +33,7 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection { proxy: MainThreadDiagnosticsShape | undefined, onDidChangeDiagnostics: Emitter ) { - this.#data = new SkipList((a, b) => extUri.compare(a, b)); + this.#data = new ResourceMap(uri => extUri.getComparisonKey(uri)); this.#proxy = proxy; this.#onDidChangeDiagnostics = onDidChangeDiagnostics; }