Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify Terminal REPL triggers #23641

Merged
merged 15 commits into from
Jun 21, 2024
1 change: 1 addition & 0 deletions src/client/common/terminal/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand Down
2 changes: 1 addition & 1 deletion src/client/providers/replProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class ReplProvider implements Disposable {
.then(noop, noop);
return;
}
const replProvider = this.serviceContainer.get<ICodeExecutionService>(ICodeExecutionService, 'repl');
const replProvider = this.serviceContainer.get<ICodeExecutionService>(ICodeExecutionService, 'standard');
await replProvider.initializeRepl(resource);
}
}
7 changes: 6 additions & 1 deletion src/client/terminals/codeExecution/terminalCodeExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>;

constructor(
@inject(ITerminalServiceFactory) protected readonly terminalServiceFactory: ITerminalServiceFactory,
@inject(IConfigurationService) protected readonly configurationService: IConfigurationService,
Expand Down Expand Up @@ -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<boolean>(async (resolve) => {
const replCommandArgs = await this.getExecutableInfo(resource);
let listener: IDisposable;
Expand Down Expand Up @@ -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(() => {
Expand Down
5 changes: 3 additions & 2 deletions src/test/providers/repl.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -80,6 +80,7 @@ suite('REPL Provider', () => {
const resource = Uri.parse('a');
const disposable = TypeMoq.Mock.ofType<Disposable>();
let commandHandler: undefined | (() => Promise<void>);

commandManager
.setup((c) =>
c.registerCommand(TypeMoq.It.isValue(Commands.Start_REPL), TypeMoq.It.isAny(), TypeMoq.It.isAny()),
Expand All @@ -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());
Expand Down
Loading