diff --git a/src/vs/base/common/map.ts b/src/vs/base/common/map.ts index 76a9129d26b..830aa8c4a3e 100644 --- a/src/vs/base/common/map.ts +++ b/src/vs/base/common/map.ts @@ -5,9 +5,7 @@ import { URI } from 'vs/base/common/uri'; import { CharCode } from 'vs/base/common/charCode'; -import { compareSubstringIgnoreCase, compare, compareSubstring } from 'vs/base/common/strings'; -import { Schemas } from 'vs/base/common/network'; -import { isLinux } from 'vs/base/common/platform'; +import { compareSubstringIgnoreCase, compare, compareSubstring, compareIgnoreCase } from 'vs/base/common/strings'; export function getOrSet(map: Map, key: K, value: V): V { let result = map.get(key); @@ -140,6 +138,8 @@ export class UriIterator implements IKeyIterator { private _states: UriIteratorState[] = []; private _stateIdx: number = 0; + constructor(private readonly _ignorePathCasing: boolean) { } + reset(key: URI): this { this._value = key; this._states = []; @@ -150,10 +150,7 @@ export class UriIterator implements IKeyIterator { this._states.push(UriIteratorState.Authority); } if (this._value.path) { - //todo@jrieken #107886 the case-sensitive logic is copied form `resources.ts#hasToIgnoreCase` - // which cannot be used because it depends on this - const caseSensitive = key.scheme === Schemas.file && isLinux; - this._pathIterator = new PathIterator(false, caseSensitive); + this._pathIterator = new PathIterator(false, !this._ignorePathCasing); this._pathIterator.reset(key.path); if (this._pathIterator.value()) { this._states.push(UriIteratorState.Path); @@ -185,9 +182,9 @@ export class UriIterator implements IKeyIterator { cmp(a: string): number { if (this._states[this._stateIdx] === UriIteratorState.Scheme) { - return compare(a, this._value.scheme); + return compareIgnoreCase(a, this._value.scheme); } else if (this._states[this._stateIdx] === UriIteratorState.Authority) { - return compareSubstringIgnoreCase(a, this._value.authority); + return compareIgnoreCase(a, this._value.authority); } else if (this._states[this._stateIdx] === UriIteratorState.Path) { return this._pathIterator.cmp(a); } else if (this._states[this._stateIdx] === UriIteratorState.Query) { @@ -229,8 +226,8 @@ class TernarySearchTreeNode { export class TernarySearchTree { - static forUris(): TernarySearchTree { - return new TernarySearchTree(new UriIterator()); + static forUris(ignorePathCasing: boolean = false): TernarySearchTree { + return new TernarySearchTree(new UriIterator(ignorePathCasing)); } static forPaths(): TernarySearchTree { diff --git a/src/vs/base/test/common/map.test.ts b/src/vs/base/test/common/map.test.ts index 47af3ca64a9..719335c39c6 100644 --- a/src/vs/base/test/common/map.test.ts +++ b/src/vs/base/test/common/map.test.ts @@ -368,7 +368,7 @@ suite('Map', () => { }); test('URIIterator', function () { - const iter = new UriIterator(); + const iter = new UriIterator(false); iter.reset(URI.parse('file:///usr/bin/file.txt')); assert.equal(iter.value(), 'file'); @@ -609,7 +609,7 @@ suite('Map', () => { test('TernarySearchTree (URI) - basics', function () { - let trie = new TernarySearchTree(new UriIterator()); + let trie = new TernarySearchTree(new UriIterator(false)); trie.set(URI.file('/user/foo/bar'), 1); trie.set(URI.file('/user/foo'), 2); @@ -629,7 +629,7 @@ suite('Map', () => { test('TernarySearchTree (URI) - lookup', function () { - const map = new TernarySearchTree(new UriIterator()); + const map = new TernarySearchTree(new UriIterator(false)); map.set(URI.parse('http://foo.bar/user/foo/bar'), 1); map.set(URI.parse('http://foo.bar/user/foo?query'), 2); map.set(URI.parse('http://foo.bar/user/foo?QUERY'), 3); @@ -646,7 +646,7 @@ suite('Map', () => { test('TernarySearchTree (PathSegments) - superstr', function () { - const map = new TernarySearchTree(new UriIterator()); + const map = new TernarySearchTree(new UriIterator(false)); map.set(URI.file('/user/foo/bar'), 1); map.set(URI.file('/user/foo'), 2); map.set(URI.file('/user/foo/flip/flop'), 3);