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 1 commit
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
Prev Previous commit
Next Next commit
correctly track native REPL state
  • Loading branch information
anthonykim1 committed Aug 26, 2024
commit 3093f71aca9641f00e7191051195a01f7ed5962a
10 changes: 7 additions & 3 deletions src/client/repl/nativeRepl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
}),
);
Expand Down Expand Up @@ -162,9 +163,12 @@ export class NativeRepl implements Disposable {
*/
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