Refresh master with initial release/0.24 snapshot (#332)

* Initial port of release/0.24 source code

* Fix additional headers

* Fix a typo in launch.json
This commit is contained in:
Karl Burtram
2017-12-15 15:38:57 -08:00
committed by GitHub
parent 271b3a0b82
commit 6ad0df0e3e
7118 changed files with 107999 additions and 56466 deletions

View File

@@ -4,8 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import scorer = require('vs/base/common/scorer');
import strings = require('vs/base/common/strings');
import * as strings from 'vs/base/common/strings';
import * as paths from 'vs/base/common/paths';
let intlFileNameCollator: Intl.Collator;
@@ -37,14 +36,8 @@ export function compareFileNames(one: string, other: string): number {
const FileNameMatch = /^(.*?)(\.([^.]*))?$/;
export function noIntlCompareFileNames(one: string, other: string): number {
let oneMatch = FileNameMatch.exec(one.toLowerCase());
let otherMatch = FileNameMatch.exec(other.toLowerCase());
let oneName = oneMatch[1] || '';
let oneExtension = oneMatch[3] || '';
let otherName = otherMatch[1] || '';
let otherExtension = otherMatch[3] || '';
const [oneName, oneExtension] = extractNameAndExtension(one, true);
const [otherName, otherExtension] = extractNameAndExtension(other, true);
if (oneName !== otherName) {
return oneName < otherName ? -1 : 1;
@@ -59,14 +52,8 @@ export function noIntlCompareFileNames(one: string, other: string): number {
export function compareFileExtensions(one: string, other: string): number {
if (intlFileNameCollator) {
const oneMatch = one ? FileNameMatch.exec(one) : [];
const otherMatch = other ? FileNameMatch.exec(other) : [];
const oneName = oneMatch[1] || '';
const oneExtension = oneMatch[3] || '';
const otherName = otherMatch[1] || '';
const otherExtension = otherMatch[3] || '';
const [oneName, oneExtension] = extractNameAndExtension(one);
const [otherName, otherExtension] = extractNameAndExtension(other);
let result = intlFileNameCollator.compare(oneExtension, otherExtension);
@@ -92,14 +79,8 @@ export function compareFileExtensions(one: string, other: string): number {
}
function noIntlCompareFileExtensions(one: string, other: string): number {
const oneMatch = one ? FileNameMatch.exec(one.toLowerCase()) : [];
const otherMatch = other ? FileNameMatch.exec(other.toLowerCase()) : [];
const oneName = oneMatch[1] || '';
const oneExtension = oneMatch[3] || '';
const otherName = otherMatch[1] || '';
const otherExtension = otherMatch[3] || '';
const [oneName, oneExtension] = extractNameAndExtension(one, true);
const [otherName, otherExtension] = extractNameAndExtension(other, true);
if (oneExtension !== otherExtension) {
return oneExtension < otherExtension ? -1 : 1;
@@ -112,6 +93,12 @@ function noIntlCompareFileExtensions(one: string, other: string): number {
return oneName < otherName ? -1 : 1;
}
function extractNameAndExtension(str?: string, lowercase?: boolean): [string, string] {
const match = str ? FileNameMatch.exec(lowercase ? str.toLowerCase() : str) : [] as RegExpExecArray;
return [(match && match[1]) || '', (match && match[3]) || ''];
}
export function comparePaths(one: string, other: string): number {
const oneParts = one.split(paths.nativeSep);
const otherParts = other.split(paths.nativeSep);
@@ -186,56 +173,4 @@ export function compareByPrefix(one: string, other: string, lookFor: string): nu
}
return 0;
}
export interface IScorableResourceAccessor<T> {
getLabel(t: T): string;
getResourcePath(t: T): string;
}
export function compareByScore<T>(elementA: T, elementB: T, accessor: IScorableResourceAccessor<T>, lookFor: string, lookForNormalizedLower: string, scorerCache?: { [key: string]: number }): number {
const labelA = accessor.getLabel(elementA);
const labelB = accessor.getLabel(elementB);
// treat prefix matches highest in any case
const prefixCompare = compareByPrefix(labelA, labelB, lookFor);
if (prefixCompare) {
return prefixCompare;
}
// Give higher importance to label score
const labelAScore = scorer.score(labelA, lookFor, scorerCache);
const labelBScore = scorer.score(labelB, lookFor, scorerCache);
if (labelAScore !== labelBScore) {
return labelAScore > labelBScore ? -1 : 1;
}
// Score on full resource path comes next (if available)
let resourcePathA = accessor.getResourcePath(elementA);
let resourcePathB = accessor.getResourcePath(elementB);
if (resourcePathA && resourcePathB) {
const resourceAScore = scorer.score(resourcePathA, lookFor, scorerCache);
const resourceBScore = scorer.score(resourcePathB, lookFor, scorerCache);
if (resourceAScore !== resourceBScore) {
return resourceAScore > resourceBScore ? -1 : 1;
}
}
// At this place, the scores are identical so we check for string lengths and favor shorter ones
if (labelA.length !== labelB.length) {
return labelA.length < labelB.length ? -1 : 1;
}
if (resourcePathA && resourcePathB && resourcePathA.length !== resourcePathB.length) {
return resourcePathA.length < resourcePathB.length ? -1 : 1;
}
// Finally compare by label or resource path
if (labelA === labelB && resourcePathA && resourcePathB) {
return compareAnything(resourcePathA, resourcePathB, lookForNormalizedLower);
}
return compareAnything(labelA, labelB, lookForNormalizedLower);
}
}