Skip to content

Commit 0a6ab08

Browse files
committed
draft and start prompt native repl in terminal
1 parent 2fed954 commit 0a6ab08

File tree

4 files changed

+57
-6
lines changed

4 files changed

+57
-6
lines changed

src/client/common/utils/localize.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ export namespace AttachProcess {
101101

102102
export namespace Repl {
103103
export const disableSmartSend = l10n.t('Disable Smart Send');
104+
// TODO: get feedback on text message below:
105+
export const terminalSuggestNativeReplPrompt = l10n.t(
106+
'The Python extension now includes an editor based native Python REPL with Intellisense, syntax highlighting. Would you like to try this out?',
107+
);
104108
}
105109
export namespace Pylance {
106110
export const remindMeLater = l10n.t('Remind me later');

src/client/extensionActivation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export function activateFeatures(ext: ExtensionState, _components: Components):
111111
);
112112
const executionHelper = ext.legacyIOC.serviceContainer.get<ICodeExecutionHelper>(ICodeExecutionHelper);
113113
const commandManager = ext.legacyIOC.serviceContainer.get<ICommandManager>(ICommandManager);
114-
registerTriggerForTerminalREPL(ext.disposables);
114+
registerTriggerForTerminalREPL(commandManager, ext.disposables);
115115
registerStartNativeReplCommand(ext.disposables, interpreterService);
116116
registerReplCommands(ext.disposables, interpreterService, executionHelper, commandManager);
117117
registerReplExecuteOnEnter(ext.disposables, interpreterService, commandManager);

src/client/terminals/codeExecution/terminalCodeExecution.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,23 @@
55

66
import { inject, injectable } from 'inversify';
77
import * as path from 'path';
8-
import { Disposable, Uri } from 'vscode';
8+
import { Disposable, TerminalShellExecutionStartEvent, Uri } from 'vscode';
99
import { IApplicationShell, ICommandManager, IWorkspaceService } from '../../common/application/types';
1010
import '../../common/extensions';
1111
import { IPlatformService } from '../../common/platform/types';
1212
import { ITerminalService, ITerminalServiceFactory } from '../../common/terminal/types';
1313
import { IConfigurationService, IDisposable, IDisposableRegistry, Resource } from '../../common/types';
14-
import { Diagnostics, Repl } from '../../common/utils/localize';
15-
import { showWarningMessage } from '../../common/vscodeApis/windowApis';
14+
import { Common, Diagnostics, Repl } from '../../common/utils/localize';
15+
import { onDidStartTerminalShellExecution, showWarningMessage } from '../../common/vscodeApis/windowApis';
1616
import { IInterpreterService } from '../../interpreter/contracts';
1717
import { traceInfo } from '../../logging';
1818
import { buildPythonExecInfo, PythonExecInfo } from '../../pythonEnvironments/exec';
1919
import { ICodeExecutionService } from '../../terminals/types';
2020
import { EventName } from '../../telemetry/constants';
2121
import { sendTelemetryEvent } from '../../telemetry';
22+
import { getActiveInterpreter } from '../../repl/replUtils';
23+
import { getNativeRepl } from '../../repl/nativeRepl';
24+
import { checkREPLCommand } from './terminalReplWatcher';
2225

2326
@injectable()
2427
export class TerminalCodeExecutionProvider implements ICodeExecutionService {
@@ -63,11 +66,43 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService {
6366
}
6467
}
6568

69+
public suggestNativeRepl(resource: Resource) {
70+
this.disposables.push(
71+
onDidStartTerminalShellExecution(async (e: TerminalShellExecutionStartEvent) => {
72+
if (e.execution.commandLine.isTrusted && checkREPLCommand(e.execution.commandLine.value)) {
73+
sendTelemetryEvent(EventName.REPL, undefined, { replType: 'manualTerminal' });
74+
const selection = await showWarningMessage(
75+
Repl.terminalSuggestNativeReplPrompt,
76+
Common.doNotShowAgain,
77+
);
78+
if (selection === Repl.terminalSuggestNativeReplPrompt) {
79+
sendTelemetryEvent(EventName.REPL, undefined, { replType: 'Native' });
80+
const interpreter = await getActiveInterpreter(resource as Uri, this.interpreterService);
81+
if (interpreter) {
82+
const nativeRepl = await getNativeRepl(interpreter, this.disposables);
83+
await nativeRepl.sendToNativeRepl(undefined, false);
84+
}
85+
}
86+
}
87+
}),
88+
);
89+
}
90+
6691
public async initializeRepl(resource: Resource) {
6792
const terminalService = this.getTerminalService(resource);
93+
if (!this.replActive) {
94+
this.suggestNativeRepl(resource);
95+
}
6896
if (this.replActive && (await this.replActive)) {
6997
await terminalService.show();
7098
return;
99+
} else {
100+
// Suggest launch of Native REPL
101+
const interpreter = await getActiveInterpreter(resource!, this.interpreterService);
102+
if (interpreter) {
103+
const nativeRepl = await getNativeRepl(interpreter, this.disposables);
104+
await nativeRepl.sendToNativeRepl(undefined, false);
105+
}
71106
}
72107
sendTelemetryEvent(EventName.REPL, undefined, { replType: 'Terminal' });
73108
this.replActive = new Promise<boolean>(async (resolve) => {

src/client/terminals/codeExecution/terminalReplWatcher.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,29 @@ import { Disposable, TerminalShellExecutionStartEvent } from 'vscode';
22
import { onDidStartTerminalShellExecution } from '../../common/vscodeApis/windowApis';
33
import { sendTelemetryEvent } from '../../telemetry';
44
import { EventName } from '../../telemetry/constants';
5+
import { ICommandManager } from '../../common/application/types';
6+
import { Commands } from '../../common/constants';
57

6-
function checkREPLCommand(command: string): boolean {
8+
export function checkREPLCommand(command: string): boolean {
79
const lower = command.toLowerCase().trimStart();
810
return lower.startsWith('python') || lower.startsWith('py ');
911
}
1012

11-
export function registerTriggerForTerminalREPL(disposables: Disposable[]): void {
13+
export async function registerTriggerForTerminalREPL(
14+
commandManager: ICommandManager,
15+
disposables: Disposable[],
16+
): Promise<void> {
1217
disposables.push(
1318
onDidStartTerminalShellExecution(async (e: TerminalShellExecutionStartEvent) => {
1419
if (e.execution.commandLine.isTrusted && checkREPLCommand(e.execution.commandLine.value)) {
1520
sendTelemetryEvent(EventName.REPL, undefined, { replType: 'manualTerminal' });
21+
// TODO: Prompt user to start Native REPL
22+
23+
// If yes, then launch native REPL
24+
await commandManager.executeCommand(Commands.Start_Native_REPL, undefined);
25+
26+
// TODO: Decide whether we want everytime, or once per workspace, or once per terminal
27+
// How do I even track all terminal instances.
1628
}
1729
}),
1830
);

0 commit comments

Comments
 (0)