diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index c3b90181d563..de276762de4b 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -58,6 +58,7 @@ export class TerminalService implements ITerminalService, Disposable { if (!this.options?.hideFromUser) { this.terminal!.show(true); } + this.terminal!.sendText(text, true); } public async sendText(text: string): Promise { diff --git a/src/client/providers/replProvider.ts b/src/client/providers/replProvider.ts index db0e459c12dd..ba01dea3390d 100644 --- a/src/client/providers/replProvider.ts +++ b/src/client/providers/replProvider.ts @@ -40,7 +40,7 @@ export class ReplProvider implements Disposable { .then(noop, noop); return; } - const replProvider = this.serviceContainer.get(ICodeExecutionService, 'repl'); + const replProvider = this.serviceContainer.get(ICodeExecutionService, 'standard'); await replProvider.initializeRepl(resource); } } diff --git a/src/client/terminals/codeExecution/terminalCodeExecution.ts b/src/client/terminals/codeExecution/terminalCodeExecution.ts index 4d775dbf6f97..ce317dec20e7 100644 --- a/src/client/terminals/codeExecution/terminalCodeExecution.ts +++ b/src/client/terminals/codeExecution/terminalCodeExecution.ts @@ -17,11 +17,13 @@ import { IInterpreterService } from '../../interpreter/contracts'; import { traceInfo } from '../../logging'; import { buildPythonExecInfo, PythonExecInfo } from '../../pythonEnvironments/exec'; import { ICodeExecutionService } from '../../terminals/types'; + @injectable() export class TerminalCodeExecutionProvider implements ICodeExecutionService { private hasRanOutsideCurrentDrive = false; protected terminalTitle!: string; private replActive?: Promise; + constructor( @inject(ITerminalServiceFactory) protected readonly terminalServiceFactory: ITerminalServiceFactory, @inject(IConfigurationService) protected readonly configurationService: IConfigurationService, @@ -58,12 +60,14 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService { await this.getTerminalService(resource).sendText(code); } } + public async initializeRepl(resource: Resource) { const terminalService = this.getTerminalService(resource); if (this.replActive && (await this.replActive)) { await terminalService.show(); return; } + this.replActive = new Promise(async (resolve) => { const replCommandArgs = await this.getExecutableInfo(resource); let listener: IDisposable; @@ -93,7 +97,8 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService { } resolve(true); }); - terminalService.sendCommand(replCommandArgs.command, replCommandArgs.args); + + await terminalService.sendCommand(replCommandArgs.command, replCommandArgs.args); }); this.disposables.push( terminalService.onDidCloseTerminal(() => { diff --git a/src/test/providers/repl.unit.test.ts b/src/test/providers/repl.unit.test.ts index 87811e243bfd..72adfa95a4a0 100644 --- a/src/test/providers/repl.unit.test.ts +++ b/src/test/providers/repl.unit.test.ts @@ -36,7 +36,7 @@ suite('REPL Provider', () => { serviceContainer.setup((c) => c.get(ICommandManager)).returns(() => commandManager.object); serviceContainer.setup((c) => c.get(IWorkspaceService)).returns(() => workspace.object); serviceContainer - .setup((c) => c.get(ICodeExecutionService, TypeMoq.It.isValue('repl'))) + .setup((s) => s.get(TypeMoq.It.isValue(ICodeExecutionService), TypeMoq.It.isValue('standard'))) .returns(() => codeExecutionService.object); serviceContainer.setup((c) => c.get(IDocumentManager)).returns(() => documentManager.object); serviceContainer.setup((c) => c.get(IActiveResourceService)).returns(() => activeResourceService.object); @@ -80,6 +80,7 @@ suite('REPL Provider', () => { const resource = Uri.parse('a'); const disposable = TypeMoq.Mock.ofType(); let commandHandler: undefined | (() => Promise); + commandManager .setup((c) => c.registerCommand(TypeMoq.It.isValue(Commands.Start_REPL), TypeMoq.It.isAny(), TypeMoq.It.isAny()), @@ -98,7 +99,7 @@ suite('REPL Provider', () => { await commandHandler!.call(replProvider); serviceContainer.verify( - (c) => c.get(TypeMoq.It.isValue(ICodeExecutionService), TypeMoq.It.isValue('repl')), + (c) => c.get(TypeMoq.It.isValue(ICodeExecutionService), TypeMoq.It.isValue('standard')), TypeMoq.Times.once(), ); codeExecutionService.verify((c) => c.initializeRepl(TypeMoq.It.isValue(resource)), TypeMoq.Times.once());