Option in showNotebook to open as REPL (#225273)

* new API option and flag

* show the notebook as a repl

* handle any notebook type, dispose all model refs

* open notebook doc as scratchpad

* delay loading the model for untitled notebooks until shown

* add initial content consistently for untitled

* simplify utitled notebook creation

* recover open untitled notebook as dirty behavior
This commit is contained in:
Aaron Munger
2024-08-14 14:21:22 -07:00
committed by GitHub
parent 622106fdd8
commit 1c5490e38a
14 changed files with 225 additions and 119 deletions

View File

@@ -18,6 +18,10 @@ async function openRandomNotebookDocument() {
return vscode.workspace.openNotebookDocument(uri);
}
async function openUntitledNotebookDocument(data?: vscode.NotebookData) {
return vscode.workspace.openNotebookDocument('notebookCoreTest', data);
}
export async function saveAllFilesAndCloseAll() {
await saveAllEditors();
await closeAllEditors();
@@ -188,6 +192,27 @@ const apiTestSerializer: vscode.NotebookSerializer = {
assert.strictEqual(vscode.window.activeNotebookEditor!.notebook.uri.toString(), document.uri.toString());
});
test('Opening an utitled notebook without content will only open the editor when shown.', async function () {
const document = await openUntitledNotebookDocument();
assert.strictEqual(vscode.window.activeNotebookEditor, undefined);
// opening a cell-uri opens a notebook editor
await vscode.window.showNotebookDocument(document);
assert.strictEqual(!!vscode.window.activeNotebookEditor, true);
assert.strictEqual(vscode.window.activeNotebookEditor!.notebook.uri.toString(), document.uri.toString());
});
test('Opening an untitled notebook with content will open a dirty document.', async function () {
const language = 'python';
const cell = new vscode.NotebookCellData(vscode.NotebookCellKind.Code, '', language);
const data = new vscode.NotebookData([cell]);
const doc = await vscode.workspace.openNotebookDocument('jupyter-notebook', data);
assert.strictEqual(doc.isDirty, true);
});
test('Cannot open notebook from cell-uri with vscode.open-command', async function () {
const document = await openRandomNotebookDocument();