diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index b4a2aabc165..3328a19eabe 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -769,4 +769,12 @@ declare module 'vscode' { } //#endregion + + //#region Terminal + + export namespace window { + export const onDidOpenTerminal: Event; + } + + //#endregion } diff --git a/src/vs/workbench/api/electron-browser/mainThreadTerminalService.ts b/src/vs/workbench/api/electron-browser/mainThreadTerminalService.ts index ee934a107b5..3911dc347bd 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadTerminalService.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadTerminalService.ts @@ -22,6 +22,7 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape ) { this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostTerminalService); this._toDispose = []; + this._toDispose.push(terminalService.onInstanceCreated((terminalInstance) => this._onTerminalOpened(terminalInstance))); this._toDispose.push(terminalService.onInstanceDisposed((terminalInstance) => this._onTerminalDisposed(terminalInstance))); this._toDispose.push(terminalService.onInstanceProcessIdReady((terminalInstance) => this._onTerminalProcessIdReady(terminalInstance))); } @@ -78,6 +79,10 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape this._proxy.$acceptTerminalClosed(terminalInstance.id); } + private _onTerminalOpened(terminalInstance: ITerminalInstance): void { + this._proxy.$acceptTerminalOpened(terminalInstance.id, terminalInstance.title); + } + private _onTerminalProcessIdReady(terminalInstance: ITerminalInstance): void { this._proxy.$acceptTerminalProcessId(terminalInstance.id, terminalInstance.processId); } diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index da7a17f7d25..3ccab97e133 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -351,6 +351,9 @@ export function createApiFactory( onDidCloseTerminal(listener, thisArg?, disposables?) { return extHostTerminalService.onDidCloseTerminal(listener, thisArg, disposables); }, + onDidOpenTerminal(listener, thisArg?, disposables?) { + return extHostTerminalService.onDidOpenTerminal(listener, thisArg, disposables); + }, get state() { return extHostWindow.state; }, diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index 44e0ba2ce5b..c2902a8e204 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -728,6 +728,7 @@ export interface ExtHostQuickOpenShape { export interface ExtHostTerminalServiceShape { $acceptTerminalClosed(id: number): void; + $acceptTerminalOpened(id: number, name: string): void; $acceptTerminalProcessId(id: number, processId: number): void; } diff --git a/src/vs/workbench/api/node/extHostTerminalService.ts b/src/vs/workbench/api/node/extHostTerminalService.ts index 2a0f3081e2b..c0331705cf5 100644 --- a/src/vs/workbench/api/node/extHostTerminalService.ts +++ b/src/vs/workbench/api/node/extHostTerminalService.ts @@ -20,12 +20,7 @@ export class ExtHostTerminal implements vscode.Terminal { constructor( proxy: MainThreadTerminalServiceShape, - name?: string, - shellPath?: string, - shellArgs?: string[], - cwd?: string, - env?: { [key: string]: string }, - waitOnExit?: boolean + name?: string ) { this._name = name; this._queuedRequests = []; @@ -33,8 +28,16 @@ export class ExtHostTerminal implements vscode.Terminal { this._pidPromise = new Promise(c => { this._pidPromiseComplete = c; }); + } - this._proxy.$createTerminal(name, shellPath, shellArgs, cwd, env, waitOnExit).then((id) => { + public create( + shellPath?: string, + shellArgs?: string[], + cwd?: string, + env?: { [key: string]: string }, + waitOnExit?: boolean + ): void { + this._proxy.$createTerminal(this._name, shellPath, shellArgs, cwd, env, waitOnExit).then((id) => { this._id = id; this._queuedRequests.forEach((r) => { r.run(this._proxy, this._id); @@ -99,23 +102,27 @@ export class ExtHostTerminal implements vscode.Terminal { export class ExtHostTerminalService implements ExtHostTerminalServiceShape { private readonly _onDidCloseTerminal: Emitter; + private readonly _onDidOpenTerminal: Emitter; private _proxy: MainThreadTerminalServiceShape; private _terminals: ExtHostTerminal[]; constructor(mainContext: IMainContext) { this._onDidCloseTerminal = new Emitter(); + this._onDidOpenTerminal = new Emitter(); this._proxy = mainContext.getProxy(MainContext.MainThreadTerminalService); this._terminals = []; } public createTerminal(name?: string, shellPath?: string, shellArgs?: string[]): vscode.Terminal { - let terminal = new ExtHostTerminal(this._proxy, name, shellPath, shellArgs); + let terminal = new ExtHostTerminal(this._proxy, name); + terminal.create(shellPath, shellArgs); this._terminals.push(terminal); return terminal; } public createTerminalFromOptions(options: vscode.TerminalOptions): vscode.Terminal { - let terminal = new ExtHostTerminal(this._proxy, options.name, options.shellPath, options.shellArgs, options.cwd, options.env /*, options.waitOnExit*/); + let terminal = new ExtHostTerminal(this._proxy, options.name); + terminal.create(options.shellPath, options.shellArgs, options.cwd, options.env /*, options.waitOnExit*/); this._terminals.push(terminal); return terminal; } @@ -124,6 +131,10 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape { return this._onDidCloseTerminal && this._onDidCloseTerminal.event; } + public get onDidOpenTerminal(): Event { + return this._onDidOpenTerminal && this._onDidOpenTerminal.event; + } + public $acceptTerminalClosed(id: number): void { let index = this._getTerminalIndexById(id); if (index === null) { @@ -134,6 +145,15 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape { this._onDidCloseTerminal.fire(terminal); } + // TOOD: How do we set PID + // TODO: Make sure both API terminals and non-API terminals are created correctly + public $acceptTerminalOpened(id: number, name: string): void { + // TODO: Only create a terminal if it doesn't already exist for the ID + let terminal = new ExtHostTerminal(this._proxy, name); + this._terminals.push(terminal); + this._onDidOpenTerminal.fire(terminal); + } + public $acceptTerminalProcessId(id: number, processId: number): void { let terminal = this._getTerminalById(id); if (terminal) { diff --git a/src/vs/workbench/parts/terminal/common/terminal.ts b/src/vs/workbench/parts/terminal/common/terminal.ts index ed019f21ef7..2fcfe1c89b7 100644 --- a/src/vs/workbench/parts/terminal/common/terminal.ts +++ b/src/vs/workbench/parts/terminal/common/terminal.ts @@ -149,6 +149,7 @@ export interface ITerminalService { configHelper: ITerminalConfigHelper; onActiveTabChanged: Event; onTabDisposed: Event; + onInstanceCreated: Event; onInstanceDisposed: Event; onInstanceProcessIdReady: Event; onInstancesChanged: Event; diff --git a/src/vs/workbench/parts/terminal/common/terminalService.ts b/src/vs/workbench/parts/terminal/common/terminalService.ts index 104182733c6..a3534b05ff0 100644 --- a/src/vs/workbench/parts/terminal/common/terminalService.ts +++ b/src/vs/workbench/parts/terminal/common/terminalService.ts @@ -24,6 +24,7 @@ export abstract class TerminalService implements ITerminalService { protected _terminalContainer: HTMLElement; protected _onInstancesChanged: Emitter; protected _onTabDisposed: Emitter; + protected _onInstanceCreated: Emitter; protected _onInstanceDisposed: Emitter; protected _onInstanceProcessIdReady: Emitter; protected _onInstanceTitleChanged: Emitter; @@ -36,6 +37,7 @@ export abstract class TerminalService implements ITerminalService { public get activeTabIndex(): number { return this._activeTabIndex; } public get onActiveTabChanged(): Event { return this._onActiveTabChanged.event; } public get onTabDisposed(): Event { return this._onTabDisposed.event; } + public get onInstanceCreated(): Event { return this._onInstanceCreated.event; } public get onInstanceDisposed(): Event { return this._onInstanceDisposed.event; } public get onInstanceProcessIdReady(): Event { return this._onInstanceProcessIdReady.event; } public get onInstanceTitleChanged(): Event { return this._onInstanceTitleChanged.event; } @@ -57,6 +59,7 @@ export abstract class TerminalService implements ITerminalService { this._onActiveTabChanged = new Emitter(); this._onTabDisposed = new Emitter(); + this._onInstanceCreated = new Emitter(); this._onInstanceDisposed = new Emitter(); this._onInstanceProcessIdReady = new Emitter(); this._onInstanceTitleChanged = new Emitter(); diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalService.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalService.ts index a09efd1925d..715cf6d3609 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalService.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalService.ts @@ -82,6 +82,7 @@ export class TerminalService extends AbstractTerminalService implements ITermina // It's the first instance so it should be made active automatically this.setActiveInstanceByIndex(0); } + this._onInstanceCreated.fire(instance); this._onInstancesChanged.fire(); this._suggestShellChange(wasNewTerminalAction); return instance; diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalTab.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalTab.ts index 55eb0c497b3..30b324f6b3d 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalTab.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalTab.ts @@ -402,6 +402,8 @@ export class TerminalTab extends Disposable implements ITerminalTab { shellLaunchConfig); this._terminalInstances.splice(this._activeInstanceIndex + 1, 0, instance); this._initInstanceListeners(instance); + // TODO: Ensure change event is fired + // TODO: Fire create event on service this._setActiveInstance(instance); if (this._splitPaneContainer) {