Skip to content

Commit da62fb5

Browse files
authored
Stop creating duplicate REPL and allow new REPL instance (#23496)
Resolves: #23495 Resolves: #23500
1 parent 45a8858 commit da62fb5

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

src/client/repl/replCommands.ts

+27-12
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ function getSendToNativeREPLSetting(): boolean {
5353
const configuration = getConfiguration('python', uri);
5454
return configuration.get<boolean>('REPL.sendToNativeREPL', false);
5555
}
56+
57+
window.onDidChangeVisibleTextEditors((editors) => {
58+
const interactiveWindowIsOpen = editors.some((editor) => editor.document.uri.scheme === 'vscode-interactive-input');
59+
if (!interactiveWindowIsOpen) {
60+
notebookEditor = undefined;
61+
notebookDocument = undefined;
62+
}
63+
});
64+
5665
// Will only be called when user has experiment enabled.
5766
export async function registerReplCommands(
5867
disposables: Disposable[],
@@ -82,18 +91,24 @@ export async function registerReplCommands(
8291
const activeEditor = window.activeTextEditor as TextEditor;
8392
const code = await getSelectedTextToExecute(activeEditor);
8493

85-
const interactiveWindowObject = (await commands.executeCommand(
86-
'interactive.open',
87-
{
88-
preserveFocus: true,
89-
viewColumn: ViewColumn.Beside,
90-
},
91-
undefined,
92-
notebookController.id,
93-
'Python REPL',
94-
)) as { notebookEditor: NotebookEditor };
95-
notebookEditor = interactiveWindowObject.notebookEditor;
96-
notebookDocument = interactiveWindowObject.notebookEditor.notebook;
94+
if (!notebookEditor) {
95+
const interactiveWindowObject = (await commands.executeCommand(
96+
'interactive.open',
97+
{
98+
preserveFocus: true,
99+
viewColumn: ViewColumn.Beside,
100+
},
101+
undefined,
102+
notebookController.id,
103+
'Python REPL',
104+
)) as { notebookEditor: NotebookEditor };
105+
notebookEditor = interactiveWindowObject.notebookEditor;
106+
notebookDocument = interactiveWindowObject.notebookEditor.notebook;
107+
}
108+
// Handle case where user has closed REPL window, and re-opens.
109+
if (notebookEditor && notebookDocument) {
110+
await window.showNotebookDocument(notebookDocument, { viewColumn: ViewColumn.Beside });
111+
}
97112

98113
if (notebookDocument) {
99114
notebookController.updateNotebookAffinity(notebookDocument, NotebookControllerAffinity.Default);

0 commit comments

Comments
 (0)