no more implicit path magic for UriIterator, https://github.com/microsoft/vscode/issues/107886

This commit is contained in:
Johannes Rieken
2020-10-02 09:40:55 +02:00
parent 70a31b6a02
commit b228267d50
2 changed files with 12 additions and 15 deletions

View File

@@ -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<K, V>(map: Map<K, V>, key: K, value: V): V {
let result = map.get(key);
@@ -140,6 +138,8 @@ export class UriIterator implements IKeyIterator<URI> {
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<URI> {
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<URI> {
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<K, V> {
export class TernarySearchTree<K, V> {
static forUris<E>(): TernarySearchTree<URI, E> {
return new TernarySearchTree<URI, E>(new UriIterator());
static forUris<E>(ignorePathCasing: boolean = false): TernarySearchTree<URI, E> {
return new TernarySearchTree<URI, E>(new UriIterator(ignorePathCasing));
}
static forPaths<E>(): TernarySearchTree<string, E> {

View File

@@ -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<URI, number>(new UriIterator());
let trie = new TernarySearchTree<URI, number>(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<URI, number>(new UriIterator());
const map = new TernarySearchTree<URI, number>(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<URI, number>(new UriIterator());
const map = new TernarySearchTree<URI, number>(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);