Skip to content

Commit 10f9613

Browse files
anthonykim1DonJayamanne
authored andcommitted
Unify Terminal REPL triggers (#23641)
Resolves: microsoft#22242 Attempting to keep instance of REPL. Did not end up using shell integration for this, but shell integration and exit code will come in handy when we have to keep track of 'opened' state of REPL instance for cases when user wants to enter 'exit()'
1 parent 42b8eac commit 10f9613

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

src/client/common/terminal/service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export class TerminalService implements ITerminalService, Disposable {
5858
if (!this.options?.hideFromUser) {
5959
this.terminal!.show(true);
6060
}
61+
6162
this.terminal!.sendText(text, true);
6263
}
6364
public async sendText(text: string): Promise<void> {

src/client/providers/replProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class ReplProvider implements Disposable {
4040
.then(noop, noop);
4141
return;
4242
}
43-
const replProvider = this.serviceContainer.get<ICodeExecutionService>(ICodeExecutionService, 'repl');
43+
const replProvider = this.serviceContainer.get<ICodeExecutionService>(ICodeExecutionService, 'standard');
4444
await replProvider.initializeRepl(resource);
4545
}
4646
}

src/client/terminals/codeExecution/terminalCodeExecution.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ import { IInterpreterService } from '../../interpreter/contracts';
1717
import { traceInfo } from '../../logging';
1818
import { buildPythonExecInfo, PythonExecInfo } from '../../pythonEnvironments/exec';
1919
import { ICodeExecutionService } from '../../terminals/types';
20+
2021
@injectable()
2122
export class TerminalCodeExecutionProvider implements ICodeExecutionService {
2223
private hasRanOutsideCurrentDrive = false;
2324
protected terminalTitle!: string;
2425
private replActive?: Promise<boolean>;
26+
2527
constructor(
2628
@inject(ITerminalServiceFactory) protected readonly terminalServiceFactory: ITerminalServiceFactory,
2729
@inject(IConfigurationService) protected readonly configurationService: IConfigurationService,
@@ -58,12 +60,14 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService {
5860
await this.getTerminalService(resource).sendText(code);
5961
}
6062
}
63+
6164
public async initializeRepl(resource: Resource) {
6265
const terminalService = this.getTerminalService(resource);
6366
if (this.replActive && (await this.replActive)) {
6467
await terminalService.show();
6568
return;
6669
}
70+
6771
this.replActive = new Promise<boolean>(async (resolve) => {
6872
const replCommandArgs = await this.getExecutableInfo(resource);
6973
let listener: IDisposable;
@@ -93,7 +97,8 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService {
9397
}
9498
resolve(true);
9599
});
96-
terminalService.sendCommand(replCommandArgs.command, replCommandArgs.args);
100+
101+
await terminalService.sendCommand(replCommandArgs.command, replCommandArgs.args);
97102
});
98103
this.disposables.push(
99104
terminalService.onDidCloseTerminal(() => {

src/test/providers/repl.unit.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ suite('REPL Provider', () => {
3636
serviceContainer.setup((c) => c.get(ICommandManager)).returns(() => commandManager.object);
3737
serviceContainer.setup((c) => c.get(IWorkspaceService)).returns(() => workspace.object);
3838
serviceContainer
39-
.setup((c) => c.get(ICodeExecutionService, TypeMoq.It.isValue('repl')))
39+
.setup((s) => s.get(TypeMoq.It.isValue(ICodeExecutionService), TypeMoq.It.isValue('standard')))
4040
.returns(() => codeExecutionService.object);
4141
serviceContainer.setup((c) => c.get(IDocumentManager)).returns(() => documentManager.object);
4242
serviceContainer.setup((c) => c.get(IActiveResourceService)).returns(() => activeResourceService.object);
@@ -80,6 +80,7 @@ suite('REPL Provider', () => {
8080
const resource = Uri.parse('a');
8181
const disposable = TypeMoq.Mock.ofType<Disposable>();
8282
let commandHandler: undefined | (() => Promise<void>);
83+
8384
commandManager
8485
.setup((c) =>
8586
c.registerCommand(TypeMoq.It.isValue(Commands.Start_REPL), TypeMoq.It.isAny(), TypeMoq.It.isAny()),
@@ -98,7 +99,7 @@ suite('REPL Provider', () => {
9899
await commandHandler!.call(replProvider);
99100

100101
serviceContainer.verify(
101-
(c) => c.get(TypeMoq.It.isValue(ICodeExecutionService), TypeMoq.It.isValue('repl')),
102+
(c) => c.get(TypeMoq.It.isValue(ICodeExecutionService), TypeMoq.It.isValue('standard')),
102103
TypeMoq.Times.once(),
103104
);
104105
codeExecutionService.verify((c) => c.initializeRepl(TypeMoq.It.isValue(resource)), TypeMoq.Times.once());

0 commit comments

Comments
 (0)