| 25 | * @returns notebook |
| 26 | */ |
| 27 | export async function openNewNotebookEditor( |
| 28 | cellContents: string[], |
| 29 | language: string = "plaintext" |
| 30 | ) { |
| 31 | await vscode.commands.executeCommand("workbench.action.closeAllEditors"); |
| 32 | |
| 33 | const document = await vscode.workspace.openNotebookDocument( |
| 34 | "jupyter-notebook", |
| 35 | new vscode.NotebookData( |
| 36 | cellContents.map( |
| 37 | (contents) => |
| 38 | new vscode.NotebookCellData( |
| 39 | vscode.NotebookCellKind.Code, |
| 40 | contents, |
| 41 | language |
| 42 | ) |
| 43 | ) |
| 44 | ) |
| 45 | ); |
| 46 | |
| 47 | await (await getParseTreeApi()).loadLanguage(language); |
| 48 | |
| 49 | return document; |
| 50 | } |