From 5a5a9f7a40c93a6a7797b3553e8997b0d488589b Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Tue, 13 Sep 2016 16:15:54 -0700 Subject: [PATCH] Reintroduce terminal API request queue system Fixes #11990 --- src/vs/workbench/api/node/extHost.protocol.ts | 2 +- .../api/node/extHostTerminalService.ts | 46 +++++++++++++++---- .../api/node/mainThreadTerminalService.ts | 5 +- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index 2b0c5345d70..1e10df02db2 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -153,7 +153,7 @@ export abstract class MainThreadOutputServiceShape { } export abstract class MainThreadTerminalServiceShape { - $createTerminal(name?: string, shellPath?: string, shellArgs?: string[]): number { throw ni(); } + $createTerminal(name?: string, shellPath?: string, shellArgs?: string[]): TPromise { throw ni(); } $dispose(terminalId: number): void { throw ni(); } $hide(terminalId: number): void { throw ni(); } $sendText(terminalId: number, text: string, addNewLine: boolean): void { throw ni(); } diff --git a/src/vs/workbench/api/node/extHostTerminalService.ts b/src/vs/workbench/api/node/extHostTerminalService.ts index 04032aea8b3..2253748554b 100644 --- a/src/vs/workbench/api/node/extHostTerminalService.ts +++ b/src/vs/workbench/api/node/extHostTerminalService.ts @@ -10,16 +10,21 @@ import {MainContext, MainThreadTerminalServiceShape} from './extHost.protocol'; export class ExtHostTerminal implements vscode.Terminal { - public _name: string; - + private _name: string; private _id: number; private _proxy: MainThreadTerminalServiceShape; private _disposed: boolean; + private _queuedRequests: ApiRequest[] = []; - constructor(proxy: MainThreadTerminalServiceShape, id: number, name?: string, shellPath?: string, shellArgs?: string[]) { + constructor(proxy: MainThreadTerminalServiceShape, name?: string, shellPath?: string, shellArgs?: string[]) { this._name = name; this._proxy = proxy; - this._id = this._proxy.$createTerminal(name, shellPath, shellArgs); + this._proxy.$createTerminal(name, shellPath, shellArgs).then((id) => { + this._id = id; + this._queuedRequests.forEach((r) => { + r.run(this._proxy, this._id); + }); + }); } public get name(): string { @@ -29,26 +34,35 @@ export class ExtHostTerminal implements vscode.Terminal { public sendText(text: string, addNewLine: boolean = true): void { this._checkDisposed(); - this._proxy.$sendText(this._id, text, addNewLine); + this._queueApiRequest(this._proxy.$sendText, [text, addNewLine]); } public show(preserveFocus: boolean): void { this._checkDisposed(); - this._proxy.$show(this._id, preserveFocus); + this._queueApiRequest(this._proxy.$show, [preserveFocus]); } public hide(): void { this._checkDisposed(); - this._proxy.$hide(this._id); + this._queueApiRequest(this._proxy.$hide, []); } public dispose(): void { if (!this._disposed) { this._disposed = true; - this._proxy.$dispose(this._id); + this._queueApiRequest(this._proxy.$dispose, []); } } + private _queueApiRequest(callback: (...args: any[]) => void, args: any[]) { + let request: ApiRequest = new ApiRequest(callback, args); + if (!this._id) { + this._queuedRequests.push(request); + return; + } + request.run(this._proxy, this._id); + } + private _checkDisposed() { if (this._disposed) { throw new Error('Terminal has already been disposed'); @@ -65,6 +79,20 @@ export class ExtHostTerminalService { } public createTerminal(name?: string, shellPath?: string, shellArgs?: string[]): vscode.Terminal { - return new ExtHostTerminal(this._proxy, -1, name, shellPath, shellArgs); + return new ExtHostTerminal(this._proxy, name, shellPath, shellArgs); } } + +class ApiRequest { + private _callback: (...args: any[]) => void; + private _args: any[]; + + constructor(callback: (...args: any[]) => void, args: any[]) { + this._callback = callback; + this._args = args; + } + + public run(proxy: MainThreadTerminalServiceShape, id: number) { + this._callback.apply(proxy, [id].concat(this._args)); + } +} \ No newline at end of file diff --git a/src/vs/workbench/api/node/mainThreadTerminalService.ts b/src/vs/workbench/api/node/mainThreadTerminalService.ts index 67c0c1bd8fe..6c9a57262ab 100644 --- a/src/vs/workbench/api/node/mainThreadTerminalService.ts +++ b/src/vs/workbench/api/node/mainThreadTerminalService.ts @@ -8,6 +8,7 @@ import {ITerminalService} from 'vs/workbench/parts/terminal/electron-browser/ter import {IPanelService} from 'vs/workbench/services/panel/common/panelService'; import {IPartService} from 'vs/workbench/services/part/common/partService'; import {MainThreadTerminalServiceShape} from './extHost.protocol'; +import {TPromise} from 'vs/base/common/winjs.base'; export class MainThreadTerminalService extends MainThreadTerminalServiceShape { @@ -19,8 +20,8 @@ export class MainThreadTerminalService extends MainThreadTerminalServiceShape { super(); } - public $createTerminal(name?: string, shellPath?: string, shellArgs?: string[]): number { - return this.terminalService.createInstance(name, shellPath, shellArgs).id; + public $createTerminal(name?: string, shellPath?: string, shellArgs?: string[]): TPromise { + return TPromise.as(this.terminalService.createInstance(name, shellPath, shellArgs).id); } public $show(terminalId: number, preserveFocus: boolean): void { -- GitLab