11import {
2- NotebookController ,
32 NotebookEditor ,
43 ViewColumn ,
54 NotebookDocument ,
@@ -10,7 +9,6 @@ import {
109 Uri ,
1110} from 'vscode' ;
1211import { getExistingReplViewColumn , getTabNameForUri } from './replUtils' ;
13- import { PVSC_EXTENSION_ID } from '../common/constants' ;
1412import { showNotebookDocument } from '../common/vscodeApis/windowApis' ;
1513import { openNotebookDocument , applyEdit } from '../common/vscodeApis/workspaceApis' ;
1614import { executeCommand } from '../common/vscodeApis/commandApis' ;
@@ -19,46 +17,42 @@ import { executeCommand } from '../common/vscodeApis/commandApis';
1917 * Function that opens/show REPL using IW UI.
2018 */
2119export async function openInteractiveREPL (
22- notebookController : NotebookController ,
2320 notebookDocument : NotebookDocument | Uri | undefined ,
2421 preserveFocus : boolean = true ,
25- ) : Promise < NotebookEditor | undefined > {
22+ ) : Promise < { notebookEditor : NotebookEditor ; documentCreated : boolean } | undefined > {
2623 let viewColumn = ViewColumn . Beside ;
24+ let alreadyExists = false ;
2725 if ( notebookDocument instanceof Uri ) {
2826 // Case where NotebookDocument is undefined, but workspace mementoURI exists.
2927 notebookDocument = await openNotebookDocument ( notebookDocument ) ;
3028 } else if ( notebookDocument ) {
3129 // Case where NotebookDocument (REPL document already exists in the tab)
3230 const existingReplViewColumn = getExistingReplViewColumn ( notebookDocument ) ;
3331 viewColumn = existingReplViewColumn ?? viewColumn ;
32+ alreadyExists = true ;
3433 } else if ( ! notebookDocument ) {
3534 // Case where NotebookDocument doesnt exist, or
3635 // became outdated (untitled.ipynb created without Python extension knowing, effectively taking over original Python REPL's URI)
3736 notebookDocument = await openNotebookDocument ( 'jupyter-notebook' ) ;
3837 }
39- const editor = await showNotebookDocument ( notebookDocument ! , {
38+
39+ const notebookEditor = await showNotebookDocument ( notebookDocument ! , {
4040 viewColumn,
4141 asRepl : 'Python REPL' ,
4242 preserveFocus,
4343 } ) ;
4444
4545 // Sanity check that we opened a Native REPL from showNotebookDocument.
4646 if (
47- ! editor ||
48- ! editor . notebook ||
49- ! editor . notebook . uri ||
50- getTabNameForUri ( editor . notebook . uri ) !== 'Python REPL'
47+ ! notebookEditor ||
48+ ! notebookEditor . notebook ||
49+ ! notebookEditor . notebook . uri ||
50+ getTabNameForUri ( notebookEditor . notebook . uri ) !== 'Python REPL'
5151 ) {
5252 return undefined ;
5353 }
5454
55- await executeCommand ( 'notebook.selectKernel' , {
56- editor,
57- id : notebookController . id ,
58- extension : PVSC_EXTENSION_ID ,
59- } ) ;
60-
61- return editor ;
55+ return { notebookEditor, documentCreated : ! alreadyExists } ;
6256}
6357
6458/**
0 commit comments