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

fix: identify script/module launch vs repl launch from terminal #24844

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/client/telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down
16 changes: 12 additions & 4 deletions src/client/terminals/codeExecution/terminalReplWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}),
);
Expand Down
Loading