提交 41d06331 编写于 作者: G Gabriel DeBacker

Address code review feedback

上级 998b70c7
...@@ -1254,12 +1254,15 @@ declare module 'vscode' { ...@@ -1254,12 +1254,15 @@ declare module 'vscode' {
/** /**
* @param callback The callback that will be called when the extension callback task is executed. * @param callback The callback that will be called when the extension callback task is executed.
*/ */
constructor(callback: (terminalRenderer: TerminalRenderer, cancellationToken: CancellationToken, thisArg?: any) => Thenable<number | undefined>); constructor(callback: (terminalRenderer: TerminalRenderer, cancellationToken: CancellationToken, thisArg?: any) => Thenable<number>);
/** /**
* The callback used to execute the task. * The callback used to execute the task.
* @param terminalRenderer Used by the task to render output and receive input.
* @param cancellationToken Cancellation used to signal a cancel request to the executing task.
* @returns The callback should return '0' for success and a non-zero value for failure.
*/ */
callback: (terminalRenderer: TerminalRenderer, cancellationToken: CancellationToken, thisArg?: any) => Thenable<number | undefined>; callback: (terminalRenderer: TerminalRenderer, cancellationToken: CancellationToken, thisArg?: any) => Thenable<number>;
} }
/** /**
......
...@@ -1709,9 +1709,9 @@ export enum TaskScope { ...@@ -1709,9 +1709,9 @@ export enum TaskScope {
} }
export class CustomExecution implements vscode.CustomExecution { export class CustomExecution implements vscode.CustomExecution {
private _callback: (args: vscode.TerminalRenderer, cancellationToken: vscode.CancellationToken) => Thenable<number | undefined>; private _callback: (args: vscode.TerminalRenderer, cancellationToken: vscode.CancellationToken) => Thenable<number>;
constructor(callback: (args: vscode.TerminalRenderer, cancellationToken: vscode.CancellationToken) => Thenable<number | undefined>) { constructor(callback: (args: vscode.TerminalRenderer, cancellationToken: vscode.CancellationToken) => Thenable<number>) {
this._callback = callback; this._callback = callback;
} }
...@@ -1722,11 +1722,11 @@ export class CustomExecution implements vscode.CustomExecution { ...@@ -1722,11 +1722,11 @@ export class CustomExecution implements vscode.CustomExecution {
return hash.digest('hex'); return hash.digest('hex');
} }
public set callback(value: (args: vscode.TerminalRenderer, cancellationToken: vscode.CancellationToken) => Thenable<number | undefined>) { public set callback(value: (args: vscode.TerminalRenderer, cancellationToken: vscode.CancellationToken) => Thenable<number>) {
this._callback = value; this._callback = value;
} }
public get callback(): (args: vscode.TerminalRenderer, cancellationToken: vscode.CancellationToken) => Thenable<number | undefined> { public get callback(): (args: vscode.TerminalRenderer, cancellationToken: vscode.CancellationToken) => Thenable<number> {
return this._callback; return this._callback;
} }
} }
......
...@@ -136,5 +136,5 @@ export interface ITaskSystem { ...@@ -136,5 +136,5 @@ export interface ITaskSystem {
terminate(task: Task): Promise<TaskTerminateResponse>; terminate(task: Task): Promise<TaskTerminateResponse>;
terminateAll(): Promise<TaskTerminateResponse[]>; terminateAll(): Promise<TaskTerminateResponse[]>;
revealTask(task: Task): boolean; revealTask(task: Task): boolean;
customExecutionComplete(task: Task, result: number | undefined): Promise<void>; customExecutionComplete(task: Task, result: number): Promise<void>;
} }
\ No newline at end of file
...@@ -718,7 +718,7 @@ class TaskService extends Disposable implements ITaskService { ...@@ -718,7 +718,7 @@ class TaskService extends Disposable implements ITaskService {
this._taskSystemInfos.set(key, info); this._taskSystemInfos.set(key, info);
} }
public extensionCallbackTaskComplete(task: Task, result: number | undefined): Promise<void> { public extensionCallbackTaskComplete(task: Task, result: number): Promise<void> {
if (!this._taskSystem) { if (!this._taskSystem) {
return Promise.resolve(); return Promise.resolve();
} }
......
...@@ -269,7 +269,7 @@ export class TerminalTaskSystem implements ITaskSystem { ...@@ -269,7 +269,7 @@ export class TerminalTaskSystem implements ITaskSystem {
return Object.keys(this.activeTasks).map(key => this.activeTasks[key].task); return Object.keys(this.activeTasks).map(key => this.activeTasks[key].task);
} }
public customExecutionComplete(task: Task, result?: number): Promise<void> { public customExecutionComplete(task: Task, result: number): Promise<void> {
let activeTerminal = this.activeTasks[task.getMapKey()]; let activeTerminal = this.activeTasks[task.getMapKey()];
if (!activeTerminal) { if (!activeTerminal) {
return Promise.reject(new Error('Expected to have a terminal for an custom execution task')); return Promise.reject(new Error('Expected to have a terminal for an custom execution task'));
......
...@@ -208,8 +208,8 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -208,8 +208,8 @@ export class TerminalInstance implements ITerminalInstance {
public get shellLaunchConfig(): IShellLaunchConfig { return this._shellLaunchConfig; } public get shellLaunchConfig(): IShellLaunchConfig { return this._shellLaunchConfig; }
public get commandTracker(): TerminalCommandTracker { return this._commandTracker; } public get commandTracker(): TerminalCommandTracker { return this._commandTracker; }
private readonly _onExit = new Emitter<number | undefined>(); private readonly _onExit = new Emitter<number>();
public get onExit(): Event<number | undefined> { return this._onExit.event; } public get onExit(): Event<number> { return this._onExit.event; }
private readonly _onDisposed = new Emitter<ITerminalInstance>(); private readonly _onDisposed = new Emitter<ITerminalInstance>();
public get onDisposed(): Event<ITerminalInstance> { return this._onDisposed.event; } public get onDisposed(): Event<ITerminalInstance> { return this._onDisposed.event; }
private readonly _onFocused = new Emitter<ITerminalInstance>(); private readonly _onFocused = new Emitter<ITerminalInstance>();
...@@ -731,8 +731,8 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -731,8 +731,8 @@ export class TerminalInstance implements ITerminalInstance {
} else { } else {
// In cases where there is no associated process (for example executing an extension callback task) // In cases where there is no associated process (for example executing an extension callback task)
// consumers still expect on onExit event to be fired. An example of this is terminating the extension callback // consumers still expect on onExit event to be fired. An example of this is terminating the extension callback
// task. There is no exit code at this point, so firing undefined is appropriate. // task.
this._onExit.fire(undefined); this._onExit.fire(0);
} }
if (!this._isDisposed) { if (!this._isDisposed) {
...@@ -742,7 +742,7 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -742,7 +742,7 @@ export class TerminalInstance implements ITerminalInstance {
this._disposables = lifecycle.dispose(this._disposables); this._disposables = lifecycle.dispose(this._disposables);
} }
public rendererExit(result?: number): void { public rendererExit(result: number): void {
// The use of this API is for cases where there is no backing process // The use of this API is for cases where there is no backing process
// behind a terminal instance (such as when executing an custom execution task). // behind a terminal instance (such as when executing an custom execution task).
// There is no associated string, error text, etc, as the consumer of the renderer // There is no associated string, error text, etc, as the consumer of the renderer
...@@ -918,13 +918,8 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -918,13 +918,8 @@ export class TerminalInstance implements ITerminalInstance {
* Called when either a process tied to a terminal has exited or when a custom execution has completed. * Called when either a process tied to a terminal has exited or when a custom execution has completed.
* @param exitCode The exit code can be undefined if the terminal was exited through user action or if a custom execution callback did not provide a exit code when it finished. * @param exitCode The exit code can be undefined if the terminal was exited through user action or if a custom execution callback did not provide a exit code when it finished.
*/ */
private _onProcessOrExtensionCallbackExit(exitCode?: number): void { private _onProcessOrExtensionCallbackExit(exitCode: number): void {
// Use 'typeof exitCode' because simply doing if (exitCode) would return false for both "not undefined" and a value of 0
// which is not the intention.
const isExitCodeSpecified: boolean = (typeof exitCode === `number`);
if (exitCode) {
this._logService.debug(`Terminal process exit (id: ${this.id}) with code ${exitCode}`); this._logService.debug(`Terminal process exit (id: ${this.id}) with code ${exitCode}`);
}
// Prevent dispose functions being triggered multiple times // Prevent dispose functions being triggered multiple times
if (this._isExiting) { if (this._isExiting) {
...@@ -932,11 +927,8 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -932,11 +927,8 @@ export class TerminalInstance implements ITerminalInstance {
} }
this._isExiting = true; this._isExiting = true;
let exitCodeMessage: string;
if (isExitCodeSpecified) { const exitCodeMessage: string = nls.localize('terminal.integrated.exitedWithCode', 'The terminal process terminated with exit code: {0}', exitCode);
exitCodeMessage = nls.localize('terminal.integrated.exitedWithCode', 'The terminal process terminated with exit code: {0}', exitCode);
}
if (this._processManager) { if (this._processManager) {
this._logService.debug(`Terminal process exit (id: ${this.id}) state ${this._processManager!.processState}`); this._logService.debug(`Terminal process exit (id: ${this.id}) state ${this._processManager!.processState}`);
...@@ -945,9 +937,7 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -945,9 +937,7 @@ export class TerminalInstance implements ITerminalInstance {
// Only trigger wait on exit when the exit was *not* triggered by the // Only trigger wait on exit when the exit was *not* triggered by the
// user (via the `workbench.action.terminal.kill` command). // user (via the `workbench.action.terminal.kill` command).
if (this._shellLaunchConfig.waitOnExit && (!this._processManager || this._processManager.processState !== ProcessState.KILLED_BY_USER)) { if (this._shellLaunchConfig.waitOnExit && (!this._processManager || this._processManager.processState !== ProcessState.KILLED_BY_USER)) {
if (isExitCodeSpecified) {
this._xterm.writeln(exitCodeMessage!); this._xterm.writeln(exitCodeMessage!);
}
if (typeof this._shellLaunchConfig.waitOnExit === 'string') { if (typeof this._shellLaunchConfig.waitOnExit === 'string') {
let message = this._shellLaunchConfig.waitOnExit; let message = this._shellLaunchConfig.waitOnExit;
// Bold the message and add an extra new line to make it stand out from the rest of the output // Bold the message and add an extra new line to make it stand out from the rest of the output
...@@ -961,7 +951,6 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -961,7 +951,6 @@ export class TerminalInstance implements ITerminalInstance {
} }
} else { } else {
this.dispose(); this.dispose();
if (isExitCodeSpecified) {
if (this._processManager && this._processManager.processState === ProcessState.KILLED_DURING_LAUNCH) { if (this._processManager && this._processManager.processState === ProcessState.KILLED_DURING_LAUNCH) {
let args = ''; let args = '';
if (typeof this._shellLaunchConfig.args === 'string') { if (typeof this._shellLaunchConfig.args === 'string') {
...@@ -987,7 +976,6 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -987,7 +976,6 @@ export class TerminalInstance implements ITerminalInstance {
} }
} }
} }
}
this._onExit.fire(exitCode); this._onExit.fire(exitCode);
} }
...@@ -1007,7 +995,7 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -1007,7 +995,7 @@ export class TerminalInstance implements ITerminalInstance {
public reuseTerminal(shell: IShellLaunchConfig): void { public reuseTerminal(shell: IShellLaunchConfig): void {
// Unsubscribe any key listener we may have. // Unsubscribe any key listener we may have.
if (!this._keyPressListener) { if (this._keyPressListener) {
this._keyPressListener.dispose(); this._keyPressListener.dispose();
this._keyPressListener = undefined; this._keyPressListener = undefined;
} }
...@@ -1037,8 +1025,11 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -1037,8 +1025,11 @@ export class TerminalInstance implements ITerminalInstance {
this._shellLaunchConfig = shell; // Must be done before calling _createProcess() this._shellLaunchConfig = shell; // Must be done before calling _createProcess()
// Launch the process unless this is only a renderer. // Launch the process unless this is only a renderer.
// In the renderer only cases, we still need to set the title correctly.
if (!this._shellLaunchConfig.isRendererOnly) { if (!this._shellLaunchConfig.isRendererOnly) {
this._createProcess(); this._createProcess();
} else if (this._shellLaunchConfig.name) {
this.setTitle(this._shellLaunchConfig.name, false);
} }
if (oldTitle !== this._title) { if (oldTitle !== this._title) {
......
...@@ -390,7 +390,7 @@ export interface ITerminalInstance { ...@@ -390,7 +390,7 @@ export interface ITerminalInstance {
* is the processes' exit code, an exit code of null means the process was killed as a result of * is the processes' exit code, an exit code of null means the process was killed as a result of
* the ITerminalInstance being disposed. * the ITerminalInstance being disposed.
*/ */
onExit: Event<number | undefined>; onExit: Event<number>;
processReady: Promise<void>; processReady: Promise<void>;
...@@ -442,9 +442,9 @@ export interface ITerminalInstance { ...@@ -442,9 +442,9 @@ export interface ITerminalInstance {
/** /**
* Indicates that a consumer of a renderer only terminal is finished with it. * Indicates that a consumer of a renderer only terminal is finished with it.
* *
* @param result - Optional result code from a from a task process or custom execution. * @param result - Result code from a from a task process or custom execution. Zero indicates success, non-zero indicates failure.
*/ */
rendererExit(result?: number): void; rendererExit(result: number): void;
/** /**
* Forces the terminal to redraw its viewport. * Forces the terminal to redraw its viewport.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册