Skip to content

Commit 165686e

Browse files
authored
Merge pull request microsoft#47987 from Microsoft/tyriar/terminal_process_refactor
Separate terminal instance from terminal process
2 parents e592885 + aa85bbb commit 165686e

27 files changed

Lines changed: 733 additions & 700 deletions

src/vs/workbench/api/electron-browser/mainThreadTerminalService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
5555
ignoreConfigurationCwd: true,
5656
env
5757
};
58-
return TPromise.as(this.terminalService.createInstance(shellLaunchConfig).id);
58+
return TPromise.as(this.terminalService.createTerminal(shellLaunchConfig).id);
5959
}
6060

6161
public $show(terminalId: number, preserveFocus: boolean): void {

src/vs/workbench/parts/debug/electron-browser/terminalSupport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class TerminalLauncher implements ITerminalLauncher {
4242

4343
let t = this.integratedTerminalInstance;
4444
if ((t && this.isBusy(t)) || !t) {
45-
t = this.terminalService.createInstance({ name: args.title || nls.localize('debug.terminal.title', "debuggee") });
45+
t = this.terminalService.createTerminal({ name: args.title || nls.localize('debug.terminal.title', "debuggee") });
4646
this.integratedTerminalInstance = t;
4747
}
4848
this.terminalService.setActiveInstance(t);

src/vs/workbench/parts/execution/electron-browser/execution.contribution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ CommandsRegistry.registerCommand({
9191
const directoriesToOpen = distinct(stats.map(({ stat }) => stat.isDirectory ? stat.resource.fsPath : paths.dirname(stat.resource.fsPath)));
9292
return directoriesToOpen.map(dir => {
9393
if (configurationService.getValue<ITerminalConfiguration>().terminal.explorerKind === 'integrated') {
94-
const instance = integratedTerminalService.createInstance({ cwd: dir }, true);
94+
const instance = integratedTerminalService.createTerminal({ cwd: dir }, true);
9595
if (instance && (resources.length === 1 || !resource || dir === resource.fsPath || dir === paths.dirname(resource.fsPath))) {
9696
integratedTerminalService.setActiveInstance(instance);
9797
integratedTerminalService.showPanel(true);

src/vs/workbench/parts/tasks/electron-browser/terminalTaskSystem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ export class TerminalTaskSystem implements ITaskSystem {
571571
return [terminalToReuse.terminal, commandExecutable];
572572
}
573573

574-
const result = this.terminalService.createInstance(shellLaunchConfig);
574+
const result = this.terminalService.createTerminal(shellLaunchConfig);
575575
const terminalKey = result.id.toString();
576576
result.onDisposed((terminal) => {
577577
let terminalData = this.terminals[terminalKey];

src/vs/workbench/parts/terminal/electron-browser/terminalFindWidget.ts renamed to src/vs/workbench/parts/terminal/browser/terminalFindWidget.ts

File renamed without changes.

src/vs/workbench/parts/terminal/browser/terminalQuickOpen.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* Copyright (c) Microsoft Corporation. All rights reserved.
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
5-
'use strict';
65

76
import * as nls from 'vs/nls';
87
import { TPromise } from 'vs/base/common/winjs.base';

src/vs/workbench/parts/terminal/electron-browser/terminalTab.ts renamed to src/vs/workbench/parts/terminal/browser/terminalTab.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { ITerminalInstance, IShellLaunchConfig, ITerminalTab, Direction, ITerminalService } from 'vs/workbench/parts/terminal/common/terminal';
7-
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
8-
import { TerminalConfigHelper } from 'vs/workbench/parts/terminal/electron-browser/terminalConfigHelper';
6+
import { ITerminalInstance, IShellLaunchConfig, ITerminalTab, Direction, ITerminalService, ITerminalConfigHelper } from 'vs/workbench/parts/terminal/common/terminal';
97
import { IContextKey } from 'vs/platform/contextkey/common/contextkey';
10-
import { TerminalInstance } from 'vs/workbench/parts/terminal/electron-browser/terminalInstance';
118
import { Event, Emitter, anyEvent } from 'vs/base/common/event';
129
import { IDisposable, Disposable } from 'vs/base/common/lifecycle';
1310
import { SplitView, Orientation, IView } from 'vs/base/browser/ui/splitview/splitview';
@@ -255,22 +252,22 @@ export class TerminalTab extends Disposable implements ITerminalTab {
255252

256253
constructor(
257254
terminalFocusContextKey: IContextKey<boolean>,
258-
configHelper: TerminalConfigHelper,
255+
configHelper: ITerminalConfigHelper,
259256
private _container: HTMLElement,
260257
shellLaunchConfig: IShellLaunchConfig,
261-
@IInstantiationService private readonly _instantiationService: IInstantiationService,
262258
@ITerminalService private readonly _terminalService: ITerminalService,
263259
@IPartService private readonly _partService: IPartService
264260
) {
265261
super();
266262
this._onDisposed = new Emitter<ITerminalTab>();
267263
this._onInstancesChanged = new Emitter<void>();
268264

269-
const instance = this._instantiationService.createInstance(TerminalInstance,
265+
const instance = this._terminalService.createInstance(
270266
terminalFocusContextKey,
271267
configHelper,
272268
undefined,
273-
shellLaunchConfig);
269+
shellLaunchConfig,
270+
true);
274271
this._terminalInstances.push(instance);
275272
this._initInstanceListeners(instance);
276273
this._activeInstanceIndex = 0;
@@ -392,14 +389,15 @@ export class TerminalTab extends Disposable implements ITerminalTab {
392389

393390
public split(
394391
terminalFocusContextKey: IContextKey<boolean>,
395-
configHelper: TerminalConfigHelper,
392+
configHelper: ITerminalConfigHelper,
396393
shellLaunchConfig: IShellLaunchConfig
397394
): ITerminalInstance {
398-
const instance = this._instantiationService.createInstance(TerminalInstance,
395+
const instance = this._terminalService.createInstance(
399396
terminalFocusContextKey,
400397
configHelper,
401398
undefined,
402-
shellLaunchConfig);
399+
shellLaunchConfig,
400+
true);
403401
this._terminalInstances.splice(this._activeInstanceIndex + 1, 0, instance);
404402
this._initInstanceListeners(instance);
405403
this._setActiveInstance(instance);

src/vs/workbench/parts/terminal/common/terminal.ts

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* Copyright (c) Microsoft Corporation. All rights reserved.
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
5-
'use strict';
65

76
import { Event } from 'vs/base/common/event';
87
import { IDisposable } from 'vs/base/common/lifecycle';
@@ -157,7 +156,17 @@ export interface ITerminalService {
157156
terminalInstances: ITerminalInstance[];
158157
terminalTabs: ITerminalTab[];
159158

160-
createInstance(shell?: IShellLaunchConfig, wasNewTerminalAction?: boolean): ITerminalInstance;
159+
/**
160+
* Creates a terminal.
161+
* @param shell The shell launch configuration to use.
162+
* @param wasNewTerminalAction Whether this was triggered by a new terminal action, if so a
163+
* default shell selection dialog may display.
164+
*/
165+
createTerminal(shell?: IShellLaunchConfig, wasNewTerminalAction?: boolean): ITerminalInstance;
166+
/**
167+
* Creates a raw terminal instance, this should not be used outside of the terminal part.
168+
*/
169+
createInstance(terminalFocusContextKey: IContextKey<boolean>, configHelper: ITerminalConfigHelper, container: HTMLElement, shellLaunchConfig: IShellLaunchConfig, doCreateProcess: boolean): ITerminalInstance;
161170
getInstanceFromId(terminalId: number): ITerminalInstance;
162171
getInstanceFromIndex(terminalIndex: number): ITerminalInstance;
163172
getTabLabels(): string[];
@@ -456,3 +465,44 @@ export interface ITerminalCommandTracker {
456465
selectToPreviousCommand(): void;
457466
selectToNextCommand(): void;
458467
}
468+
469+
export interface ITerminalProcessMessage {
470+
type: 'pid' | 'data' | 'title';
471+
content: number | string;
472+
}
473+
474+
export interface ITerminalProcessManager extends IDisposable {
475+
readonly processState: ProcessState;
476+
readonly ptyProcessReady: TPromise<void>;
477+
readonly shellProcessId: number;
478+
readonly initialCwd: string;
479+
480+
readonly onProcessReady: Event<void>;
481+
readonly onProcessData: Event<string>;
482+
readonly onProcessTitle: Event<string>;
483+
readonly onProcessExit: Event<number>;
484+
485+
addDisposable(disposable: IDisposable);
486+
createProcess(shellLaunchConfig: IShellLaunchConfig, cols: number, rows: number);
487+
write(data: string): void;
488+
setDimensions(cols: number, rows: number): void;
489+
}
490+
491+
export enum ProcessState {
492+
// The process has not been initialized yet.
493+
UNINITIALIZED,
494+
// The process is currently launching, the process is marked as launching
495+
// for a short duration after being created and is helpful to indicate
496+
// whether the process died as a result of bad shell and args.
497+
LAUNCHING,
498+
// The process is running normally.
499+
RUNNING,
500+
// The process was killed during launch, likely as a result of bad shell and
501+
// args.
502+
KILLED_DURING_LAUNCH,
503+
// The process was killed by the user (the event originated from VS Code).
504+
KILLED_BY_USER,
505+
// The process was killed by itself, for example the shell crashed or `exit`
506+
// was run.
507+
KILLED_BY_PROCESS
508+
}

src/vs/workbench/parts/terminal/electron-browser/terminalColorRegistry.ts renamed to src/vs/workbench/parts/terminal/common/terminalColorRegistry.ts

File renamed without changes.

src/vs/workbench/parts/terminal/electron-browser/terminalCommands.ts renamed to src/vs/workbench/parts/terminal/common/terminalCommands.ts

File renamed without changes.

0 commit comments

Comments
 (0)