MCPcopy Create free account
hub / github.com/deepnote/vscode-deepnote / insertCodeCell

Function insertCodeCell

src/test/datascience/notebook/helper.ts:153–168  ·  view source on GitHub ↗
(source: string, options?: { language?: string; index?: number })

Source from the content-addressed store, hash-verified

151 return activeEditor.notebook.cellAt(startNumber)!;
152}
153export 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}
169export async function deleteCell(index: number = 0) {
170 const activeEditor = window.activeNotebookEditor;
171 if (!activeEditor || activeEditor.notebook.cellCount === 0) {

Calls 4

setMethod · 0.95
insertCellsMethod · 0.80
applyEditMethod · 0.80
cellAtMethod · 0.80

Tested by 1

testCompletionsFunction · 0.72