1
1
import {
2
- NotebookController ,
3
2
NotebookEditor ,
4
3
ViewColumn ,
5
4
NotebookDocument ,
@@ -10,7 +9,6 @@ import {
10
9
Uri ,
11
10
} from 'vscode' ;
12
11
import { getExistingReplViewColumn , getTabNameForUri } from './replUtils' ;
13
- import { PVSC_EXTENSION_ID } from '../common/constants' ;
14
12
import { showNotebookDocument } from '../common/vscodeApis/windowApis' ;
15
13
import { openNotebookDocument , applyEdit } from '../common/vscodeApis/workspaceApis' ;
16
14
import { executeCommand } from '../common/vscodeApis/commandApis' ;
@@ -19,46 +17,42 @@ import { executeCommand } from '../common/vscodeApis/commandApis';
19
17
* Function that opens/show REPL using IW UI.
20
18
*/
21
19
export async function openInteractiveREPL (
22
- notebookController : NotebookController ,
23
20
notebookDocument : NotebookDocument | Uri | undefined ,
24
21
preserveFocus : boolean = true ,
25
- ) : Promise < NotebookEditor | undefined > {
22
+ ) : Promise < { notebookEditor : NotebookEditor ; documentCreated : boolean } | undefined > {
26
23
let viewColumn = ViewColumn . Beside ;
24
+ let alreadyExists = false ;
27
25
if ( notebookDocument instanceof Uri ) {
28
26
// Case where NotebookDocument is undefined, but workspace mementoURI exists.
29
27
notebookDocument = await openNotebookDocument ( notebookDocument ) ;
30
28
} else if ( notebookDocument ) {
31
29
// Case where NotebookDocument (REPL document already exists in the tab)
32
30
const existingReplViewColumn = getExistingReplViewColumn ( notebookDocument ) ;
33
31
viewColumn = existingReplViewColumn ?? viewColumn ;
32
+ alreadyExists = true ;
34
33
} else if ( ! notebookDocument ) {
35
34
// Case where NotebookDocument doesnt exist, or
36
35
// became outdated (untitled.ipynb created without Python extension knowing, effectively taking over original Python REPL's URI)
37
36
notebookDocument = await openNotebookDocument ( 'jupyter-notebook' ) ;
38
37
}
39
- const editor = await showNotebookDocument ( notebookDocument ! , {
38
+
39
+ const notebookEditor = await showNotebookDocument ( notebookDocument ! , {
40
40
viewColumn,
41
41
asRepl : 'Python REPL' ,
42
42
preserveFocus,
43
43
} ) ;
44
44
45
45
// Sanity check that we opened a Native REPL from showNotebookDocument.
46
46
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'
51
51
) {
52
52
return undefined ;
53
53
}
54
54
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 } ;
62
56
}
63
57
64
58
/**
0 commit comments