From 7ccf01ebe33624a7dbb7b69abe5e0c3db11d3735 Mon Sep 17 00:00:00 2001 From: Anthony Kim <62267334+anthonykim1@users.noreply.github.com> Date: Mon, 26 Aug 2024 15:31:12 -0700 Subject: [PATCH] Correctly track native REPL state (#23997) Resolves: #23996 --- src/client/repl/nativeRepl.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/client/repl/nativeRepl.ts b/src/client/repl/nativeRepl.ts index eaa97f9518df..8b233f765468 100644 --- a/src/client/repl/nativeRepl.ts +++ b/src/client/repl/nativeRepl.ts @@ -20,6 +20,7 @@ import { createReplController } from './replController'; import { EventName } from '../telemetry/constants'; import { sendTelemetryEvent } from '../telemetry'; +let nativeRepl: NativeRepl | undefined; // In multi REPL scenario, hashmap of URI to Repl. export class NativeRepl implements Disposable { // Adding ! since it will get initialized in create method, not the constructor. private pythonServer!: PythonServer; @@ -34,6 +35,8 @@ export class NativeRepl implements Disposable { private notebookDocument: NotebookDocument | undefined; + public newReplSession: boolean | undefined = true; + // TODO: In the future, could also have attribute of URI for file specific REPL. private constructor() { this.watchNotebookClosed(); @@ -63,6 +66,7 @@ export class NativeRepl implements Disposable { workspace.onDidCloseNotebookDocument((nb) => { if (this.notebookDocument && nb.uri.toString() === this.notebookDocument.uri.toString()) { this.notebookDocument = undefined; + this.newReplSession = true; } }), ); @@ -152,8 +156,6 @@ export class NativeRepl implements Disposable { } } -let nativeRepl: NativeRepl | undefined; // In multi REPL scenario, hashmap of URI to Repl. - /** * Get Singleton Native REPL Instance * @param interpreter @@ -161,9 +163,12 @@ let nativeRepl: NativeRepl | undefined; // In multi REPL scenario, hashmap of UR */ export async function getNativeRepl(interpreter: PythonEnvironment, disposables: Disposable[]): Promise { if (!nativeRepl) { - sendTelemetryEvent(EventName.REPL, undefined, { replType: 'Native' }); nativeRepl = await NativeRepl.create(interpreter); disposables.push(nativeRepl); } + if (nativeRepl && nativeRepl.newReplSession) { + sendTelemetryEvent(EventName.REPL, undefined, { replType: 'Native' }); + nativeRepl.newReplSession = false; + } return nativeRepl; }