From 8b7922212d47fca9052ad18f0a22bb2876b0dd3d Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 28 May 2024 01:29:31 -0700 Subject: [PATCH 1/4] Attempt to fix duplicate REPL --- python_files/python_server.py | 3 +++ src/client/repl/replCommands.ts | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/python_files/python_server.py b/python_files/python_server.py index 30be834631c6..627297588332 100644 --- a/python_files/python_server.py +++ b/python_files/python_server.py @@ -11,6 +11,9 @@ STDOUT = sys.stdout STDERR = sys.stderr USER_GLOBALS = {} +# import debugpy + +# debugpy.connect(5678) def send_message(msg: str): diff --git a/src/client/repl/replCommands.ts b/src/client/repl/replCommands.ts index d9d0858a6637..4c3e9c2c575e 100644 --- a/src/client/repl/replCommands.ts +++ b/src/client/repl/replCommands.ts @@ -96,6 +96,18 @@ export async function registerReplCommands( notebookEditor = interactiveWindowObject.notebookEditor; notebookDocument = interactiveWindowObject.notebookEditor.notebook; } + // open notebook + if (notebookEditor && notebookDocument) { + // show existing notebook editor + // Auto-Select Python REPL Kernel + await commands.executeCommand('notebook.selectKernel', { + notebookEditor, + id: notebookController.id, + extension: PVSC_EXTENSION_ID, + }); + + await window.showNotebookDocument(notebookDocument, { viewColumn: ViewColumn.Beside }); + } if (notebookDocument) { notebookController.updateNotebookAffinity(notebookDocument, NotebookControllerAffinity.Default); @@ -107,7 +119,7 @@ export async function registerReplCommands( extension: PVSC_EXTENSION_ID, }); - const { cellCount } = notebookDocument; + const { cellCount } = notebookDocument; // CELL COUNT IS NOT GETTING UPDATED PROPERLY await addCellToNotebook(code as string); // Execute the cell commands.executeCommand('notebook.cell.execute', { From 7eb498492ecc27057d2bd34d0e573cc785aec388 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 28 May 2024 09:18:17 -0700 Subject: [PATCH 2/4] fix bug --- src/client/repl/replCommands.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/client/repl/replCommands.ts b/src/client/repl/replCommands.ts index 4c3e9c2c575e..d85cdf8ae0e7 100644 --- a/src/client/repl/replCommands.ts +++ b/src/client/repl/replCommands.ts @@ -53,6 +53,15 @@ function getSendToNativeREPLSetting(): boolean { const configuration = getConfiguration('python', uri); return configuration.get('REPL.sendToNativeREPL', false); } + +window.onDidChangeVisibleTextEditors((editors) => { + const interactiveWindowIsOpen = editors.some((editor) => editor.document.uri.scheme === 'vscode-interactive-input'); + if (!interactiveWindowIsOpen) { + notebookEditor = undefined; + notebookDocument = undefined; + } +}); + // Will only be called when user has experiment enabled. export async function registerReplCommands( disposables: Disposable[], @@ -107,6 +116,12 @@ export async function registerReplCommands( }); await window.showNotebookDocument(notebookDocument, { viewColumn: ViewColumn.Beside }); + // await window.showNotebookDocument(window.activeNotebookEditor!.notebook, { + // viewColumn: ViewColumn.Beside, + // }); + // const myVar = window.activeNotebookEditor!.notebook; + // await window.showNotebookDocument(notebookDocument, { viewColumn: ViewColumn.Beside }); + // const myVar2 = myVar; } if (notebookDocument) { @@ -119,13 +134,17 @@ export async function registerReplCommands( extension: PVSC_EXTENSION_ID, }); - const { cellCount } = notebookDocument; // CELL COUNT IS NOT GETTING UPDATED PROPERLY + // const { cellCount } = notebookDocument; // CELL COUNT IS NOT GETTING UPDATED PROPERLY + const { cellCount } = window.activeNotebookEditor!.notebook; await addCellToNotebook(code as string); // Execute the cell commands.executeCommand('notebook.cell.execute', { ranges: [{ start: cellCount, end: cellCount + 1 }], document: notebookDocument.uri, }); + // await commands.executeCommand('interactive.execute'); + // grab active notebook + // const activeNotebook = window.activeNotebookEditor; } } }), From b7d351a07f885f445e3c4f66cbc00aff8eb90c5f Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 28 May 2024 09:21:15 -0700 Subject: [PATCH 3/4] cleanup --- python_files/python_server.py | 3 --- src/client/repl/replCommands.ts | 15 ++------------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/python_files/python_server.py b/python_files/python_server.py index 627297588332..30be834631c6 100644 --- a/python_files/python_server.py +++ b/python_files/python_server.py @@ -11,9 +11,6 @@ STDOUT = sys.stdout STDERR = sys.stderr USER_GLOBALS = {} -# import debugpy - -# debugpy.connect(5678) def send_message(msg: str): diff --git a/src/client/repl/replCommands.ts b/src/client/repl/replCommands.ts index d85cdf8ae0e7..4e28e8c1df89 100644 --- a/src/client/repl/replCommands.ts +++ b/src/client/repl/replCommands.ts @@ -105,9 +105,8 @@ export async function registerReplCommands( notebookEditor = interactiveWindowObject.notebookEditor; notebookDocument = interactiveWindowObject.notebookEditor.notebook; } - // open notebook + // Handle case where user has closed REPL window, and re-opens. if (notebookEditor && notebookDocument) { - // show existing notebook editor // Auto-Select Python REPL Kernel await commands.executeCommand('notebook.selectKernel', { notebookEditor, @@ -116,12 +115,6 @@ export async function registerReplCommands( }); await window.showNotebookDocument(notebookDocument, { viewColumn: ViewColumn.Beside }); - // await window.showNotebookDocument(window.activeNotebookEditor!.notebook, { - // viewColumn: ViewColumn.Beside, - // }); - // const myVar = window.activeNotebookEditor!.notebook; - // await window.showNotebookDocument(notebookDocument, { viewColumn: ViewColumn.Beside }); - // const myVar2 = myVar; } if (notebookDocument) { @@ -134,17 +127,13 @@ export async function registerReplCommands( extension: PVSC_EXTENSION_ID, }); - // const { cellCount } = notebookDocument; // CELL COUNT IS NOT GETTING UPDATED PROPERLY - const { cellCount } = window.activeNotebookEditor!.notebook; + const { cellCount } = notebookDocument; await addCellToNotebook(code as string); // Execute the cell commands.executeCommand('notebook.cell.execute', { ranges: [{ start: cellCount, end: cellCount + 1 }], document: notebookDocument.uri, }); - // await commands.executeCommand('interactive.execute'); - // grab active notebook - // const activeNotebook = window.activeNotebookEditor; } } }), From c0074577c0bb4550b6d8db7866f38eb9553feaed Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 28 May 2024 14:29:49 -0700 Subject: [PATCH 4/4] take suggestion and dont duplicate kernel selection --- src/client/repl/replCommands.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/client/repl/replCommands.ts b/src/client/repl/replCommands.ts index 4e28e8c1df89..1260c78a6a56 100644 --- a/src/client/repl/replCommands.ts +++ b/src/client/repl/replCommands.ts @@ -107,13 +107,6 @@ export async function registerReplCommands( } // Handle case where user has closed REPL window, and re-opens. if (notebookEditor && notebookDocument) { - // Auto-Select Python REPL Kernel - await commands.executeCommand('notebook.selectKernel', { - notebookEditor, - id: notebookController.id, - extension: PVSC_EXTENSION_ID, - }); - await window.showNotebookDocument(notebookDocument, { viewColumn: ViewColumn.Beside }); }