| 151 | return activeEditor.notebook.cellAt(startNumber)!; |
| 152 | } |
| 153 | export async function insertCodeCell(source: string, options?: { language?: string; index?: number }) { |
| 154 | const activeEditor = window.activeNotebookEditor; |
| 155 | if (!activeEditor) { |
| 156 | throw new Error('No active editor'); |
| 157 | } |
| 158 | const startNumber = options?.index ?? activeEditor.notebook.cellCount; |
| 159 | const edit = new WorkspaceEdit(); |
| 160 | const cellData = new NotebookCellData(NotebookCellKind.Code, source, options?.language || PYTHON_LANGUAGE); |
| 161 | cellData.outputs = []; |
| 162 | cellData.metadata = {}; |
| 163 | const nbEdit = NotebookEdit.insertCells(startNumber, [cellData]); |
| 164 | edit.set(activeEditor.notebook.uri, [nbEdit]); |
| 165 | await workspace.applyEdit(edit); |
| 166 | |
| 167 | return activeEditor.notebook.cellAt(startNumber)!; |
| 168 | } |
| 169 | export async function deleteCell(index: number = 0) { |
| 170 | const activeEditor = window.activeNotebookEditor; |
| 171 | if (!activeEditor || activeEditor.notebook.cellCount === 0) { |