diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index e92fbd3d494f..ea2503ba6e3b 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -141,9 +141,9 @@ export class TerminalService implements ITerminalService, Disposable { } } // TODO: Debt switch to Promise ---> breaks 20 tests - public async ensureTerminal(preserveFocus: boolean = true): Promise { + public async ensureTerminal(preserveFocus: boolean = true): Promise { if (this.terminal) { - return; + return this.terminal; } if (useEnvExtension()) { @@ -174,7 +174,7 @@ export class TerminalService implements ITerminalService, Disposable { } this.sendTelemetry().ignoreErrors(); - return; + return this.terminal; } private terminalCloseHandler(terminal: Terminal) { if (terminal === this.terminal) { diff --git a/src/client/common/terminal/syncTerminalService.ts b/src/client/common/terminal/syncTerminalService.ts index 0b46a86ee51e..c1e7a655e94d 100644 --- a/src/client/common/terminal/syncTerminalService.ts +++ b/src/client/common/terminal/syncTerminalService.ts @@ -4,7 +4,7 @@ 'use strict'; import { inject } from 'inversify'; -import { CancellationToken, Disposable, Event, TerminalShellExecution } from 'vscode'; +import { CancellationToken, Disposable, Event, Terminal, TerminalShellExecution } from 'vscode'; import { IInterpreterService } from '../../interpreter/contracts'; import { traceVerbose } from '../../logging'; import { PythonEnvironment } from '../../pythonEnvironments/info'; @@ -152,6 +152,17 @@ export class SynchronousTerminalService implements ITerminalService, Disposable return this.terminalService.show(preserveFocus); } + /** + * Ensures that a terminal exists, creating one if necessary. + * + * @param {boolean} [preserveFocus] Whether the editor should keep focus after the terminal is shown. Defaults to `true`. + * @returns {Promise} The terminal instance. + * @memberof SynchronousTerminalService + */ + public async ensureTerminal(preserveFocus: boolean = true): Promise { + return this.terminalService.ensureTerminal(preserveFocus); + } + private createLockFile(): Promise { return this.fs.createTemporaryFile('.log').then((l) => { this.disposables.push(l); diff --git a/src/client/common/terminal/types.ts b/src/client/common/terminal/types.ts index 3e54458a57fd..cbc2b6fd5a51 100644 --- a/src/client/common/terminal/types.ts +++ b/src/client/common/terminal/types.ts @@ -56,6 +56,14 @@ export interface ITerminalService extends IDisposable { sendText(text: string): Promise; executeCommand(commandLine: string, isPythonShell: boolean): Promise; show(preserveFocus?: boolean): Promise; + /** + * Ensures that a terminal exists, creating one if necessary. + * + * @param {boolean} [preserveFocus] Whether the editor should keep focus after the terminal is shown. Defaults to `true`. + * @returns {Promise} The terminal instance. + * @memberof ITerminalService + */ + ensureTerminal(preserveFocus?: boolean): Promise; } export const ITerminalServiceFactory = Symbol('ITerminalServiceFactory');