From e84cbe6c8a04894829b66110dc828942d53b348e Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 26 Aug 2024 16:46:54 -0400 Subject: [PATCH 1/4] set native repl to undefined when closed --- src/client/repl/nativeRepl.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/client/repl/nativeRepl.ts b/src/client/repl/nativeRepl.ts index eaa97f9518df..d2fad908ec00 100644 --- a/src/client/repl/nativeRepl.ts +++ b/src/client/repl/nativeRepl.ts @@ -20,6 +20,8 @@ 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; @@ -63,6 +65,7 @@ export class NativeRepl implements Disposable { workspace.onDidCloseNotebookDocument((nb) => { if (this.notebookDocument && nb.uri.toString() === this.notebookDocument.uri.toString()) { this.notebookDocument = undefined; + nativeRepl = undefined; } }), ); @@ -152,8 +155,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 From 3093f71aca9641f00e7191051195a01f7ed5962a Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 26 Aug 2024 17:02:37 -0400 Subject: [PATCH 2/4] correctly track native REPL state --- src/client/repl/nativeRepl.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/client/repl/nativeRepl.ts b/src/client/repl/nativeRepl.ts index d2fad908ec00..ffe0aba8b581 100644 --- a/src/client/repl/nativeRepl.ts +++ b/src/client/repl/nativeRepl.ts @@ -21,7 +21,6 @@ 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; @@ -36,6 +35,8 @@ export class NativeRepl implements Disposable { private notebookDocument: NotebookDocument | undefined; + public newReplSession = true; + // TODO: In the future, could also have attribute of URI for file specific REPL. private constructor() { this.watchNotebookClosed(); @@ -65,7 +66,7 @@ export class NativeRepl implements Disposable { workspace.onDidCloseNotebookDocument((nb) => { if (this.notebookDocument && nb.uri.toString() === this.notebookDocument.uri.toString()) { this.notebookDocument = undefined; - nativeRepl = undefined; + this.newReplSession = true; } }), ); @@ -162,9 +163,12 @@ export class NativeRepl implements Disposable { */ 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.newReplSession) { + sendTelemetryEvent(EventName.REPL, undefined, { replType: 'Native' }); + nativeRepl.newReplSession = false; + } return nativeRepl; } From bdd48a18b425b153793573e6853e721558218182 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 26 Aug 2024 17:10:27 -0400 Subject: [PATCH 3/4] stop complaining --- src/client/repl/nativeRepl.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/repl/nativeRepl.ts b/src/client/repl/nativeRepl.ts index ffe0aba8b581..6448c99d6b5d 100644 --- a/src/client/repl/nativeRepl.ts +++ b/src/client/repl/nativeRepl.ts @@ -35,7 +35,7 @@ export class NativeRepl implements Disposable { private notebookDocument: NotebookDocument | undefined; - public newReplSession = true; + public newReplSession: boolean | undefined = true; // TODO: In the future, could also have attribute of URI for file specific REPL. private constructor() { From 245ba59e0ecc13586278b2455c86569f6e424eb9 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 26 Aug 2024 17:19:32 -0400 Subject: [PATCH 4/4] please --- src/client/repl/nativeRepl.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/repl/nativeRepl.ts b/src/client/repl/nativeRepl.ts index 6448c99d6b5d..8b233f765468 100644 --- a/src/client/repl/nativeRepl.ts +++ b/src/client/repl/nativeRepl.ts @@ -166,7 +166,7 @@ export async function getNativeRepl(interpreter: PythonEnvironment, disposables: nativeRepl = await NativeRepl.create(interpreter); disposables.push(nativeRepl); } - if (nativeRepl.newReplSession) { + if (nativeRepl && nativeRepl.newReplSession) { sendTelemetryEvent(EventName.REPL, undefined, { replType: 'Native' }); nativeRepl.newReplSession = false; }