Skip to content

Commit

Permalink
account for updates
Browse files Browse the repository at this point in the history
  • Loading branch information
amunger committed Sep 18, 2024
1 parent 84d23cc commit 5271067
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/client/repl/nativeRepl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class NativeRepl implements Disposable {
this.replController.updateNotebookAffinity(this.notebookDocument, NotebookControllerAffinity.Default);
await selectNotebookKernel(notebookEditor, this.replController.id, PVSC_EXTENSION_ID);
if (code) {
await executeNotebookCell(this.notebookDocument, code);
await executeNotebookCell(notebookEditor, code);
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/client/repl/replCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function openInteractiveREPL(
// Case where NotebookDocument doesnt exist, create a blank one.
notebookDocument = await workspace.openNotebookDocument('jupyter-notebook');
}
const editor = window.showNotebookDocument(notebookDocument!, { viewColumn, asRepl: true, label: 'Python REPL' });
const editor = window.showNotebookDocument(notebookDocument!, { viewColumn, asRepl: 'Python REPL' });
await commands.executeCommand('notebook.selectKernel', {
editor,
id: notebookController.id,
Expand Down Expand Up @@ -69,13 +69,14 @@ export async function selectNotebookKernel(
* @param code
* @return Promise<void>
*/
export async function executeNotebookCell(notebookDocument: NotebookDocument, code: string): Promise<void> {
const { cellCount } = notebookDocument;
await addCellToNotebook(notebookDocument, code);
export async function executeNotebookCell(notebookEditor: NotebookEditor, code: string): Promise<void> {
const { notebook, replOptions } = notebookEditor;
const cellIndex = replOptions?.appendIndex ?? notebook.cellCount;
await addCellToNotebook(notebook, cellIndex, code);
// Execute the cell
commands.executeCommand('notebook.cell.execute', {
ranges: [{ start: cellCount - 1, end: cellCount }],
document: notebookDocument.uri,
ranges: [{ start: cellIndex, end: cellIndex + 1 }],
document: notebook.uri,
});
}

Expand All @@ -85,11 +86,10 @@ export async function executeNotebookCell(notebookDocument: NotebookDocument, co
* @param code
*
*/
async function addCellToNotebook(notebookDocument: NotebookDocument, code: string): Promise<void> {
async function addCellToNotebook(notebookDocument: NotebookDocument, index: number, code: string): Promise<void> {
const notebookCellData = new NotebookCellData(NotebookCellKind.Code, code as string, 'python');
const { cellCount } = notebookDocument!;
// Add new cell to interactive window document
const notebookEdit = NotebookEdit.insertCells(cellCount - 1, [notebookCellData]);
const notebookEdit = NotebookEdit.insertCells(index, [notebookCellData]);
const workspaceEdit = new WorkspaceEdit();
workspaceEdit.set(notebookDocument!.uri, [notebookEdit]);
await workspace.applyEdit(workspaceEdit);
Expand Down
21 changes: 17 additions & 4 deletions types/vscode.proposed.notebookReplDocument.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,26 @@ declare module 'vscode' {
export interface NotebookDocumentShowOptions {
/**
* The notebook should be opened in a REPL editor,
* where the last cell of the notebook is an input box and the rest are read-only.
* where the last cell of the notebook is an input box and the other cells are the read-only history.
* When the value is a string, it will be used as the label for the editor tab.
*/
readonly asRepl?: boolean;
readonly asRepl?: boolean | string | {
/**
* The label to be used for the editor tab.
*/
readonly label: string;
};
}

export interface NotebookEditor {
/**
* The label to be used for the editor tab.
* Information about the REPL editor if the notebook was opened as a repl.
*/
readonly label?: string;
replOptions?: {
/**
* The index where new cells should be appended.
*/
appendIndex: number;
};
}
}

0 comments on commit 5271067

Please sign in to comment.