Merge from vscode 1b314ab317fbff7d799b21754326b7d849889ceb

This commit is contained in:
ADS Merger
2020-07-15 23:51:18 +00:00
parent aae013d498
commit 9d3f12d0b7
554 changed files with 15159 additions and 8223 deletions

View File

@@ -591,6 +591,14 @@ export function asArray<T>(x: T | T[]): T[] {
return Array.isArray(x) ? x : [x];
}
export function toArray<T>(iterable: IterableIterator<T>): T[] {
const result: T[] = [];
for (let element of iterable) {
result.push(element);
}
return result;
}
export function getRandomElement<T>(arr: T[]): T | undefined {
return arr[Math.floor(Math.random() * arr.length)];
}

View File

@@ -52,6 +52,8 @@ export class Codicon {
_registry.add(this);
}
public get classNames() { return 'codicon codicon-' + this.id; }
// classNamesArray is useful for migrating to ES6 classlist
public get classNamesArray() { return ['codicon', 'codicon-' + this.id]; }
public get cssSelector() { return '.codicon.codicon-' + this.id; }
}
@@ -472,6 +474,8 @@ export namespace Codicon {
export const stopCircle = new Codicon('stop-circle', { character: '\\eba5' });
export const playCircle = new Codicon('play-circle', { character: '\\eba6' });
export const record = new Codicon('record', { character: '\\eba7' });
export const debugAltSmall = new Codicon('debug-alt-small', { character: '\\eba8' });
export const vmConnect = new Codicon('vm-connect', { character: '\\eba9' });
}

View File

@@ -203,3 +203,12 @@ export class NotImplementedError extends Error {
}
}
}
export class NotSupportedError extends Error {
constructor(message?: string) {
super('NotSupported');
if (message) {
this.message = message;
}
}
}

View File

