Merge from vscode 64980ea1f3f532c82bb6c28d27bba9ef2c5b4463 (#7206)

* Merge from vscode 64980ea1f3f532c82bb6c28d27bba9ef2c5b4463

* fix config changes

* fix strictnull checks
This commit is contained in:
Anthony Dresser
2019-09-15 22:38:26 -07:00
committed by GitHub
parent fa6c52699e
commit ea0f9e6ce9
1226 changed files with 21541 additions and 17633 deletions

View File

@@ -8,3 +8,11 @@ import { URI } from 'vs/base/common/uri';
export function getPathFromAmdModule(requirefn: typeof require, relativePath: string): string {
return URI.parse(requirefn.toUrl(relativePath)).fsPath;
}
/**
* Reference a resource that might be inlined.
* Do not rename this method unless you adopt the build scripts.
*/
export function registerAndGetAmdImageURL(absolutePath: string): string {
return require.toUrl(absolutePath);
}

View File

@@ -7,17 +7,14 @@
* An interface for a JavaScript object that
* acts a dictionary. The keys are strings.
*/
export interface IStringDictionary<V> {
[name: string]: V;
}
export type IStringDictionary<V> = Record<string, V>;
/**
* An interface for a JavaScript object that
* acts a dictionary. The keys are numbers.
*/
export interface INumberDictionary<V> {
[idx: number]: V;
}
export type INumberDictionary<V> = Record<number, V>;
const hasOwnProperty = Object.prototype.hasOwnProperty;
@@ -138,4 +135,4 @@ export class SetMap<K, V> {
values.forEach(fn);
}
}
}

View File

