Skip to content

Commit

Permalink
Correctly track native REPL state (#23997)
Browse files Browse the repository at this point in the history
Resolves: #23996
  • Loading branch information
anthonykim1 authored Aug 26, 2024
1 parent 61bc2d5 commit 7ccf01e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/client/repl/nativeRepl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
}),
);
Expand Down Expand Up @@ -152,18 +156,19 @@ 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
* @returns Native REPL instance
*/
export async function getNativeRepl(interpreter: PythonEnvironment, disposables: Disposable[]): Promise<NativeRepl> {
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;
}

0 comments on commit 7ccf01e

Please sign in to comment.