Skip to content

Commit

Permalink
Recreate pid promise when reusing terminals
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyriar committed Dec 13, 2018
1 parent 461bf72 commit e6254db
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
this._toDispose.push(terminalService.onInstanceRequestExtHostProcess(request => this._onTerminalRequestExtHostProcess(request)));
this._toDispose.push(terminalService.onActiveInstanceChanged(instance => this._onActiveTerminalChanged(instance ? instance.id : undefined)));
this._toDispose.push(terminalService.onInstanceTitleChanged(instance => this._onTitleChanged(instance.id, instance.title)));
this._toDispose.push(terminalService.onInstanceProcessLaunching(instance => this._onProcessLaunching(instance.id)));

// Set initial ext host state
this.terminalService.terminalInstances.forEach(t => {
Expand Down Expand Up @@ -173,10 +172,6 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
this._proxy.$acceptTerminalTitleChange(terminalId, name);
}

private _onProcessLaunching(terminalId: number): void {
this._proxy.$acceptTerminalProcessLaunching(terminalId);
}

private _onTerminalRendererInput(terminalId: number, data: string): void {
this._proxy.$acceptTerminalRendererInput(terminalId, data);
}
Expand Down
1 change: 0 additions & 1 deletion src/vs/workbench/api/node/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,6 @@ export interface ExtHostTerminalServiceShape {
$acceptTerminalProcessId(id: number, processId: number): void;
$acceptTerminalProcessData(id: number, data: string): void;
$acceptTerminalRendererInput(id: number, data: string): void;
$acceptTerminalProcessLaunching(id: number): void;
$acceptTerminalTitleChange(id: number, name: string): void;
$acceptTerminalRendererDimensions(id: number, cols: number, rows: number): void;
$createProcess(id: number, shellLaunchConfig: ShellLaunchConfigDto, activeWorkspaceRootUri: URI, cols: number, rows: number): void;
Expand Down
29 changes: 14 additions & 15 deletions src/vs/workbench/api/node/extHostTerminalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ export class ExtHostTerminal extends BaseExtHostTerminal implements vscode.Termi
pid?: number
) {
super(proxy, id);
this._createProcessIdPromise(pid);
this._pidPromise = new Promise<number>(c => {
if (pid === RENDERER_NO_PROCESS_ID) {
c(undefined);
} else {
this._pidPromiseComplete = c;
}
});
}

public create(
Expand Down Expand Up @@ -133,21 +139,18 @@ export class ExtHostTerminal extends BaseExtHostTerminal implements vscode.Termi
this._queueApiRequest(this._proxy.$hide, []);
}

public _createProcessIdPromise(pid?: number): void {
this._pidPromise = new Promise<number>(c => {
if (pid === RENDERER_NO_PROCESS_ID) {
c(undefined);
} else {
this._pidPromiseComplete = c;
}
});
}

public _setProcessId(processId: number): void {
// The event may fire 2 times when the panel is restored
if (this._pidPromiseComplete) {
this._pidPromiseComplete(processId);
this._pidPromiseComplete = null;
} else {
// Recreate the promise if this is the nth processId set (eg. reused task terminals)
this._pidPromise.then(pid => {
if (pid !== processId) {
this._pidPromise = Promise.resolve(processId);
}
});
}
}

Expand Down Expand Up @@ -355,10 +358,6 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape {
this._performTerminalIdAction(id, terminal => terminal._setProcessId(processId));
}

public $acceptTerminalProcessLaunching(id: number): void {
this._performTerminalIdAction(id, terminal => terminal._createProcessIdPromise());
}

private _performTerminalIdAction(id: number, callback: (terminal: ExtHostTerminal) => void): void {
let terminal = this._getTerminalById(id);
if (terminal) {
Expand Down
3 changes: 0 additions & 3 deletions src/vs/workbench/parts/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ export interface ITerminalService {
onTabDisposed: Event<ITerminalTab>;
onInstanceCreated: Event<ITerminalInstance>;
onInstanceDisposed: Event<ITerminalInstance>;
onInstanceProcessLaunching: Event<ITerminalInstance>;
onInstanceProcessIdReady: Event<ITerminalInstance>;
onInstanceDimensionsChanged: Event<ITerminalInstance>;
onInstanceRequestExtHostProcess: Event<ITerminalProcessExtHostRequest>;
Expand Down Expand Up @@ -323,8 +322,6 @@ export interface ITerminalInstance {

onFocused: Event<ITerminalInstance>;

onProcessLaunching: Event<ITerminalInstance>;

onProcessIdReady: Event<ITerminalInstance>;

onRequestExtHostProcess: Event<ITerminalInstance>;
Expand Down
3 changes: 0 additions & 3 deletions src/vs/workbench/parts/terminal/common/terminalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ export abstract class TerminalService implements ITerminalService {
public get onInstancesChanged(): Event<void> { return this._onInstancesChanged.event; }
protected readonly _onInstanceTitleChanged: Emitter<ITerminalInstance> = new Emitter<ITerminalInstance>();
public get onInstanceTitleChanged(): Event<ITerminalInstance> { return this._onInstanceTitleChanged.event; }
protected readonly _onInstanceProcessLaunching: Emitter<ITerminalInstance> = new Emitter<ITerminalInstance>();
public get onInstanceProcessLaunching(): Event<ITerminalInstance> { return this._onInstanceProcessLaunching.event; }
protected readonly _onActiveInstanceChanged: Emitter<ITerminalInstance> = new Emitter<ITerminalInstance>();
public get onActiveInstanceChanged(): Event<ITerminalInstance> { return this._onActiveInstanceChanged.event; }
protected readonly _onTabDisposed: Emitter<ITerminalTab> = new Emitter<ITerminalTab>();
Expand Down Expand Up @@ -288,7 +286,6 @@ export abstract class TerminalService implements ITerminalService {
instance.addDisposable(instance.onTitleChanged(this._onInstanceTitleChanged.fire, this._onInstanceTitleChanged));
instance.addDisposable(instance.onProcessIdReady(this._onInstanceProcessIdReady.fire, this._onInstanceProcessIdReady));
instance.addDisposable(instance.onDimensionsChanged(() => this._onInstanceDimensionsChanged.fire(instance)));
instance.addDisposable(instance.onProcessLaunching(() => this._onInstanceProcessLaunching.fire(instance)));
instance.addDisposable(instance.onFocus(this._onActiveInstanceChanged.fire, this._onActiveInstanceChanged));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ export class TerminalInstance implements ITerminalInstance {
public get onProcessIdReady(): Event<ITerminalInstance> { return this._onProcessIdReady.event; }
private readonly _onTitleChanged: Emitter<ITerminalInstance> = new Emitter<ITerminalInstance>();
public get onTitleChanged(): Event<ITerminalInstance> { return this._onTitleChanged.event; }
private readonly _onProcessLaunching: Emitter<ITerminalInstance> = new Emitter<ITerminalInstance>();
public get onProcessLaunching(): Event<ITerminalInstance> { return this._onProcessLaunching.event; }
private readonly _onData: Emitter<string> = new Emitter<string>();
public get onData(): Event<string> { return this._onData.event; }
private readonly _onLineData: Emitter<string> = new Emitter<string>();
Expand Down Expand Up @@ -786,8 +784,6 @@ export class TerminalInstance implements ITerminalInstance {
this._processManager.onProcessExit(exitCode => this._onProcessExit(exitCode));
this._processManager.onProcessData(data => this._onData.fire(data));

this._onProcessLaunching.fire(this);

if (this._shellLaunchConfig.name) {
this.setTitle(this._shellLaunchConfig.name, false);
} else {
Expand Down

0 comments on commit e6254db

Please sign in to comment.