Merge from vscode f2d41726ba5a0e8abfe61b2c743022b1b6372010 (#7415)

* Merge from vscode f2d41726ba5a0e8abfe61b2c743022b1b6372010

* add missing files
This commit is contained in:
Anthony Dresser
2019-09-27 23:30:36 -07:00
committed by GitHub
parent d0fb6de390
commit bca7c8e6bd
123 changed files with 1704 additions and 1330 deletions

View File

@@ -781,6 +781,12 @@ export function createStyleSheet(container: HTMLElement = document.getElementsBy
return style;
}
export function createMetaElement(container: HTMLElement = document.getElementsByTagName('head')[0]): HTMLMetaElement {
let meta = document.createElement('meta');
container.appendChild(meta);
return meta;
}
let _sharedStyleSheet: HTMLStyleElement | null = null;
function getSharedStyleSheet(): HTMLStyleElement {
if (!_sharedStyleSheet) {

View File

@@ -698,7 +698,7 @@ export class MenuBar extends Disposable {
private focusPrevious(): void {
if (!this.focusedMenu) {
if (!this.focusedMenu || this.numMenusShown === 0) {
return;
}
@@ -728,7 +728,7 @@ export class MenuBar extends Disposable {
}
private focusNext(): void {
if (!this.focusedMenu) {
if (!this.focusedMenu || this.numMenusShown === 0) {
return;
}

View File

@@ -4,16 +4,25 @@
*--------------------------------------------------------------------------------------------*/
import { Event } from 'vs/base/common/event';
import { IChannel, IServerChannel } from 'vs/base/parts/ipc/common/ipc';
import { IServerChannel, IChannel } from 'vs/base/parts/ipc/common/ipc';
import { revive } from 'vs/base/common/marshalling';
import { isUndefinedOrNull } from 'vs/base/common/types';
import { isUpperAsciiLetter } from 'vs/base/common/strings';
//
// Use both `createChannelReceiver` and `createChannelSender`
// for automated process <=> process communication over methods
// and events.
//
/**
* Use both `createChannelReceiver` and `createChannelSender`
* for automated process <=> process communication over methods
* and events. You do not need to spell out each method on both
* sides, a proxy will take care of this.
*
* Rules:
* - if marshalling is enabled, only `URI` and `RegExp` is converted
* automatically for you
* - events must follow the naming convention `onUppercase`
* - `CancellationToken` is currently not supported
* - if a context is provided, you can use `AddFirstParameterToFunctions`
* utility to signal this in the receiving side type
*/
export interface IBaseChannelOptions {

View File

@@ -5,11 +5,14 @@
import * as assert from 'assert';
import { IChannel, IServerChannel, IMessagePassingProtocol, IPCServer, ClientConnectionEvent, IPCClient } from 'vs/base/parts/ipc/common/ipc';
import { createChannelReceiver, createChannelSender } from 'vs/base/parts/ipc/node/ipc';
import { Emitter, Event } from 'vs/base/common/event';
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
import { canceled } from 'vs/base/common/errors';
import { timeout } from 'vs/base/common/async';
import { VSBuffer } from 'vs/base/common/buffer';
import { URI } from 'vs/base/common/uri';
import { isEqual } from 'vs/base/common/resources';
class QueueProtocol implements IMessagePassingProtocol {
@@ -101,14 +104,16 @@ interface ITestService {
neverComplete(): Promise<void>;
neverCompleteCT(cancellationToken: CancellationToken): Promise<void>;
buffersLength(buffers: Buffer[]): Promise<number>;
marshall(uri: URI): Promise<URI>;
context(): Promise<unknown>;
pong: Event<string>;
onPong: Event<string>;
}
class TestService implements ITestService {
private readonly _pong = new Emitter<string>();
readonly pong = this._pong.event;
private readonly _onPong = new Emitter<string>();
readonly onPong = this._onPong.event;
marco(): Promise<string> {
return Promise.resolve('polo');
@@ -135,7 +140,15 @@ class TestService implements ITestService {
}
ping(msg: string): void {
this._pong.fire(msg);
this._onPong.fire(msg);
}
marshall(uri: URI): Promise<URI> {
return Promise.resolve(uri);
}
context(context?: unknown): Promise<unknown> {
return Promise.resolve(context);
}
}
@@ -156,7 +169,7 @@ class TestChannel implements IServerChannel {
listen(_: unknown, event: string, arg?: any): Event<any> {
switch (event) {
case 'pong': return this.service.pong;
case 'onPong': return this.service.onPong;
default: throw new Error('not implemented');
}
}
@@ -164,8 +177,8 @@ class TestChannel implements IServerChannel {
class TestChannelClient implements ITestService {
get pong(): Event<string> {
return this.channel.listen('pong');
get onPong(): Event<string> {
return this.channel.listen('onPong');
}
constructor(private channel: IChannel) { }
@@ -189,6 +202,14 @@ class TestChannelClient implements ITestService {
buffersLength(buffers: Buffer[]): Promise<number> {
return this.channel.call('buffersLength', buffers);
}
marshall(uri: URI): Promise<URI> {
return this.channel.call('marshall', uri);
}
context(): Promise<unknown> {
return this.channel.call('context');
}
}
suite('Base IPC', function () {
@@ -281,7 +302,7 @@ suite('Base IPC', function () {
test('listen to events', async function () {
const messages: string[] = [];
ipcService.pong(msg => messages.push(msg));
ipcService.onPong(msg => messages.push(msg));
await timeout(0);
assert.deepEqual(messages, []);
@@ -300,4 +321,98 @@ suite('Base IPC', function () {
return assert.equal(r, 5);
});
});
suite('one to one (proxy)', function () {
let server: IPCServer;
let client: IPCClient;
let service: TestService;
let ipcService: ITestService;
setup(function () {
service = new TestService();
const testServer = new TestIPCServer();
server = testServer;
server.registerChannel(TestChannelId, createChannelReceiver(service));
client = testServer.createConnection('client1');
ipcService = createChannelSender(client.getChannel(TestChannelId));
});
teardown(function () {
client.dispose();
server.dispose();
});
test('call success', async function () {
const r = await ipcService.marco();
return assert.equal(r, 'polo');
});
test('call error', async function () {
try {
await ipcService.error('nice error');
return assert.fail('should not reach here');
} catch (err) {
return assert.equal(err.message, 'nice error');
}
});
test('listen to events', async function () {
const messages: string[] = [];
ipcService.onPong(msg => messages.push(msg));
await timeout(0);
assert.deepEqual(messages, []);
service.ping('hello');
await timeout(0);
assert.deepEqual(messages, ['hello']);
service.ping('world');
await timeout(0);
assert.deepEqual(messages, ['hello', 'world']);
});
test('marshalling uri', async function () {
const uri = URI.file('foobar');
const r = await ipcService.marshall(uri);
assert.ok(r instanceof URI);
return assert.ok(isEqual(r, uri));
});
test('buffers in arrays', async function () {
const r = await ipcService.buffersLength([Buffer.allocUnsafe(2), Buffer.allocUnsafe(3)]);
return assert.equal(r, 5);
});
});
suite('one to one (proxy, extra context)', function () {
let server: IPCServer;
let client: IPCClient;
let service: TestService;
let ipcService: ITestService;
setup(function () {
service = new TestService();
const testServer = new TestIPCServer();
server = testServer;
server.registerChannel(TestChannelId, createChannelReceiver(service));
client = testServer.createConnection('client1');
ipcService = createChannelSender(client.getChannel(TestChannelId), { context: 'Super Context' });
});
teardown(function () {
client.dispose();
server.dispose();
});
test('call extra context', async function () {
const r = await ipcService.context();
return assert.equal(r, 'Super Context');
});
});
});