Merge from vscode a234f13c45b40a0929777cb440ee011b7549eed2 (#8911)

* Merge from vscode a234f13c45b40a0929777cb440ee011b7549eed2

* update distro

* fix layering

* update distro

* fix tests
This commit is contained in:
Anthony Dresser
2020-01-22 13:42:37 -08:00
committed by GitHub
parent 977111eb21
commit bd7aac8ee0
895 changed files with 24651 additions and 14520 deletions

View File

@@ -12,6 +12,7 @@ import { BrowserFeatures } from 'vs/base/browser/canIUse';
export interface IStandardMouseMoveEventData {
leftButton: boolean;
buttons: number;
posx: number;
posy: number;
}
@@ -33,21 +34,22 @@ export function standardMouseMoveMerger(lastEvent: IStandardMouseMoveEventData |
ev.preventDefault();
return {
leftButton: ev.leftButton,
buttons: ev.buttons,
posx: ev.posx,
posy: ev.posy
};
}
export class GlobalMouseMoveMonitor<R> implements IDisposable {
export class GlobalMouseMoveMonitor<R extends { buttons: number; }> implements IDisposable {
protected readonly hooks = new DisposableStore();
protected mouseMoveEventMerger: IEventMerger<R> | null = null;
protected mouseMoveCallback: IMouseMoveCallback<R> | null = null;
protected onStopCallback: IOnStopCallback | null = null;
private readonly _hooks = new DisposableStore();
private _mouseMoveEventMerger: IEventMerger<R> | null = null;
private _mouseMoveCallback: IMouseMoveCallback<R> | null = null;
private _onStopCallback: IOnStopCallback | null = null;
public dispose(): void {
this.stopMonitoring(false);
this.hooks.dispose();
this._hooks.dispose();
}
public stopMonitoring(invokeStopCallback: boolean): void {
@@ -57,11 +59,11 @@ export class GlobalMouseMoveMonitor<R> implements IDisposable {
}
// Unhook
this.hooks.clear();
this.mouseMoveEventMerger = null;
this.mouseMoveCallback = null;
const onStopCallback = this.onStopCallback;
this.onStopCallback = null;
this._hooks.clear();
this._mouseMoveEventMerger = null;
this._mouseMoveCallback = null;
const onStopCallback = this._onStopCallback;
this._onStopCallback = null;
if (invokeStopCallback && onStopCallback) {
onStopCallback();
@@ -69,10 +71,11 @@ export class GlobalMouseMoveMonitor<R> implements IDisposable {
}
public isMonitoring(): boolean {
return !!this.mouseMoveEventMerger;
return !!this._mouseMoveEventMerger;
}
public startMonitoring(
initialButtons: number,
mouseMoveEventMerger: IEventMerger<R>,
mouseMoveCallback: IMouseMoveCallback<R>,
onStopCallback: IOnStopCallback
@@ -81,40 +84,47 @@ export class GlobalMouseMoveMonitor<R> implements IDisposable {
// I am already hooked
return;
}
this.mouseMoveEventMerger = mouseMoveEventMerger;
this.mouseMoveCallback = mouseMoveCallback;
this.onStopCallback = onStopCallback;
this._mouseMoveEventMerger = mouseMoveEventMerger;
this._mouseMoveCallback = mouseMoveCallback;
this._onStopCallback = onStopCallback;
let windowChain = IframeUtils.getSameOriginWindowChain();
const mouseMove = platform.isIOS && BrowserFeatures.pointerEvents ? 'pointermove' : 'mousemove';
const mouseUp = platform.isIOS && BrowserFeatures.pointerEvents ? 'pointerup' : 'mouseup';
for (const element of windowChain) {
this.hooks.add(dom.addDisposableThrottledListener(element.window.document, mouseMove,
(data: R) => this.mouseMoveCallback!(data),
(lastEvent: R | null, currentEvent) => this.mouseMoveEventMerger!(lastEvent, currentEvent as MouseEvent)
this._hooks.add(dom.addDisposableThrottledListener(element.window.document, mouseMove,
(data: R) => {
if (data.buttons !== initialButtons) {
// Buttons state has changed in the meantime
this.stopMonitoring(true);
return;
}
this._mouseMoveCallback!(data);
},
(lastEvent: R | null, currentEvent) => this._mouseMoveEventMerger!(lastEvent, currentEvent as MouseEvent)
));
this.hooks.add(dom.addDisposableListener(element.window.document, mouseUp, (e: MouseEvent) => this.stopMonitoring(true)));
this._hooks.add(dom.addDisposableListener(element.window.document, mouseUp, (e: MouseEvent) => this.stopMonitoring(true)));
}
if (IframeUtils.hasDifferentOriginAncestor()) {
let lastSameOriginAncestor = windowChain[windowChain.length - 1];
// We might miss a mouse up if it happens outside the iframe
// This one is for Chrome
this.hooks.add(dom.addDisposableListener(lastSameOriginAncestor.window.document, 'mouseout', (browserEvent: MouseEvent) => {
this._hooks.add(dom.addDisposableListener(lastSameOriginAncestor.window.document, 'mouseout', (browserEvent: MouseEvent) => {
let e = new StandardMouseEvent(browserEvent);
if (e.target.tagName.toLowerCase() === 'html') {
this.stopMonitoring(true);
}
}));
// This one is for FF
this.hooks.add(dom.addDisposableListener(lastSameOriginAncestor.window.document, 'mouseover', (browserEvent: MouseEvent) => {
this._hooks.add(dom.addDisposableListener(lastSameOriginAncestor.window.document, 'mouseover', (browserEvent: MouseEvent) => {
let e = new StandardMouseEvent(browserEvent);
if (e.target.tagName.toLowerCase() === 'html') {
this.stopMonitoring(true);
}
}));
// This one is for IE
this.hooks.add(dom.addDisposableListener(lastSameOriginAncestor.window.document.body, 'mouseleave', (browserEvent: MouseEvent) => {
this._hooks.add(dom.addDisposableListener(lastSameOriginAncestor.window.document.body, 'mouseleave', (browserEvent: MouseEvent) => {
this.stopMonitoring(true);
}));
}

View File

@@ -12,6 +12,7 @@ export interface IMouseEvent {
readonly leftButton: boolean;
readonly middleButton: boolean;
readonly rightButton: boolean;
readonly buttons: number;
readonly target: HTMLElement;
readonly detail: number;
readonly posx: number;
@@ -33,6 +34,7 @@ export class StandardMouseEvent implements IMouseEvent {
public readonly leftButton: boolean;
public readonly middleButton: boolean;
public readonly rightButton: boolean;
public readonly buttons: number;
public readonly target: HTMLElement;
public detail: number;
public readonly posx: number;
@@ -49,6 +51,7 @@ export class StandardMouseEvent implements IMouseEvent {
this.leftButton = e.button === 0;
this.middleButton = e.button === 1;
this.rightButton = e.button === 2;
this.buttons = e.buttons;
this.target = <HTMLElement>e.target;

View File

@@ -130,7 +130,7 @@ export class Button extends Disposable {
applyStyles(): void {
if (this._element) {
const background = this.buttonBackground ? this.buttonBackground.toString() : '';
const foreground = this.buttonForeground ? this.buttonForeground.toString() : null;
const foreground = this.buttonForeground ? this.buttonForeground.toString() : '';
const border = this.buttonBorder ? this.buttonBorder.toString() : '';
this._element.style.color = foreground;

View File

@@ -220,7 +220,7 @@ export class SimpleCheckbox extends Widget {
}
protected applyStyles(): void {
this.domNode.style.color = this.styles.checkboxForeground ? this.styles.checkboxForeground.toString() : null;
this.domNode.style.color = this.styles.checkboxForeground ? this.styles.checkboxForeground.toString() : '';
this.domNode.style.backgroundColor = this.styles.checkboxBackground ? this.styles.checkboxBackground.toString() : '';
this.domNode.style.borderColor = this.styles.checkboxBorder ? this.styles.checkboxBorder.toString() : '';
}

View File

@@ -5,7 +5,7 @@
@font-face {
font-family: "codicon";
src: url("./codicon.ttf?17db7f5e5f31fd546e62218bb0823c0c") format("truetype");
src: url("./codicon.ttf?ed926e87ee4e27771159d875e877f74a") format("truetype");
}
.codicon[class*='codicon-'] {
@@ -409,4 +409,5 @@
.codicon-call-outgoing:before { content: "\eb93" }
.codicon-menu:before { content: "\eb94" }
.codicon-expand-all:before { content: "\eb95" }
.codicon-feedback:before { content: "\eb96" }
.codicon-debug-alt:before { content: "\f101" }

View File

@@ -392,6 +392,8 @@ class BranchNode implements ISplitView<ILayoutContext>, IDisposable {
const child = this._removeChild(from);
this._addChild(child, to);
this.onDidChildrenChange();
}
swapChildren(from: number, to: number): void {
@@ -408,6 +410,8 @@ class BranchNode implements ISplitView<ILayoutContext>, IDisposable {
this.splitview.swapViews(from, to);
[this.children[from].orthogonalStartSash, this.children[from].orthogonalEndSash, this.children[to].orthogonalStartSash, this.children[to].orthogonalEndSash] = [this.children[to].orthogonalStartSash, this.children[to].orthogonalEndSash, this.children[from].orthogonalStartSash, this.children[from].orthogonalEndSash];
[this.children[from], this.children[to]] = [this.children[to], this.children[from]];
this.onDidChildrenChange();
}
resizeChild(index: number, size: number): void {

View File

@@ -10,6 +10,7 @@ import { escape } from 'vs/base/common/strings';
export interface IHighlight {
start: number;
end: number;
extraClasses?: string;
}
export class HighlightedLabel {
@@ -69,7 +70,11 @@ export class HighlightedLabel {
htmlContent += '</span>';
pos = highlight.end;
}
htmlContent += '<span class="highlight">';
if (highlight.extraClasses) {
htmlContent += `<span class="highlight ${highlight.extraClasses}">`;
} else {
htmlContent += `<span class="highlight">`;
}
const substring = this.text.substring(highlight.start, highlight.end);
htmlContent += this.supportCodicons ? renderCodicons(escape(substring)) : escape(substring);
htmlContent += '</span>';

View File

@@ -511,7 +511,7 @@ export class InputBox extends Widget {
const styles = this.stylesForType(this.message.type);
spanElement.style.backgroundColor = styles.background ? styles.background.toString() : '';
spanElement.style.color = styles.foreground ? styles.foreground.toString() : null;
spanElement.style.color = styles.foreground ? styles.foreground.toString() : '';
spanElement.style.border = styles.border ? `1px solid ${styles.border}` : '';
dom.append(div, spanElement);

View File

@@ -597,12 +597,12 @@ class BaseMenuActionViewItem extends BaseActionViewItem {
const border = isSelected && this.menuStyle.selectionBorderColor ? `thin solid ${this.menuStyle.selectionBorderColor}` : '';
if (this.item) {
this.item.style.color = fgColor ? `${fgColor}` : null;
this.item.style.backgroundColor = bgColor ? `${bgColor}` : '';
this.item.style.color = fgColor ? fgColor.toString() : '';
this.item.style.backgroundColor = bgColor ? bgColor.toString() : '';
}
if (this.check) {
this.check.style.color = fgColor ? `${fgColor}` : '';
this.check.style.color = fgColor ? fgColor.toString() : '';
}
if (this.container) {

View File

@@ -20,6 +20,7 @@ import { INewScrollPosition, Scrollable, ScrollbarVisibility } from 'vs/base/com
const MOUSE_DRAG_RESET_DISTANCE = 140;
export interface ISimplifiedMouseEvent {
buttons: number;
posx: number;
posy: number;
}
@@ -222,6 +223,7 @@ export abstract class AbstractScrollbar extends Widget {
this.slider.toggleClassName('active', true);
this._mouseMoveMonitor.startMonitoring(
e.buttons,
standardMouseMoveMerger,
(mouseMoveData: IStandardMouseMoveEventData) => {
const mouseOrthogonalPosition = this._sliderOrthogonalMousePosition(mouseMoveData);

View File

@@ -93,6 +93,7 @@ export class ScrollbarArrow extends Widget {
this._mousedownScheduleRepeatTimer.cancelAndSet(scheduleRepeater, 200);
this._mouseMoveMonitor.startMonitoring(
e.buttons,
standardMouseMoveMerger,
(mouseMoveData: IStandardMouseMoveEventData) => {
/* Intentional empty */

View File

@@ -230,7 +230,7 @@ export abstract class Pane extends Disposable implements IView {
toggleClass(this.header, 'expanded', expanded);
this.header.setAttribute('aria-expanded', String(expanded));
this.header.style.color = this.styles.headerForeground ? this.styles.headerForeground.toString() : null;
this.header.style.color = this.styles.headerForeground ? this.styles.headerForeground.toString() : '';
this.header.style.backgroundColor = this.styles.headerBackground ? this.styles.headerBackground.toString() : '';
this.header.style.borderTop = this.styles.headerBorder ? `1px solid ${this.styles.headerBorder}` : '';
this._dropBackground = this.styles.dropBackground;

View File

@@ -190,7 +190,13 @@ function asListOptions<T, TFilterData, TRef>(modelProvider: () => ITreeModel<T,
},
getPosInSet(node) {
return node.visibleChildIndex + 1;
}
},
isChecked: options.ariaProvider && options.ariaProvider.isChecked ? (node) => {
return options.ariaProvider!.isChecked!(node.element);
} : undefined,
getRole: options.ariaProvider && options.ariaProvider.getRole ? (node) => {
return options.ariaProvider!.getRole!(node.element);
} : undefined
}
};
}

View File

@@ -258,7 +258,20 @@ function asObjectTreeOptions<TInput, T, TFilterData>(options?: IAsyncDataTreeOpt
e => (options.expandOnlyOnTwistieClick as ((e: T) => boolean))(e.element as T)
)
),
ariaProvider: undefined,
ariaProvider: options.ariaProvider && {
getPosInSet(el, index) {
return options.ariaProvider!.getPosInSet(el.element as T, index);
},
getSetSize(el, index, listLength) {
return options.ariaProvider!.getSetSize(el.element as T, index, listLength);
},
getRole: options.ariaProvider!.getRole ? (el) => {
return options.ariaProvider!.getRole!(el.element as T);
} : undefined,
isChecked: options.ariaProvider!.isChecked ? (e) => {
return options.ariaProvider?.isChecked!(e.element as T);
} : undefined
},
additionalScrollHeight: options.additionalScrollHeight
};
}

View File

@@ -668,7 +668,7 @@ export class RunOnceWorker<T> extends RunOnceScheduler {
export interface IdleDeadline {
readonly didTimeout: boolean;
timeRemaining(): DOMHighResTimeStamp;
timeRemaining(): number;
}
/**
* Execute the callback the next time the browser is idle

View File

@@ -6,7 +6,7 @@
import * as strings from 'vs/base/common/strings';
import * as streams from 'vs/base/common/stream';
declare var Buffer: any;
declare const Buffer: any;
const hasBuffer = (typeof Buffer !== 'undefined');
const hasTextEncoder = (typeof TextEncoder !== 'undefined');

View File

@@ -560,9 +560,9 @@ export function fuzzyScore(pattern: string, patternLow: string, patternStart: nu
let wordPos = wordStart;
// There will be a match, fill in tables
for (row = 1, patternPos = patternStart; patternPos < patternLen; row++ , patternPos++) {
for (row = 1, patternPos = patternStart; patternPos < patternLen; row++, patternPos++) {
for (column = 1, wordPos = wordStart; wordPos < wordLen; column++ , wordPos++) {
for (column = 1, wordPos = wordStart; wordPos < wordLen; column++, wordPos++) {
const score = _doScore(pattern, patternLow, patternPos, patternStart, word, wordLow, wordPos);

View File

@@ -163,7 +163,7 @@ export abstract class Disposable implements IDisposable {
/**
* Manages the lifecycle of a disposable value that may be changed.
*
* This ensures that when the the disposable value is changed, the previously held disposable is disposed of. You can
* This ensures that when the disposable value is changed, the previously held disposable is disposed of. You can
* also register a `MutableDisposable` on a `Disposable` to ensure it is automatically cleaned up.
*/
export class MutableDisposable<T extends IDisposable> implements IDisposable {

View File

@@ -454,8 +454,8 @@ export class ResourceMap<T> {
return this.map.delete(this.toKey(resource));
}
forEach(clb: (value: T) => void): void {
this.map.forEach(clb);
forEach(clb: (value: T, key: URI) => void): void {
this.map.forEach((value, index) => clb(value, URI.parse(index)));
}
values(): T[] {

View File

@@ -12,47 +12,47 @@ export namespace Schemas {
* A schema that is used for models that exist in memory
* only and that have no correspondence on a server or such.
*/
export const inMemory: string = 'inmemory';
export const inMemory = 'inmemory';
/**
* A schema that is used for setting files
*/
export const vscode: string = 'vscode';
export const vscode = 'vscode';
/**
* A schema that is used for internal private files
*/
export const internal: string = 'private';
export const internal = 'private';
/**
* A walk-through document.
*/
export const walkThrough: string = 'walkThrough';
export const walkThrough = 'walkThrough';
/**
* An embedded code snippet.
*/
export const walkThroughSnippet: string = 'walkThroughSnippet';
export const walkThroughSnippet = 'walkThroughSnippet';
export const http: string = 'http';
export const http = 'http';
export const https: string = 'https';
export const https = 'https';
export const file: string = 'file';
export const file = 'file';
export const mailto: string = 'mailto';
export const mailto = 'mailto';
export const untitled: string = 'untitled';
export const untitled = 'untitled';
export const data: string = 'data';
export const data = 'data';
export const command: string = 'command';
export const command = 'command';
export const vscodeRemote: string = 'vscode-remote';
export const vscodeRemote = 'vscode-remote';
export const vscodeRemoteResource: string = 'vscode-remote-resource';
export const vscodeRemoteResource = 'vscode-remote-resource';
export const userData: string = 'vscode-userdata';
export const userData = 'vscode-userdata';
}
class RemoteAuthoritiesImpl {

View File

@@ -100,7 +100,7 @@ if (typeof global === 'object') {
if (typeof define === 'function') {
// amd
define([], function () { return _factory(sharedObj); });
} else if (typeof module === "object" && typeof module.exports === "object") {
} else if (typeof module === 'object' && typeof module.exports === 'object') {
// commonjs
module.exports = _factory(sharedObj);
} else {

View File

@@ -57,12 +57,3 @@ export function toUint32(v: number): number {
}
return v | 0;
}
export function toUint32Array(arr: number[]): Uint32Array {
const len = arr.length;
const r = new Uint32Array(len);
for (let i = 0; i < len; i++) {
r[i] = toUint32(arr[i]);
}
return r;
}

View File

@@ -390,7 +390,7 @@ interface UriState extends UriComponents {
const _pathSepMarker = isWindows ? 1 : undefined;
// tslint:disable-next-line:class-name
// eslint-disable-next-line @typescript-eslint/class-name-casing
class _URI extends URI {
_formatted: string | null = null;

View File

@@ -12,7 +12,7 @@ const INITIALIZE = '$initialize';
export interface IWorker extends IDisposable {
getId(): number;
postMessage(message: any, transfer: Transferable[]): void;
postMessage(message: any, transfer: ArrayBuffer[]): void;
}
export interface IWorkerCallback {
@@ -302,7 +302,7 @@ export class SimpleWorkerServer<H extends object> {
private _requestHandler: IRequestHandler | null;
private _protocol: SimpleWorkerProtocol;
constructor(postMessage: (msg: any, transfer?: Transferable[]) => void, requestHandlerFactory: IRequestHandlerFactory<H> | null) {
constructor(postMessage: (msg: any, transfer?: ArrayBuffer[]) => void, requestHandlerFactory: IRequestHandlerFactory<H> | null) {
this._requestHandlerFactory = requestHandlerFactory;
this._requestHandler = null;
this._protocol = new SimpleWorkerProtocol({

View File

@@ -4,8 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import * as iconv from 'iconv-lite';
import { isLinux, isMacintosh } from 'vs/base/common/platform';
import { exec } from 'child_process';
import { Readable, Writable } from 'stream';
import { VSBuffer } from 'vs/base/common/buffer';
@@ -24,9 +22,10 @@ export const UTF16be_BOM = [0xFE, 0xFF];
export const UTF16le_BOM = [0xFF, 0xFE];
export const UTF8_BOM = [0xEF, 0xBB, 0xBF];
const ZERO_BYTE_DETECTION_BUFFER_MAX_LEN = 512; // number of bytes to look at to decide about a file being binary or not
const NO_GUESS_BUFFER_MAX_LEN = 512; // when not auto guessing the encoding, small number of bytes are enough
const AUTO_GUESS_BUFFER_MAX_LEN = 512 * 8; // with auto guessing we want a lot more content to be read for guessing
const ZERO_BYTE_DETECTION_BUFFER_MAX_LEN = 512; // number of bytes to look at to decide about a file being binary or not
const NO_ENCODING_GUESS_MIN_BYTES = 512; // when not auto guessing the encoding, small number of bytes are enough
const AUTO_ENCODING_GUESS_MIN_BYTES = 512 * 8; // with auto guessing we want a lot more content to be read for guessing
const AUTO_ENCODING_GUESS_MAX_BYTES = 512 * 128; // set an upper limit for the number of bytes we pass on to jschardet
export interface IDecodeStreamOptions {
guessEncoding: boolean;
@@ -42,7 +41,7 @@ export interface IDecodeStreamResult {
export function toDecodeStream(readable: Readable, options: IDecodeStreamOptions): Promise<IDecodeStreamResult> {
if (!options.minBytesRequiredForDetection) {
options.minBytesRequiredForDetection = options.guessEncoding ? AUTO_GUESS_BUFFER_MAX_LEN : NO_GUESS_BUFFER_MAX_LEN;
options.minBytesRequiredForDetection = options.guessEncoding ? AUTO_ENCODING_GUESS_MIN_BYTES : NO_ENCODING_GUESS_MIN_BYTES;
}
return new Promise<IDecodeStreamResult>((resolve, reject) => {
@@ -212,7 +211,7 @@ const IGNORE_ENCODINGS = ['ascii', 'utf-16', 'utf-32'];
async function guessEncodingByBuffer(buffer: Buffer): Promise<string | null> {
const jschardet = await import('jschardet');
const guessed = jschardet.detect(buffer);
const guessed = jschardet.detect(buffer.slice(0, AUTO_ENCODING_GUESS_MAX_BYTES)); // ensure to limit buffer for guessing due to https://github.com/aadsm/jschardet/issues/53
if (!guessed || !guessed.encoding) {
return null;
}
@@ -353,87 +352,3 @@ export function detectEncodingFromBuffer({ buffer, bytesRead }: IReadResult, aut
return { seemsBinary, encoding };
}
// https://ss64.com/nt/chcp.html
const windowsTerminalEncodings = {
'437': 'cp437', // United States
'850': 'cp850', // Multilingual(Latin I)
'852': 'cp852', // Slavic(Latin II)
'855': 'cp855', // Cyrillic(Russian)
'857': 'cp857', // Turkish
'860': 'cp860', // Portuguese
'861': 'cp861', // Icelandic
'863': 'cp863', // Canadian - French
'865': 'cp865', // Nordic
'866': 'cp866', // Russian
'869': 'cp869', // Modern Greek
'936': 'cp936', // Simplified Chinese
'1252': 'cp1252' // West European Latin
};
export async function resolveTerminalEncoding(verbose?: boolean): Promise<string> {
let rawEncodingPromise: Promise<string>;
// Support a global environment variable to win over other mechanics
const cliEncodingEnv = process.env['VSCODE_CLI_ENCODING'];
if (cliEncodingEnv) {
if (verbose) {
console.log(`Found VSCODE_CLI_ENCODING variable: ${cliEncodingEnv}`);
}
rawEncodingPromise = Promise.resolve(cliEncodingEnv);
}
// Linux/Mac: use "locale charmap" command
else if (isLinux || isMacintosh) {
rawEncodingPromise = new Promise<string>(resolve => {
if (verbose) {
console.log('Running "locale charmap" to detect terminal encoding...');
}
exec('locale charmap', (err, stdout, stderr) => resolve(stdout));
});
}
// Windows: educated guess
else {
rawEncodingPromise = new Promise<string>(resolve => {
if (verbose) {
console.log('Running "chcp" to detect terminal encoding...');
}
exec('chcp', (err, stdout, stderr) => {
if (stdout) {
const windowsTerminalEncodingKeys = Object.keys(windowsTerminalEncodings) as Array<keyof typeof windowsTerminalEncodings>;
for (const key of windowsTerminalEncodingKeys) {
if (stdout.indexOf(key) >= 0) {
return resolve(windowsTerminalEncodings[key]);
}
}
}
return resolve(undefined);
});
});
}
const rawEncoding = await rawEncodingPromise;
if (verbose) {
console.log(`Detected raw terminal encoding: ${rawEncoding}`);
}
if (!rawEncoding || rawEncoding.toLowerCase() === 'utf-8' || rawEncoding.toLowerCase() === UTF8) {
return UTF8;
}
const iconvEncoding = toIconvLiteEncoding(rawEncoding);
if (iconv.encodingExists(iconvEncoding)) {
return iconvEncoding;
}
if (verbose) {
console.log('Unsupported terminal encoding, falling back to UTF-8.');
}
return UTF8;
}

View File

@@ -0,0 +1,98 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/**
* This code is also used by standalone cli's. Avoid adding dependencies to keep the size of the cli small.
*/
import { exec } from 'child_process';
import * as os from 'os';
const windowsTerminalEncodings = {
'437': 'cp437', // United States
'850': 'cp850', // Multilingual(Latin I)
'852': 'cp852', // Slavic(Latin II)
'855': 'cp855', // Cyrillic(Russian)
'857': 'cp857', // Turkish
'860': 'cp860', // Portuguese
'861': 'cp861', // Icelandic
'863': 'cp863', // Canadian - French
'865': 'cp865', // Nordic
'866': 'cp866', // Russian
'869': 'cp869', // Modern Greek
'936': 'cp936', // Simplified Chinese
'1252': 'cp1252' // West European Latin
};
function toIconvLiteEncoding(encodingName: string): string {
const normalizedEncodingName = encodingName.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();
const mapped = JSCHARDET_TO_ICONV_ENCODINGS[normalizedEncodingName];
return mapped || normalizedEncodingName;
}
const JSCHARDET_TO_ICONV_ENCODINGS: { [name: string]: string } = {
'ibm866': 'cp866',
'big5': 'cp950'
};
const UTF8 = 'utf8';
export async function resolveTerminalEncoding(verbose?: boolean): Promise<string> {
let rawEncodingPromise: Promise<string>;
// Support a global environment variable to win over other mechanics
const cliEncodingEnv = process.env['VSCODE_CLI_ENCODING'];
if (cliEncodingEnv) {
if (verbose) {
console.log(`Found VSCODE_CLI_ENCODING variable: ${cliEncodingEnv}`);
}
rawEncodingPromise = Promise.resolve(cliEncodingEnv);
}
// Windows: educated guess
else if (os.platform() === 'win32') {
rawEncodingPromise = new Promise<string>(resolve => {
if (verbose) {
console.log('Running "chcp" to detect terminal encoding...');
}
exec('chcp', (err, stdout, stderr) => {
if (stdout) {
const windowsTerminalEncodingKeys = Object.keys(windowsTerminalEncodings) as Array<keyof typeof windowsTerminalEncodings>;
for (const key of windowsTerminalEncodingKeys) {
if (stdout.indexOf(key) >= 0) {
return resolve(windowsTerminalEncodings[key]);
}
}
}
return resolve(undefined);
});
});
}
// Linux/Mac: use "locale charmap" command
else {
rawEncodingPromise = new Promise<string>(resolve => {
if (verbose) {
console.log('Running "locale charmap" to detect terminal encoding...');
}
exec('locale charmap', (err, stdout, stderr) => resolve(stdout));
});
}
const rawEncoding = await rawEncodingPromise;
if (verbose) {
console.log(`Detected raw terminal encoding: ${rawEncoding}`);
}
if (!rawEncoding || rawEncoding.toLowerCase() === 'utf-8' || rawEncoding.toLowerCase() === UTF8) {
return UTF8;
}
return toIconvLiteEncoding(rawEncoding);
}

View File

@@ -187,7 +187,7 @@ const BufferPresets = {
Object: createOneByteBuffer(DataType.Object),
};
declare var Buffer: any;
declare const Buffer: any;
const hasBuffer = (typeof Buffer !== 'undefined');
function serialize(writer: IWriter, data: any): void {

View File

@@ -406,7 +406,7 @@ export class QuickOpenWidget extends Disposable implements IModelProvider, IThem
protected applyStyles(): void {
if (this.element) {
const foreground = this.styles.foreground ? this.styles.foreground.toString() : null;
const foreground = this.styles.foreground ? this.styles.foreground.toString() : '';
const background = this.styles.background ? this.styles.background.toString() : '';
const borderColor = this.styles.borderColor ? this.styles.borderColor.toString() : '';
const widgetShadow = this.styles.widgetShadow ? this.styles.widgetShadow.toString() : '';

View File

@@ -77,7 +77,7 @@
}
.monaco-quick-open-widget .quick-open-tree .monaco-icon-label,
.monaco-quick-open-widget .quick-open-tree .monaco-icon-label .monaco-icon-label-description-container {
.monaco-quick-open-widget .quick-open-tree .monaco-icon-label .monaco-icon-label-container > .monaco-icon-name-container {
flex: 1; /* make sure the icon label grows within the row */
}

View File

@@ -68,9 +68,7 @@ export interface IDataSource<T> {
export interface IRenderer<T> {
getHeight(entry: T): number;
getTemplateId(entry: T): string;
// rationale: will be replaced by quickinput later
// tslint:disable-next-line: no-dom-globals
renderTemplate(templateId: string, container: HTMLElement, styles: any): any;
renderTemplate(templateId: string, container: any /* HTMLElement */, styles: any): any;
renderElement(entry: T, templateId: string, templateData: any, styles: any): void;
disposeTemplate(templateId: string, templateData: any): void;
}

View File

@@ -137,14 +137,14 @@ suite('Storage Library', () => {
changes.clear();
// Delete is accepted
change.set('foo', undefined);
change.set('foo', undefined!);
database.fireDidChangeItemsExternal({ items: change });
ok(changes.has('foo'));
equal(storage.get('foo', null!), null);
changes.clear();
// Nothing happens if changing to same value
change.set('foo', undefined);
change.set('foo', undefined!);
database.fireDidChangeItemsExternal({ items: change });
equal(changes.size, 0);

View File

@@ -136,6 +136,7 @@ suite('Event', function () {
let a = new Emitter<undefined>();
let hit = false;
a.event(function () {
// eslint-disable-next-line no-throw-literal
throw 9;
});
a.event(function () {

View File

@@ -47,7 +47,7 @@ suite('Lazy', () => {
assert.deepEqual(innerLazy.getValue(), [1, 11]);
});
test('map should should handle error values', () => {
test('map should handle error values', () => {
let outer = 0;
let inner = 10;
const outerLazy = new Lazy(() => { throw new Error(`${++outer}`); });

View File

@@ -6,6 +6,7 @@
import * as assert from 'assert';
import * as fs from 'fs';
import * as encoding from 'vs/base/node/encoding';
import * as terminalEncoding from 'vs/base/node/terminalEncoding';
import { Readable } from 'stream';
import { getPathFromAmdModule } from 'vs/base/common/amd';
@@ -118,14 +119,14 @@ suite('Encoding', () => {
});
test('resolve terminal encoding (detect)', async function () {
const enc = await encoding.resolveTerminalEncoding();
assert.ok(encoding.encodingExists(enc));
const enc = await terminalEncoding.resolveTerminalEncoding();
assert.ok(enc.length > 0);
});
test('resolve terminal encoding (environment)', async function () {
process.env['VSCODE_CLI_ENCODING'] = 'utf16le';
const enc = await encoding.resolveTerminalEncoding();
const enc = await terminalEncoding.resolveTerminalEncoding();
assert.ok(encoding.encodingExists(enc));
assert.equal(enc, 'utf16le');
});

View File

@@ -28,7 +28,7 @@ suite('Keytar', () => {
try {
await keytar.deletePassword(name, 'foo');
} finally {
// tslint:disable-next-line: no-unsafe-finally
// eslint-disable-next-line no-unsafe-finally
throw err;
}
}