forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathterminalReplWatcher.ts
More file actions
44 lines (40 loc) · 1.72 KB
/
terminalReplWatcher.ts
File metadata and controls
44 lines (40 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { Disposable, TerminalShellExecutionStartEvent } from 'vscode';
import { onDidStartTerminalShellExecution } from '../../common/vscodeApis/windowApis';
import { sendTelemetryEvent } from '../../telemetry';
import { EventName } from '../../telemetry/constants';
function checkREPLCommand(command: string): undefined | 'manualTerminal' | `runningScript` | 'runningTest' {
const lower = command.toLowerCase().trimStart();
// Check for test commands
if (
lower.includes('pytest') ||
(lower.startsWith('python') && (lower.includes(' -m pytest') || lower.includes(' -m unittest'))) ||
(lower.startsWith('py ') && (lower.includes(' -m pytest') || lower.includes(' -m unittest'))) ||
lower.includes('py.test')
) {
return 'runningTest';
}
// Regular Python commands
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) => {
const replType = checkREPLCommand(e.execution.commandLine.value);
if (e.execution.commandLine.isTrusted && replType) {
// Send test-specific telemetry if it's a test command
if (replType === 'runningTest') {
sendTelemetryEvent(EventName.UNITTEST_RUN_CLI);
} else {
sendTelemetryEvent(EventName.REPL, undefined, { replType });
}
}
}),
);
}