@@ -114,9 +114,9 @@ export function log(entry: IRemoteConsoleLog, label: string): void {
// First arg is a string
if (typeof args[0] === 'string') {
if (topFrame && isOneStringArg) {
consoleArgs = [`%c[${label}] %c${args[0]} %c${topFrame}`, color('blue'), color('black'), color('grey')];
consoleArgs = [`%c[${label}] %c${args[0]} %c${topFrame}`, color('blue'), color(''), color('grey')];
} else {
consoleArgs = [`%c[${label}] %c${args[0]}`, color('blue'), color('black'), ...args.slice(1)];
consoleArgs = [`%c[${label}] %c${args[0]}`, color('blue'), color(''), ...args.slice(1)];
}
}
@@ -139,4 +139,4 @@ export function log(entry: IRemoteConsoleLog, label: string): void {
function color(color: string): string {
return `color: ${color}`;
}
}

View File

@@ -455,6 +455,14 @@ function printTable(table: number[][], pattern: string, patternLen: number, word
return ret;
}
function printTables(pattern: string, patternStart: number, word: string, wordStart: number): void {
pattern = pattern.substr(patternStart);
word = word.substr(wordStart);
console.log(printTable(_table, pattern, pattern.length, word, word.length));
console.log(printTable(_arrows, pattern, pattern.length, word, word.length));
console.log(printTable(_scores, pattern, pattern.length, word, word.length));
}
function isSeparatorAtPos(value: string, index: number): boolean {
if (index < 0 || index >= value.length) {
return false;
@@ -530,130 +538,127 @@ export interface FuzzyScorer {
(pattern: string, lowPattern: string, patternPos: number, word: string, lowWord: string, wordPos: number, firstMatchCanBeWeak: boolean): FuzzyScore | undefined;
}
export function fuzzyScore(pattern: string, patternLow: string, patternPos: number, word: string, wordLow: string, wordPos: number, firstMatchCanBeWeak: boolean): FuzzyScore | undefined {
if (patternPos > 0) {
pattern = pattern.substr(patternPos);
patternLow = patternLow.substr(patternPos);
patternPos = 0;
}
export function fuzzyScore(pattern: string, patternLow: string, patternStart: number, word: string, wordLow: string, wordStart: number, firstMatchCanBeWeak: boolean): FuzzyScore | undefined {
const patternLen = pattern.length > _maxLen ? _maxLen : pattern.length;
const wordLen = word.length > _maxLen ? _maxLen : word.length;
if (patternPos >= patternLen || wordPos >= wordLen || patternLen > wordLen) {
if (patternStart >= patternLen || wordStart >= wordLen || patternLen > wordLen) {
return undefined;
}
// Run a simple check if the characters of pattern occur
// (in order) at all in word. If that isn't the case we
// stop because no match will be possible
if (!isPatternInWord(patternLow, patternPos, patternLen, wordLow, wordPos, wordLen)) {
if (!isPatternInWord(patternLow, patternStart, patternLen, wordLow, wordStart, wordLen)) {
return undefined;
}
const patternStartPos = patternPos;
const wordStartPos = wordPos;
let row: number = 1;
let column: number = 1;
let patternPos = patternStart;
let wordPos = wordStart;
// There will be a match, fill in tables
for (patternPos = patternStartPos + 1; patternPos <= patternLen; patternPos++) {
for (row = 1, patternPos = patternStart; patternPos < patternLen; row++ , patternPos++) {
for (wordPos = 1; wordPos <= wordLen; wordPos++) {
for (column = 1, wordPos = wordStart; wordPos < wordLen; column++ , wordPos++) {
let score = -1;
if (patternLow[patternPos - 1] === wordLow[wordPos - 1]) {
const score = _doScore(pattern, patternLow, patternPos, patternStart, word, wordLow, wordPos);
if (wordPos === (patternPos - patternStartPos)) {
// common prefix: `foobar <-> foobaz`
// ^^^^^
if (pattern[patternPos - 1] === word[wordPos - 1]) {
score = 7;
} else {
score = 5;
}
} else if (isUpperCaseAtPos(wordPos - 1, word, wordLow) && (wordPos === 1 || !isUpperCaseAtPos(wordPos - 2, word, wordLow))) {
// hitting upper-case: `foo <-> forOthers`
// ^^ ^
if (pattern[patternPos - 1] === word[wordPos - 1]) {
score = 7;
} else {
score = 5;
}
} else if (isSeparatorAtPos(wordLow, wordPos - 1) && (wordPos === 1 || !isSeparatorAtPos(wordLow, wordPos - 2))) {
// hitting a separator: `. <-> foo.bar`
// ^
score = 5;
_scores[row][column] = score;
} else if (isSeparatorAtPos(wordLow, wordPos - 2) || isWhitespaceAtPos(wordLow, wordPos - 2)) {
// post separator: `foo <-> bar_foo`
// ^^^
score = 5;
} else {
score = 1;
}
}
_scores[patternPos][wordPos] = score;
const diag = _table[patternPos - 1][wordPos - 1] + (score > 1 ? 1 : score);
const top = _table[patternPos - 1][wordPos] + -1;
const left = _table[patternPos][wordPos - 1] + -1;
const diag = _table[row - 1][column - 1] + (score > 1 ? 1 : score);
const top = _table[row - 1][column] + -1;
const left = _table[row][column - 1] + -1;
if (left >= top) {
// left or diag
if (left > diag) {
_table[patternPos][wordPos] = left;
_arrows[patternPos][wordPos] = Arrow.Left;
_table[row][column] = left;
_arrows[row][column] = Arrow.Left;
} else if (left === diag) {
_table[patternPos][wordPos] = left;
_arrows[patternPos][wordPos] = Arrow.Left | Arrow.Diag;
_table[row][column] = left;
_arrows[row][column] = Arrow.Left | Arrow.Diag;
} else {
_table[patternPos][wordPos] = diag;
_arrows[patternPos][wordPos] = Arrow.Diag;
_table[row][column] = diag;
_arrows[row][column] = Arrow.Diag;
}
} else {
// top or diag
if (top > diag) {
_table[patternPos][wordPos] = top;
_arrows[patternPos][wordPos] = Arrow.Top;
_table[row][column] = top;
_arrows[row][column] = Arrow.Top;
} else if (top === diag) {
_table[patternPos][wordPos] = top;
_arrows[patternPos][wordPos] = Arrow.Top | Arrow.Diag;
_table[row][column] = top;
_arrows[row][column] = Arrow.Top | Arrow.Diag;
} else {
_table[patternPos][wordPos] = diag;
_arrows[patternPos][wordPos] = Arrow.Diag;
_table[row][column] = diag;
_arrows[row][column] = Arrow.Diag;
}
}
}
}
if (_debug) {
console.log(printTable(_table, pattern, patternLen, word, wordLen));
console.log(printTable(_arrows, pattern, patternLen, word, wordLen));
console.log(printTable(_scores, pattern, patternLen, word, wordLen));
printTables(pattern, patternStart, word, wordStart);
}
_matchesCount = 0;
_topScore = -100;
_patternStartPos = patternStartPos;
_wordStart = wordStart;
_firstMatchCanBeWeak = firstMatchCanBeWeak;
_findAllMatches2(patternLen, wordLen, patternLen === wordLen ? 1 : 0, 0, false);
_findAllMatches2(row - 1, column - 1, patternLen === wordLen ? 1 : 0, 0, false);
if (_matchesCount === 0) {
return undefined;
}
return [_topScore, _topMatch2, wordStartPos];
return [_topScore, _topMatch2, wordStart];
}
function _doScore(pattern: string, patternLow: string, patternPos: number, patternStart: number, word: string, wordLow: string, wordPos: number) {
if (patternLow[patternPos] !== wordLow[wordPos]) {
return -1;
}
if (wordPos === (patternPos - patternStart)) {
// common prefix: `foobar <-> foobaz`
// ^^^^^
if (pattern[patternPos] === word[wordPos]) {
return 7;
} else {
return 5;
}
} else if (isUpperCaseAtPos(wordPos, word, wordLow) && (wordPos === 0 || !isUpperCaseAtPos(wordPos - 1, word, wordLow))) {
// hitting upper-case: `foo <-> forOthers`
// ^^ ^
if (pattern[patternPos] === word[wordPos]) {
return 7;
} else {
return 5;
}
} else if (isSeparatorAtPos(wordLow, wordPos) && (wordPos === 0 || !isSeparatorAtPos(wordLow, wordPos - 1))) {
// hitting a separator: `. <-> foo.bar`
// ^
return 5;
} else if (isSeparatorAtPos(wordLow, wordPos - 1) || isWhitespaceAtPos(wordLow, wordPos - 1)) {
// post separator: `foo <-> bar_foo`
// ^^^
return 5;
} else {
return 1;
}
}
let _matchesCount: number = 0;
let _topMatch2: number = 0;
let _topScore: number = 0;
let _patternStartPos: number = 0;
let _wordStart: number = 0;
let _firstMatchCanBeWeak: boolean = false;
function _findAllMatches2(patternPos: number, wordPos: number, total: number, matches: number, lastMatched: boolean): void {
function _findAllMatches2(row: number, column: number, total: number, matches: number, lastMatched: boolean): void {
if (_matchesCount >= 10 || total < -25) {
// stop when having already 10 results, or
@@ -663,14 +668,14 @@ function _findAllMatches2(patternPos: number, wordPos: number, total: number, ma
let simpleMatchCount = 0;
while (patternPos > _patternStartPos && wordPos > 0) {
while (row > 0 && column > 0) {
const score = _scores[patternPos][wordPos];
const arrow = _arrows[patternPos][wordPos];
const score = _scores[row][column];
const arrow = _arrows[row][column];
if (arrow === Arrow.Left) {
// left -> no match, skip a word character
wordPos -= 1;
column -= 1;
if (lastMatched) {
total -= 5; // new gap penalty
} else if (matches !== 0) {
@@ -684,8 +689,8 @@ function _findAllMatches2(patternPos: number, wordPos: number, total: number, ma
if (arrow & Arrow.Left) {
// left
_findAllMatches2(
patternPos,
wordPos - 1,
row,
column - 1,
matches !== 0 ? total - 1 : total, // gap penalty after first match
matches,
lastMatched
@@ -694,12 +699,12 @@ function _findAllMatches2(patternPos: number, wordPos: number, total: number, ma
// diag
total += score;
patternPos -= 1;
wordPos -= 1;
row -= 1;
column -= 1;
lastMatched = true;
// match -> set a 1 at the word pos
matches += 2 ** wordPos;
matches += 2 ** (column + _wordStart);
// count simple matches and boost a row of
// simple matches when they yield in a
@@ -707,7 +712,7 @@ function _findAllMatches2(patternPos: number, wordPos: number, total: number, ma
if (score === 1) {
simpleMatchCount += 1;
if (patternPos === _patternStartPos && !_firstMatchCanBeWeak) {
if (row === 0 && !_firstMatchCanBeWeak) {
// when the first match is a weak
// match we discard it
return undefined;
@@ -724,7 +729,7 @@ function _findAllMatches2(patternPos: number, wordPos: number, total: number, ma
}
}
total -= wordPos >= 3 ? 9 : wordPos * 3; // late start penalty
total -= column >= 3 ? 9 : column * 3; // late start penalty
// dynamically keep track of the current top score
// and insert the current best score at head, the rest at tail

View File

@@ -207,17 +207,17 @@ export function createScanner(text: string, ignoreTrivia: boolean = false): JSON
function scanHexDigits(count: number): number {
let digits = 0;
let value = 0;
let hexValue = 0;
while (digits < count) {
const ch = text.charCodeAt(pos);
if (ch >= CharacterCodes._0 && ch <= CharacterCodes._9) {
value = value * 16 + ch - CharacterCodes._0;
hexValue = hexValue * 16 + ch - CharacterCodes._0;
}
else if (ch >= CharacterCodes.A && ch <= CharacterCodes.F) {
value = value * 16 + ch - CharacterCodes.A + 10;
hexValue = hexValue * 16 + ch - CharacterCodes.A + 10;
}
else if (ch >= CharacterCodes.a && ch <= CharacterCodes.f) {
value = value * 16 + ch - CharacterCodes.a + 10;
hexValue = hexValue * 16 + ch - CharacterCodes.a + 10;
}
else {
break;
@@ -226,9 +226,9 @@ export function createScanner(text: string, ignoreTrivia: boolean = false): JSON
digits++;
}
if (digits < count) {
value = -1;
hexValue = -1;
}
return value;
return hexValue;
}
function setPosition(newPosition: number) {
@@ -291,7 +291,7 @@ export function createScanner(text: string, ignoreTrivia: boolean = false): JSON
scanError = ScanError.UnexpectedEndOfString;
break;
}
let ch = text.charCodeAt(pos);
const ch = text.charCodeAt(pos);
if (ch === CharacterCodes.doubleQuote) {
result += text.substring(start, pos);
pos++;
@@ -304,8 +304,8 @@ export function createScanner(text: string, ignoreTrivia: boolean = false): JSON
scanError = ScanError.UnexpectedEndOfString;
break;
}
ch = text.charCodeAt(pos++);
switch (ch) {
const ch2 = text.charCodeAt(pos++);
switch (ch2) {
case CharacterCodes.doubleQuote:
result += '\"';
break;
@@ -331,9 +331,9 @@ export function createScanner(text: string, ignoreTrivia: boolean = false): JSON
result += '\t';
break;
case CharacterCodes.u:
const ch = scanHexDigits(4);
if (ch >= 0) {
result += String.fromCharCode(ch);
const ch3 = scanHexDigits(4);
if (ch3 >= 0) {
result += String.fromCharCode(ch3);
} else {
scanError = ScanError.InvalidUnicode;
}
@@ -1340,4 +1340,4 @@ function getLiteralNodeType(value: any): NodeType {
case 'string': return 'string';
default: return 'null';
}
}
}

View File

@@ -144,11 +144,11 @@ function withFormatting(text: string, edit: Edit, formattingOptions: FormattingO
// apply the formatting edits and track the begin and end offsets of the changes
for (let i = edits.length - 1; i >= 0; i--) {
const edit = edits[i];
newText = applyEdit(newText, edit);
begin = Math.min(begin, edit.offset);
end = Math.max(end, edit.offset + edit.length);
end += edit.content.length - edit.length;
const curr = edits[i];
newText = applyEdit(newText, curr);
begin = Math.min(begin, curr.offset);
end = Math.max(end, curr.offset + curr.length);
end += curr.content.length - curr.length;
}
// create a single edit with all changes
const editLength = text.length - (newText.length - end) - begin;
@@ -182,4 +182,4 @@ export function applyEdits(text: string, edits: Edit[]): string {
export function isWS(text: string, offset: number) {
return '\r\n \t'.indexOf(text.charAt(offset)) !== -1;
}
}

View File

@@ -61,6 +61,7 @@ export interface IJSONSchema {
markdownDescription?: string; // VSCode extension
doNotSuggest?: boolean; // VSCode extension
allowComments?: boolean; // VSCode extension
allowsTrailingCommas?: boolean; // VSCode extension
}
export interface IJSONSchemaMap {

View File

@@ -283,7 +283,7 @@ interface ISegment {
* @param value string to which templating is applied
* @param values the values of the templates to use
*/
export function template(template: string, values: { [key: string]: string | ISeparator | null } = Object.create(null)): string {
export function template(template: string, values: { [key: string]: string | ISeparator | undefined | null } = Object.create(null)): string {
const segments: ISegment[] = [];
let inVariable = false;

View File

@@ -18,7 +18,7 @@ export function values<V>(forEachable: { forEach(callback: (value: V, ...more: a
export function keys<K, V>(map: Map<K, V>): K[] {
const result: K[] = [];
map.forEach((value, key) => result.push(key));
map.forEach((_value, key) => result.push(key));
return result;
}
@@ -482,8 +482,6 @@ export class ResourceMap<T> {
}
}
// We should fold BoundedMap and LinkedMap. See https://github.com/Microsoft/vscode/issues/28496
interface Item<K, V> {
previous: Item<K, V> | undefined;
next: Item<K, V> | undefined;

View File

@@ -3,7 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { URI } from 'vs/base/common/uri';
import { URI, UriComponents } from 'vs/base/common/uri';
import * as platform from 'vs/base/common/platform';
export namespace Schemas {
@@ -60,18 +60,24 @@ class RemoteAuthoritiesImpl {
private readonly _ports: { [authority: string]: number; };
private readonly _connectionTokens: { [authority: string]: string; };
private _preferredWebSchema: 'http' | 'https';
private _delegate: ((uri: URI) => UriComponents) | null;
constructor() {
this._hosts = Object.create(null);
this._ports = Object.create(null);
this._connectionTokens = Object.create(null);
this._preferredWebSchema = 'http';
this._delegate = null;
}
public setPreferredWebSchema(schema: 'http' | 'https') {
this._preferredWebSchema = schema;
}
public setDelegate(delegate: (uri: URI) => UriComponents): void {
this._delegate = delegate;
}
public set(authority: string, host: string, port: number): void {
this._hosts[authority] = host;
this._ports[authority] = port;
@@ -81,7 +87,12 @@ class RemoteAuthoritiesImpl {
this._connectionTokens[authority] = connectionToken;
}
public rewrite(authority: string, path: string): URI {
public rewrite(uri: URI): URI {
if (this._delegate) {
const result = this._delegate(uri);
return URI.revive(result);
}
const authority = uri.authority;
const host = this._hosts[authority];
const port = this._ports[authority];
const connectionToken = this._connectionTokens[authority];
@@ -89,7 +100,7 @@ class RemoteAuthoritiesImpl {
scheme: platform.isWeb ? this._preferredWebSchema : Schemas.vscodeRemoteResource,
authority: `${host}:${port}`,
path: `/vscode-remote-resource`,
query: `path=${encodeURIComponent(path)}&tkn=${encodeURIComponent(connectionToken)}`
query: `path=${encodeURIComponent(uri.path)}&tkn=${encodeURIComponent(connectionToken)}`
});
}
}

View File

@@ -156,20 +156,21 @@ export const translationsConfigFile = _translationsConfigFile;
const _globals = (typeof self === 'object' ? self : typeof global === 'object' ? global : {} as any);
export const globals: any = _globals;
let _setImmediate: ((callback: (...args: any[]) => void) => number) | null = null;
export function setImmediate(callback: (...args: any[]) => void): number {
if (_setImmediate === null) {
if (globals.setImmediate) {
_setImmediate = globals.setImmediate.bind(globals);
} else if (typeof process !== 'undefined' && typeof process.nextTick === 'function') {
_setImmediate = process.nextTick.bind(process);
} else {
_setImmediate = globals.setTimeout.bind(globals);
}
}
return _setImmediate!(callback);
interface ISetImmediate {
(callback: (...args: any[]) => void): void;
}
export const setImmediate: ISetImmediate = (function defineSetImmediate() {
if (globals.setImmediate) {
return globals.setImmediate.bind(globals);
}
if (typeof process !== 'undefined' && typeof process.nextTick === 'function') {
return process.nextTick.bind(process);
}
const _promise = Promise.resolve();
return (callback: (...args: any[]) => void) => _promise.then(callback);
})();
export const enum OperatingSystem {
Windows = 1,
Macintosh = 2,

View File

@@ -10,7 +10,7 @@ interface IProcess {
env: IProcessEnvironment;
cwd(): string;
nextTick(callback: (...args: any[]) => void): number;
nextTick(callback: (...args: any[]) => void): void;
}
declare const process: IProcess;
@@ -18,7 +18,7 @@ const safeProcess: IProcess = (typeof process === 'undefined') ? {
cwd(): string { return '/'; },
env: Object.create(null),
get platform(): string { return isWindows ? 'win32' : isMacintosh ? 'darwin' : 'linux'; },
nextTick(callback: (...args: any[]) => void): number { return setImmediate(callback); }
nextTick(callback: (...args: any[]) => void): void { return setImmediate(callback); }
} : process;
export const cwd = safeProcess.cwd;

View File

@@ -12,8 +12,12 @@ export function buildReplaceStringWithCasePreserved(matches: string[] | null, pa
} else if (matches[0].toLowerCase() === matches[0]) {
return pattern.toLowerCase();
} else if (strings.containsUppercaseCharacter(matches[0][0])) {
if (validateSpecificSpecialCharacter(matches, pattern, '-')) {
const containsHyphens = validateSpecificSpecialCharacter(matches, pattern, '-');
const containsUnderscores = validateSpecificSpecialCharacter(matches, pattern, '_');
if (containsHyphens && !containsUnderscores) {
return buildReplaceStringForSpecificSpecialCharacter(matches, pattern, '-');
} else if (!containsHyphens && containsUnderscores) {
return buildReplaceStringForSpecificSpecialCharacter(matches, pattern, '_');
} else {
return pattern[0].toUpperCase() + pattern.substr(1);
}
@@ -27,8 +31,8 @@ export function buildReplaceStringWithCasePreserved(matches: string[] | null, pa
}
function validateSpecificSpecialCharacter(matches: string[], pattern: string, specialCharacter: string): boolean {
const doesConatinSpecialCharacter = matches[0].indexOf(specialCharacter) !== -1 && pattern.indexOf(specialCharacter) !== -1;
return doesConatinSpecialCharacter && matches[0].split(specialCharacter).length === pattern.split(specialCharacter).length;
const doesContainSpecialCharacter = matches[0].indexOf(specialCharacter) !== -1 && pattern.indexOf(specialCharacter) !== -1;
return doesContainSpecialCharacter && matches[0].split(specialCharacter).length === pattern.split(specialCharacter).length;
}
function buildReplaceStringForSpecificSpecialCharacter(matches: string[], pattern: string, specialCharacter: string): string {

View File

@@ -5,11 +5,6 @@
import { CharCode } from 'vs/base/common/charCode';
/**
* The empty string.
*/
export const empty = '';
export function isFalsyOrWhitespace(str: string | undefined): boolean {
if (!str || typeof str !== 'string') {
return true;
@@ -70,7 +65,7 @@ export function escape(html: string): string {
* Escapes regular expression characters in a given string
*/
export function escapeRegExpCharacters(value: string): string {
return value.replace(/[\-\\\{\}\*\+\?\|\^\$\.\[\]\(\)\#]/g, '\\$&');
return value.replace(/[\\\{\}\*\+\?\|\^\$\.\[\]\(\)]/g, '\\$&');
}
/**
@@ -608,7 +603,7 @@ export function lcut(text: string, n: number) {
re.lastIndex += 1;
}
return text.substring(i).replace(/^\s/, empty);
return text.substring(i).replace(/^\s/, '');
}
// Escape codes
@@ -636,7 +631,7 @@ export const removeAccents: (str: string) => string = (function () {
// see: https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript/37511463#37511463
const regex = /[\u0300-\u036f]/g;
return function (str: string) {
return (str as any).normalize('NFD').replace(regex, empty);
return (str as any).normalize('NFD').replace(regex, '');
};
}
})();