@@ -42,8 +42,7 @@ export function scoreFuzzy(target: string, query: string, queryLower: string, fu
// When not searching fuzzy, we require the query to be contained fully
// in the target string contiguously.
if (!fuzzy) {
const indexOfQueryInTarget = targetLower.indexOf(queryLower);
if (indexOfQueryInTarget === -1) {
if (!targetLower.includes(queryLower)) {
// if (DEBUG) {
// console.log(`Characters not matching consecutively ${queryLower} within ${targetLower}`);
// }

View File

@@ -6,6 +6,7 @@
import { equals } from 'vs/base/common/arrays';
import { UriComponents } from 'vs/base/common/uri';
import { escapeCodicons } from 'vs/base/common/codicons';
import { illegalArgument } from 'vs/base/common/errors';
export interface IMarkdownString {
readonly value: string;
@@ -22,6 +23,10 @@ export class MarkdownString implements IMarkdownString {
private _value: string = '',
isTrustedOrOptions: boolean | { isTrusted?: boolean, supportThemeIcons?: boolean } = false,
) {
if (typeof this._value !== 'string') {
throw illegalArgument('value');
}
if (typeof isTrustedOrOptions === 'boolean') {
this._isTrusted = isTrustedOrOptions;
this._supportThemeIcons = false;
@@ -30,7 +35,6 @@ export class MarkdownString implements IMarkdownString {
this._isTrusted = isTrustedOrOptions.isTrusted ?? false;
this._supportThemeIcons = isTrustedOrOptions.supportThemeIcons ?? false;
}
}
get value() { return this._value; }

View File

@@ -9,27 +9,6 @@ import { compareSubstringIgnoreCase, compare, compareSubstring } from 'vs/base/c
import { Schemas } from 'vs/base/common/network';
import { isLinux } from 'vs/base/common/platform';
/**
* @deprecated ES6: use `[...SetOrMap.values()]`
*/
export function values<V = any>(set: Set<V>): V[];
export function values<K = any, V = any>(map: Map<K, V>): V[];
export function values<V>(forEachable: { forEach(callback: (value: V, ...more: any[]) => any): void }): V[] {
const result: V[] = [];
forEachable.forEach(value => result.push(value));
return result;
}
/**
* @deprecated ES6: use `[...map.keys()]`
*/
export function keys<K, V>(map: Map<K, V>): K[] {
const result: K[] = [];
map.forEach((_value, key) => result.push(key));
return result;
}
export function getOrSet<K, V>(map: Map<K, V>, key: K, value: V): V {
let result = map.get(key);
if (result === undefined) {

View File

@@ -5,7 +5,6 @@
import { basename, posix, extname } from 'vs/base/common/path';
import { startsWithUTF8BOM } from 'vs/base/common/strings';
import { coalesce } from 'vs/base/common/arrays';
import { match } from 'vs/base/common/glob';
import { URI } from 'vs/base/common/uri';
import { Schemas } from 'vs/base/common/network';
@@ -247,34 +246,6 @@ export function isUnspecific(mime: string[] | string): boolean {
return mime.length === 1 && isUnspecific(mime[0]);
}
/**
* Returns a suggestion for the filename by the following logic:
* 1. If a relevant extension exists and is an actual filename extension (starting with a dot), suggest the prefix appended by the first one.
* 2. Otherwise, if there are other extensions, suggest the first one.
* 3. Otherwise, suggest the prefix.
*/
export function suggestFilename(mode: string | undefined, prefix: string): string {
const extensions = registeredAssociations
.filter(assoc => !assoc.userConfigured && assoc.extension && assoc.id === mode)
.map(assoc => assoc.extension);
const extensionsWithDotFirst = coalesce(extensions)
.filter(assoc => assoc.startsWith('.'));
if (extensionsWithDotFirst.length > 0) {
const candidateExtension = extensionsWithDotFirst[0];
if (prefix.endsWith(candidateExtension)) {
// do not add the prefix if it already exists
// https://github.com/microsoft/vscode/issues/83603
return prefix;
}
return prefix + candidateExtension;
}
return extensions[0] || prefix;
}
interface MapExtToMediaMimes {
[index: string]: string;
}

View File

@@ -9,22 +9,22 @@
function _factory(sharedObj) {
sharedObj._performanceEntries = sharedObj._performanceEntries || [];
sharedObj.MonacoPerformanceMarks = sharedObj.MonacoPerformanceMarks || [];
const _dataLen = 2;
const _timeStamp = typeof console.timeStamp === 'function' ? console.timeStamp.bind(console) : () => { };
function importEntries(entries) {
sharedObj._performanceEntries.splice(0, 0, ...entries);
sharedObj.MonacoPerformanceMarks.splice(0, 0, ...entries);
}
function exportEntries() {
return sharedObj._performanceEntries.slice(0);
return sharedObj.MonacoPerformanceMarks.slice(0);
}
function getEntries() {
const result = [];
const entries = sharedObj._performanceEntries;
const entries = sharedObj.MonacoPerformanceMarks;
for (let i = 0; i < entries.length; i += _dataLen) {
result.push({
name: entries[i],
@@ -35,7 +35,7 @@ function _factory(sharedObj) {
}
function getDuration(from, to) {
const entries = sharedObj._performanceEntries;
const entries = sharedObj.MonacoPerformanceMarks;
let target = to;
let endIndex = 0;
for (let i = entries.length - _dataLen; i >= 0; i -= _dataLen) {
@@ -54,7 +54,7 @@ function _factory(sharedObj) {
}
function mark(name) {
sharedObj._performanceEntries.push(name, Date.now());
sharedObj.MonacoPerformanceMarks.push(name, Date.now());
_timeStamp(name);
}
@@ -73,7 +73,8 @@ function _factory(sharedObj) {
// Because we want both instances to use the same perf-data
// we store them globally
let sharedObj;
// eslint-disable-next-line no-var
var sharedObj;
if (typeof global === 'object') {
// nodejs
sharedObj = global;
@@ -91,5 +92,5 @@ if (typeof define === 'function') {
// commonjs
module.exports = _factory(sharedObj);
} else {
// invalid context...
sharedObj.perf = _factory(sharedObj);
}

View File

@@ -474,7 +474,7 @@ export function peekReadable<T>(readable: Readable<T>, reducer: IReducer<T>, max
/**
* Helper to fully read a T stream into a T.
*/
export function consumeStream<T>(stream: ReadableStream<T>, reducer: IReducer<T>): Promise<T> {
export function consumeStream<T>(stream: ReadableStreamEvents<T>, reducer: IReducer<T>): Promise<T> {
return new Promise((resolve, reject) => {
const chunks: T[] = [];

View File

@@ -8,7 +8,7 @@ import { URI, UriComponents } from 'vs/base/common/uri';
/**
* @returns whether the provided parameter is a JavaScript Array or not.
*/
export function isArray(array: any): array is any[] {
export function isArray<T>(array: T | {}): array is T extends readonly any[] ? (unknown extends T ? never : readonly any[]) : any[] {
return Array.isArray(array);
}
@@ -171,7 +171,7 @@ export function validateConstraint(arg: any, constraint: TypeConstraint | undefi
if (arg instanceof constraint) {
return;
}
} catch{
} catch {
// ignore
}
if (!isUndefinedOrNull(arg) && arg.constructor === constraint) {

View File

@@ -252,7 +252,7 @@ export class URI implements UriComponents {
return this;
}
return new _URI(scheme, authority, path, query, fragment);
return new CachingURI(scheme, authority, path, query, fragment);
}
// ---- parse & validate ------------------------
@@ -266,9 +266,9 @@ export class URI implements UriComponents {
static parse(value: string, _strict: boolean = false): URI {
const match = _regexp.exec(value);
if (!match) {
return new _URI(_empty, _empty, _empty, _empty, _empty);
return new CachingURI(_empty, _empty, _empty, _empty, _empty);
}
return new _URI(
return new CachingURI(
match[2] || _empty,
percentDecode(match[4] || _empty),
percentDecode(match[5] || _empty),
@@ -323,11 +323,11 @@ export class URI implements UriComponents {
}
}
return new _URI('file', authority, path, _empty, _empty);
return new CachingURI('file', authority, path, _empty, _empty);
}
static from(components: { scheme: string; authority?: string; path?: string; query?: string; fragment?: string }): URI {
return new _URI(
return new CachingURI(
components.scheme,
components.authority,
components.path,
@@ -388,7 +388,7 @@ export class URI implements UriComponents {
} else if (data instanceof URI) {
return data;
} else {
const result = new _URI(data);
const result = new CachingURI(data);
result._formatted = (<UriState>data).external;
result._fsPath = (<UriState>data)._sep === _pathSepMarker ? (<UriState>data).fsPath : null;
return result;
@@ -413,8 +413,8 @@ interface UriState extends UriComponents {
const _pathSepMarker = isWindows ? 1 : undefined;
// eslint-disable-next-line @typescript-eslint/naming-convention
class _URI extends URI {
// This class exists so that URI is compatibile with vscode.Uri (API).
class CachingURI extends URI {
_formatted: string | null = null;
_fsPath: string | null = null;