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

Correctly track native REPL state #23997

Merged
merged 4 commits into from
Aug 26, 2024
Merged
Changes from 3 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
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.newReplSession) {
sendTelemetryEvent(EventName.REPL, undefined, { replType: 'Native' });
nativeRepl.newReplSession = false;
}
return nativeRepl;
}
Loading