Skip to content

Commit 5271067

Browse files
committed
account for updates
1 parent 84d23cc commit 5271067

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

src/client/repl/nativeRepl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export class NativeRepl implements Disposable {
150150
this.replController.updateNotebookAffinity(this.notebookDocument, NotebookControllerAffinity.Default);
151151
await selectNotebookKernel(notebookEditor, this.replController.id, PVSC_EXTENSION_ID);
152152
if (code) {
153-
await executeNotebookCell(this.notebookDocument, code);
153+
await executeNotebookCell(notebookEditor, code);
154154
}
155155
}
156156
}

src/client/repl/replCommandHandler.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export async function openInteractiveREPL(
3434
// Case where NotebookDocument doesnt exist, create a blank one.
3535
notebookDocument = await workspace.openNotebookDocument('jupyter-notebook');
3636
}
37-
const editor = window.showNotebookDocument(notebookDocument!, { viewColumn, asRepl: true, label: 'Python REPL' });
37+
const editor = window.showNotebookDocument(notebookDocument!, { viewColumn, asRepl: 'Python REPL' });
3838
await commands.executeCommand('notebook.selectKernel', {
3939
editor,
4040
id: notebookController.id,
@@ -69,13 +69,14 @@ export async function selectNotebookKernel(
6969
* @param code
7070
* @return Promise<void>
7171
*/
72-
export async function executeNotebookCell(notebookDocument: NotebookDocument, code: string): Promise<void> {
73-
const { cellCount } = notebookDocument;
74-
await addCellToNotebook(notebookDocument, code);
72+
export async function executeNotebookCell(notebookEditor: NotebookEditor, code: string): Promise<void> {
73+
const { notebook, replOptions } = notebookEditor;
74+
const cellIndex = replOptions?.appendIndex ?? notebook.cellCount;
75+
await addCellToNotebook(notebook, cellIndex, code);
7576
// Execute the cell
7677
commands.executeCommand('notebook.cell.execute', {
77-
ranges: [{ start: cellCount - 1, end: cellCount }],
78-
document: notebookDocument.uri,
78+
ranges: [{ start: cellIndex, end: cellIndex + 1 }],
79+
document: notebook.uri,
7980
});
8081
}
8182

@@ -85,11 +86,10 @@ export async function executeNotebookCell(notebookDocument: NotebookDocument, co
8586
* @param code
8687
*
8788
*/
88-
async function addCellToNotebook(notebookDocument: NotebookDocument, code: string): Promise<void> {
89+
async function addCellToNotebook(notebookDocument: NotebookDocument, index: number, code: string): Promise<void> {
8990
const notebookCellData = new NotebookCellData(NotebookCellKind.Code, code as string, 'python');
90-
const { cellCount } = notebookDocument!;
9191
// Add new cell to interactive window document
92-
const notebookEdit = NotebookEdit.insertCells(cellCount - 1, [notebookCellData]);
92+
const notebookEdit = NotebookEdit.insertCells(index, [notebookCellData]);
9393
const workspaceEdit = new WorkspaceEdit();
9494
workspaceEdit.set(notebookDocument!.uri, [notebookEdit]);
9595
await workspace.applyEdit(workspaceEdit);

types/vscode.proposed.notebookReplDocument.d.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,26 @@ declare module 'vscode' {
88
export interface NotebookDocumentShowOptions {
99
/**
1010
* The notebook should be opened in a REPL editor,
11-
* where the last cell of the notebook is an input box and the rest are read-only.
11+
* where the last cell of the notebook is an input box and the other cells are the read-only history.
12+
* When the value is a string, it will be used as the label for the editor tab.
1213
*/
13-
readonly asRepl?: boolean;
14+
readonly asRepl?: boolean | string | {
15+
/**
16+
* The label to be used for the editor tab.
17+
*/
18+
readonly label: string;
19+
};
20+
}
1421

22+
export interface NotebookEditor {
1523
/**
16-
* The label to be used for the editor tab.
24+
* Information about the REPL editor if the notebook was opened as a repl.
1725
*/
18-
readonly label?: string;
26+
replOptions?: {
27+
/**
28+
* The index where new cells should be appended.
29+
*/
30+
appendIndex: number;
31+
};
1932
}
2033
}

0 commit comments

Comments
 (0)