From 5c589f9d71e666325f896340e74113551a6801e2 Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Mon, 24 Feb 2025 11:52:59 -0800 Subject: [PATCH] fix: identify script/module launch vs repl launch from terminal --- src/client/telemetry/index.ts | 7 ++++++- .../codeExecution/terminalReplWatcher.ts | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/client/telemetry/index.ts b/src/client/telemetry/index.ts index f71f963d0156..6c97bd083d96 100644 --- a/src/client/telemetry/index.ts +++ b/src/client/telemetry/index.ts @@ -1972,8 +1972,13 @@ export interface IEventNamePropertyMapping { [EventName.REPL]: { /** * Whether the user launched the Terminal REPL or Native REPL + * + * Terminal - Terminal REPL user ran `Python: Start Terminal REPL` command. + * Native - Native REPL user ran `Python: Start Native Python REPL` command. + * manualTerminal - User started REPL in terminal using `python`, `python3` or `py` etc without arguments in terminal. + * runningScript - User ran a script in terminal like `python myscript.py`. */ - replType: 'Terminal' | 'Native' | 'manualTerminal'; + replType: 'Terminal' | 'Native' | 'manualTerminal' | `runningScript`; }; /** * 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.) diff --git a/src/client/terminals/codeExecution/terminalReplWatcher.ts b/src/client/terminals/codeExecution/terminalReplWatcher.ts index bab70cb2f654..951961ab6901 100644 --- a/src/client/terminals/codeExecution/terminalReplWatcher.ts +++ b/src/client/terminals/codeExecution/terminalReplWatcher.ts @@ -3,16 +3,24 @@ import { onDidStartTerminalShellExecution } from '../../common/vscodeApis/window import { sendTelemetryEvent } from '../../telemetry'; import { EventName } from '../../telemetry/constants'; -function checkREPLCommand(command: string): boolean { +function checkREPLCommand(command: string): undefined | 'manualTerminal' | `runningScript` { const lower = command.toLowerCase().trimStart(); - return lower.startsWith('python') || lower.startsWith('py '); + if (lower.startsWith('python') || lower.startsWith('py ')) { + const parts = lower.split(' '); + if (parts.length === 1) { + return 'manualTerminal'; + } + return 'runningScript'; + } + return undefined; } export function registerTriggerForTerminalREPL(disposables: Disposable[]): void { disposables.push( onDidStartTerminalShellExecution(async (e: TerminalShellExecutionStartEvent) => { - if (e.execution.commandLine.isTrusted && checkREPLCommand(e.execution.commandLine.value)) { - sendTelemetryEvent(EventName.REPL, undefined, { replType: 'manualTerminal' }); + const replType = checkREPLCommand(e.execution.commandLine.value); + if (e.execution.commandLine.isTrusted && replType) { + sendTelemetryEvent(EventName.REPL, undefined, { replType }); } }), );