Skip to content

Commit 60d0473

Browse files
authored
fix: identify script/module launch vs repl launch from terminal (#24844)
closes #24526
1 parent cd992fc commit 60d0473

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/client/telemetry/index.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1972,8 +1972,13 @@ export interface IEventNamePropertyMapping {
19721972
[EventName.REPL]: {
19731973
/**
19741974
* Whether the user launched the Terminal REPL or Native REPL
1975+
*
1976+
* Terminal - Terminal REPL user ran `Python: Start Terminal REPL` command.
1977+
* Native - Native REPL user ran `Python: Start Native Python REPL` command.
1978+
* manualTerminal - User started REPL in terminal using `python`, `python3` or `py` etc without arguments in terminal.
1979+
* runningScript - User ran a script in terminal like `python myscript.py`.
19751980
*/
1976-
replType: 'Terminal' | 'Native' | 'manualTerminal';
1981+
replType: 'Terminal' | 'Native' | 'manualTerminal' | `runningScript`;
19771982
};
19781983
/**
19791984
* Telemetry event sent if and when user configure tests command. This command can be trigerred from multiple places in the extension. (Command palette, prompt etc.)

src/client/terminals/codeExecution/terminalReplWatcher.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,24 @@ import { onDidStartTerminalShellExecution } from '../../common/vscodeApis/window
33
import { sendTelemetryEvent } from '../../telemetry';
44
import { EventName } from '../../telemetry/constants';
55

6-
function checkREPLCommand(command: string): boolean {
6+
function checkREPLCommand(command: string): undefined | 'manualTerminal' | `runningScript` {
77
const lower = command.toLowerCase().trimStart();
8-
return lower.startsWith('python') || lower.startsWith('py ');
8+
if (lower.startsWith('python') || lower.startsWith('py ')) {
9+
const parts = lower.split(' ');
10+
if (parts.length === 1) {
11+
return 'manualTerminal';
12+
}
13+
return 'runningScript';
14+
}
15+
return undefined;
916
}
1017

1118
export function registerTriggerForTerminalREPL(disposables: Disposable[]): void {
1219
disposables.push(
1320
onDidStartTerminalShellExecution(async (e: TerminalShellExecutionStartEvent) => {
14-
if (e.execution.commandLine.isTrusted && checkREPLCommand(e.execution.commandLine.value)) {
15-
sendTelemetryEvent(EventName.REPL, undefined, { replType: 'manualTerminal' });
21+
const replType = checkREPLCommand(e.execution.commandLine.value);
22+
if (e.execution.commandLine.isTrusted && replType) {
23+
sendTelemetryEvent(EventName.REPL, undefined, { replType });
1624
}
1725
}),
1826
);

0 commit comments

Comments
 (0)