diff --git a/extensions/vscode-notebook-tests/src/notebook.test.ts b/extensions/vscode-notebook-tests/src/notebook.test.ts index 91a6a1c88e7..da4e7038ff6 100644 --- a/extensions/vscode-notebook-tests/src/notebook.test.ts +++ b/extensions/vscode-notebook-tests/src/notebook.test.ts @@ -51,7 +51,7 @@ async function getEventOncePromise(event: vscode.Event): Promise { // Notebook editor/document events are not guaranteed to be sent to the ext host when promise resolves // The workaround here is waiting for the first visible notebook editor change event. async function splitEditor() { - const once = getEventOncePromise(vscode.notebook.onDidChangeVisibleNotebookEditors); + const once = getEventOncePromise(vscode.window.onDidChangeVisibleNotebookEditors); await vscode.commands.executeCommand('workbench.action.splitEditor'); await once; } @@ -90,7 +90,7 @@ async function saveAllFilesAndCloseAll(resource: vscode.Uri | undefined) { function assertInitalState() { // no-op unless we figure out why some documents are opened after the editor is closed - // assert.equal(vscode.notebook.activeNotebookEditor, undefined); + // assert.equal(vscode.window.activeNotebookEditor, undefined); // assert.equal(vscode.notebook.notebookDocuments.length, 0); // assert.equal(vscode.notebook.visibleNotebookEditors.length, 0); } @@ -201,11 +201,11 @@ suite('Notebook API tests', () => { assertInitalState(); const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); - const firstEditorOpen = getEventOncePromise(vscode.notebook.onDidChangeVisibleNotebookEditors); + const firstEditorOpen = getEventOncePromise(vscode.window.onDidChangeVisibleNotebookEditors); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); await firstEditorOpen; - const firstEditorClose = getEventOncePromise(vscode.notebook.onDidChangeVisibleNotebookEditors); + const firstEditorClose = getEventOncePromise(vscode.window.onDidChangeVisibleNotebookEditors); await vscode.commands.executeCommand('workbench.action.closeAllEditors'); await firstEditorClose; }); @@ -216,8 +216,8 @@ suite('Notebook API tests', () => { const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); let count = 0; const disposables: vscode.Disposable[] = []; - disposables.push(vscode.notebook.onDidChangeVisibleNotebookEditors(() => { - count = vscode.notebook.visibleNotebookEditors.length; + disposables.push(vscode.window.onDidChangeVisibleNotebookEditors(() => { + count = vscode.window.visibleNotebookEditors.length; })); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); @@ -239,24 +239,24 @@ suite('Notebook API tests', () => { const cellsChangeEvent = getEventOncePromise(vscode.notebook.onDidChangeNotebookCells); await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow'); const cellChangeEventRet = await cellsChangeEvent; - assert.equal(cellChangeEventRet.document, vscode.notebook.activeNotebookEditor?.document); + assert.equal(cellChangeEventRet.document, vscode.window.activeNotebookEditor?.document); assert.equal(cellChangeEventRet.changes.length, 1); assert.deepEqual(cellChangeEventRet.changes[0], { start: 1, deletedCount: 0, deletedItems: [], items: [ - vscode.notebook.activeNotebookEditor!.document.cells[1] + vscode.window.activeNotebookEditor!.document.cells[1] ] }); - const secondCell = vscode.notebook.activeNotebookEditor!.document.cells[1]; + const secondCell = vscode.window.activeNotebookEditor!.document.cells[1]; const moveCellEvent = getEventOncePromise(vscode.notebook.onDidChangeNotebookCells); await vscode.commands.executeCommand('notebook.cell.moveUp'); const moveCellEventRet = await moveCellEvent; assert.deepEqual(moveCellEventRet, { - document: vscode.notebook.activeNotebookEditor!.document, + document: vscode.window.activeNotebookEditor!.document, changes: [ { start: 1, @@ -268,7 +268,7 @@ suite('Notebook API tests', () => { start: 0, deletedCount: 0, deletedItems: [], - items: [vscode.notebook.activeNotebookEditor?.document.cells[0]] + items: [vscode.window.activeNotebookEditor?.document.cells[0]] } ] }); @@ -277,8 +277,8 @@ suite('Notebook API tests', () => { await vscode.commands.executeCommand('notebook.cell.execute'); const cellOutputsAddedRet = await cellOutputChange; assert.deepEqual(cellOutputsAddedRet, { - document: vscode.notebook.activeNotebookEditor!.document, - cells: [vscode.notebook.activeNotebookEditor!.document.cells[0]] + document: vscode.window.activeNotebookEditor!.document, + cells: [vscode.window.activeNotebookEditor!.document.cells[0]] }); assert.equal(cellOutputsAddedRet.cells[0].outputs.length, 1); @@ -286,8 +286,8 @@ suite('Notebook API tests', () => { await vscode.commands.executeCommand('notebook.cell.clearOutputs'); const cellOutputsCleardRet = await cellOutputClear; assert.deepEqual(cellOutputsCleardRet, { - document: vscode.notebook.activeNotebookEditor!.document, - cells: [vscode.notebook.activeNotebookEditor!.document.cells[0]] + document: vscode.window.activeNotebookEditor!.document, + cells: [vscode.window.activeNotebookEditor!.document.cells[0]] }); assert.equal(cellOutputsAddedRet.cells[0].outputs.length, 0); @@ -295,8 +295,8 @@ suite('Notebook API tests', () => { // await vscode.commands.executeCommand('notebook.cell.changeToMarkdown'); // const cellChangeLanguageRet = await cellChangeLanguage; // assert.deepEqual(cellChangeLanguageRet, { - // document: vscode.notebook.activeNotebookEditor!.document, - // cells: vscode.notebook.activeNotebookEditor!.document.cells[0], + // document: vscode.window.activeNotebookEditor!.document, + // cells: vscode.window.activeNotebookEditor!.document.cells[0], // language: 'markdown' // }); @@ -312,13 +312,13 @@ suite('Notebook API tests', () => { await vscode.commands.executeCommand('notebook.cell.insertCodeCellAbove'); await vscode.commands.executeCommand('notebook.focusTop'); - const activeCell = vscode.notebook.activeNotebookEditor!.selection; - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 0); + const activeCell = vscode.window.activeNotebookEditor!.selection; + assert.equal(vscode.window.activeNotebookEditor!.document.cells.indexOf(activeCell!), 0); const moveChange = getEventOncePromise(vscode.notebook.onDidChangeNotebookCells); await vscode.commands.executeCommand('notebook.cell.moveDown'); const ret = await moveChange; assert.deepEqual(ret, { - document: vscode.notebook.activeNotebookEditor?.document, + document: vscode.window.activeNotebookEditor?.document, changes: [ { start: 0, @@ -339,7 +339,7 @@ suite('Notebook API tests', () => { await vscode.commands.executeCommand('workbench.action.closeAllEditors'); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - const firstEditor = vscode.notebook.activeNotebookEditor; + const firstEditor = vscode.window.activeNotebookEditor; assert.equal(firstEditor?.document.cells.length, 1); await vscode.commands.executeCommand('workbench.action.files.save'); @@ -350,33 +350,31 @@ suite('Notebook API tests', () => { assertInitalState(); const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - const firstEditor = vscode.notebook.activeNotebookEditor; - assert.equal(firstEditor?.active, true); - assert.equal(firstEditor?.visible, true); + const firstEditor = vscode.window.activeNotebookEditor; + assert.strictEqual(firstEditor && vscode.window.visibleNotebookEditors.indexOf(firstEditor) >= 0, true); await splitEditor(); - const secondEditor = vscode.notebook.activeNotebookEditor; - assert.equal(secondEditor?.active, true); - assert.equal(secondEditor?.visible, true); - assert.equal(firstEditor?.active, false); + const secondEditor = vscode.window.activeNotebookEditor; + assert.strictEqual(secondEditor && vscode.window.visibleNotebookEditors.indexOf(secondEditor) >= 0, true); + assert.notStrictEqual(firstEditor, secondEditor); + assert.strictEqual(firstEditor && vscode.window.visibleNotebookEditors.indexOf(firstEditor) < 0, true); + assert.equal(vscode.window.visibleNotebookEditors.length, 2); - assert.equal(vscode.notebook.visibleNotebookEditors.length, 2); - - const untitledEditorChange = getEventOncePromise(vscode.notebook.onDidChangeActiveNotebookEditor); + const untitledEditorChange = getEventOncePromise(vscode.window.onDidChangeActiveNotebookEditor); await vscode.commands.executeCommand('workbench.action.files.newUntitledFile'); await untitledEditorChange; - assert.equal(firstEditor?.visible, true); - assert.equal(firstEditor?.active, false); - assert.equal(secondEditor?.visible, false); - assert.equal(secondEditor?.active, false); - assert.equal(vscode.notebook.visibleNotebookEditors.length, 1); + assert.strictEqual(firstEditor && vscode.window.visibleNotebookEditors.indexOf(firstEditor) < 0, true); + assert.notStrictEqual(firstEditor, vscode.window.activeNotebookEditor); + assert.strictEqual(secondEditor && vscode.window.visibleNotebookEditors.indexOf(secondEditor) < 0, true); + assert.notStrictEqual(secondEditor, vscode.window.activeNotebookEditor); + assert.equal(vscode.window.visibleNotebookEditors.length, 1); - const activeEditorClose = getEventOncePromise(vscode.notebook.onDidChangeActiveNotebookEditor); + const activeEditorClose = getEventOncePromise(vscode.window.onDidChangeActiveNotebookEditor); await vscode.commands.executeCommand('workbench.action.closeActiveEditor'); await activeEditorClose; - assert.equal(secondEditor?.active, true); - assert.equal(secondEditor?.visible, true); - assert.equal(vscode.notebook.visibleNotebookEditors.length, 2); + assert.strictEqual(secondEditor, vscode.window.activeNotebookEditor); + assert.equal(vscode.window.visibleNotebookEditors.length, 2); + assert.strictEqual(secondEditor && vscode.window.visibleNotebookEditors.indexOf(secondEditor) >= 0, true); await vscode.commands.executeCommand('workbench.action.files.save'); await vscode.commands.executeCommand('workbench.action.closeAllEditors'); @@ -385,11 +383,11 @@ suite('Notebook API tests', () => { test('notebook active editor change', async function () { assertInitalState(); const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); - const firstEditorOpen = getEventOncePromise(vscode.notebook.onDidChangeActiveNotebookEditor); + const firstEditorOpen = getEventOncePromise(vscode.window.onDidChangeActiveNotebookEditor); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); await firstEditorOpen; - const firstEditorDeactivate = getEventOncePromise(vscode.notebook.onDidChangeActiveNotebookEditor); + const firstEditorDeactivate = getEventOncePromise(vscode.window.onDidChangeActiveNotebookEditor); await vscode.commands.executeCommand('workbench.action.splitEditor'); await firstEditorDeactivate; @@ -402,17 +400,17 @@ suite('Notebook API tests', () => { await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); const cellsChangeEvent = getEventOncePromise(vscode.notebook.onDidChangeNotebookCells); - await vscode.notebook.activeNotebookEditor!.edit(editBuilder => { + await vscode.window.activeNotebookEditor!.edit(editBuilder => { editBuilder.replaceCells(1, 0, [{ cellKind: vscode.CellKind.Code, language: 'javascript', source: 'test 2', outputs: [], metadata: undefined }]); }); const cellChangeEventRet = await cellsChangeEvent; - assert.strictEqual(cellChangeEventRet.document === vscode.notebook.activeNotebookEditor?.document, true); + assert.strictEqual(cellChangeEventRet.document === vscode.window.activeNotebookEditor?.document, true); assert.strictEqual(cellChangeEventRet.document.isDirty, true); assert.strictEqual(cellChangeEventRet.changes.length, 1); assert.strictEqual(cellChangeEventRet.changes[0].start, 1); assert.strictEqual(cellChangeEventRet.changes[0].deletedCount, 0); - assert.strictEqual(cellChangeEventRet.changes[0].items[0] === vscode.notebook.activeNotebookEditor!.document.cells[1], true); + assert.strictEqual(cellChangeEventRet.changes[0].items[0] === vscode.window.activeNotebookEditor!.document.cells[1], true); await saveAllFilesAndCloseAll(resource); }); @@ -422,14 +420,14 @@ suite('Notebook API tests', () => { const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - await vscode.notebook.activeNotebookEditor!.edit(editBuilder => { + await vscode.window.activeNotebookEditor!.edit(editBuilder => { editBuilder.replaceCellOutput(0, [new vscode.NotebookCellOutput([ new vscode.NotebookCellOutputItem('application/foo', 'bar'), new vscode.NotebookCellOutputItem('application/json', { data: true }, { metadata: true }), ])]); }); - const document = vscode.notebook.activeNotebookEditor?.document!; + const document = vscode.window.activeNotebookEditor?.document!; assert.strictEqual(document.isDirty, true); assert.strictEqual(document.cells.length, 1); assert.strictEqual(document.cells[0].outputs.length, 1); @@ -450,11 +448,11 @@ suite('Notebook API tests', () => { const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - await vscode.notebook.activeNotebookEditor!.edit(editBuilder => { + await vscode.window.activeNotebookEditor!.edit(editBuilder => { editBuilder.replaceCellOutput(0, [{ outputKind: vscode.CellOutputKind.Rich, data: { foo: 'bar' } }]); }); - const document = vscode.notebook.activeNotebookEditor?.document!; + const document = vscode.window.activeNotebookEditor?.document!; assert.strictEqual(document.isDirty, true); assert.strictEqual(document.cells.length, 1); assert.strictEqual(document.cells[0].outputs.length, 1); @@ -469,12 +467,12 @@ suite('Notebook API tests', () => { await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); const outputChangeEvent = getEventOncePromise(vscode.notebook.onDidChangeCellOutputs); - await vscode.notebook.activeNotebookEditor!.edit(editBuilder => { + await vscode.window.activeNotebookEditor!.edit(editBuilder => { editBuilder.replaceCellOutput(0, [{ outputKind: vscode.CellOutputKind.Rich, data: { foo: 'bar' } }]); }); const value = await outputChangeEvent; - assert.strictEqual(value.document === vscode.notebook.activeNotebookEditor?.document, true); + assert.strictEqual(value.document === vscode.window.activeNotebookEditor?.document, true); assert.strictEqual(value.document.isDirty, true); assert.strictEqual(value.cells.length, 1); assert.strictEqual(value.cells[0].outputs.length, 1); @@ -489,11 +487,11 @@ suite('Notebook API tests', () => { const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - await vscode.notebook.activeNotebookEditor!.edit(editBuilder => { + await vscode.window.activeNotebookEditor!.edit(editBuilder => { editBuilder.replaceCellMetadata(0, { inputCollapsed: true, executionOrder: 17 }); }); - const document = vscode.notebook.activeNotebookEditor?.document!; + const document = vscode.window.activeNotebookEditor?.document!; assert.strictEqual(document.cells.length, 1); assert.strictEqual(document.cells[0].metadata.executionOrder, 17); assert.strictEqual(document.cells[0].metadata.inputCollapsed, true); @@ -510,12 +508,12 @@ suite('Notebook API tests', () => { const event = getEventOncePromise(vscode.notebook.onDidChangeCellMetadata); - await vscode.notebook.activeNotebookEditor!.edit(editBuilder => { + await vscode.window.activeNotebookEditor!.edit(editBuilder => { editBuilder.replaceCellMetadata(0, { inputCollapsed: true, executionOrder: 17 }); }); const data = await event; - assert.strictEqual(data.document, vscode.notebook.activeNotebookEditor?.document); + assert.strictEqual(data.document, vscode.window.activeNotebookEditor?.document); assert.strictEqual(data.cell.metadata.executionOrder, 17); assert.strictEqual(data.cell.metadata.inputCollapsed, true); @@ -529,7 +527,7 @@ suite('Notebook API tests', () => { const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - const { document } = vscode.notebook.activeNotebookEditor!; + const { document } = vscode.window.activeNotebookEditor!; assert.strictEqual(document.cells.length, 1); // inserting two new cells @@ -610,7 +608,7 @@ suite('Notebook API tests', () => { const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - const { document } = vscode.notebook.activeNotebookEditor!; + const { document } = vscode.window.activeNotebookEditor!; assert.strictEqual(document.cells.length, 1); const edit = new vscode.WorkspaceEdit(); @@ -658,15 +656,15 @@ suite('Notebook API tests', () => { const cellsChangeEvent = getEventOncePromise(vscode.notebook.onDidChangeNotebookCells); const cellMetadataChangeEvent = getEventOncePromise(vscode.notebook.onDidChangeCellMetadata); - const version = vscode.notebook.activeNotebookEditor!.document.version; - await vscode.notebook.activeNotebookEditor!.edit(editBuilder => { + const version = vscode.window.activeNotebookEditor!.document.version; + await vscode.window.activeNotebookEditor!.edit(editBuilder => { editBuilder.replaceCells(1, 0, [{ cellKind: vscode.CellKind.Code, language: 'javascript', source: 'test 2', outputs: [], metadata: undefined }]); editBuilder.replaceCellMetadata(0, { runnable: false }); }); await cellsChangeEvent; await cellMetadataChangeEvent; - assert.strictEqual(version + 1, vscode.notebook.activeNotebookEditor!.document.version); + assert.strictEqual(version + 1, vscode.window.activeNotebookEditor!.document.version); await saveAllFilesAndCloseAll(resource); }); @@ -677,22 +675,22 @@ suite('Notebook API tests', () => { const cellsChangeEvent = getEventOncePromise(vscode.notebook.onDidChangeNotebookCells); const cellMetadataChangeEvent = getEventOncePromise(vscode.notebook.onDidChangeCellMetadata); - const version = vscode.notebook.activeNotebookEditor!.document.version; - await vscode.notebook.activeNotebookEditor!.edit(editBuilder => { + const version = vscode.window.activeNotebookEditor!.document.version; + await vscode.window.activeNotebookEditor!.edit(editBuilder => { editBuilder.replaceCells(1, 0, [{ cellKind: vscode.CellKind.Code, language: 'javascript', source: 'test 2', outputs: [], metadata: undefined }]); editBuilder.replaceCellMetadata(0, { runnable: false }); }); await cellsChangeEvent; await cellMetadataChangeEvent; - assert.strictEqual(vscode.notebook.activeNotebookEditor!.document.cells.length, 2); - assert.strictEqual(vscode.notebook.activeNotebookEditor!.document.cells[0]?.metadata?.runnable, false); - assert.strictEqual(version + 1, vscode.notebook.activeNotebookEditor!.document.version); + assert.strictEqual(vscode.window.activeNotebookEditor!.document.cells.length, 2); + assert.strictEqual(vscode.window.activeNotebookEditor!.document.cells[0]?.metadata?.runnable, false); + assert.strictEqual(version + 1, vscode.window.activeNotebookEditor!.document.version); await vscode.commands.executeCommand('undo'); - assert.strictEqual(version + 2, vscode.notebook.activeNotebookEditor!.document.version); - assert.strictEqual(vscode.notebook.activeNotebookEditor!.document.cells[0]?.metadata?.runnable, undefined); - assert.strictEqual(vscode.notebook.activeNotebookEditor!.document.cells.length, 1); + assert.strictEqual(version + 2, vscode.window.activeNotebookEditor!.document.version); + assert.strictEqual(vscode.window.activeNotebookEditor!.document.cells[0]?.metadata?.runnable, undefined); + assert.strictEqual(vscode.window.activeNotebookEditor!.document.cells.length, 1); await saveAllFilesAndCloseAll(resource); }); @@ -721,19 +719,19 @@ suite('notebook workflow', () => { assertInitalState(); const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first'); - assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), 'test'); - assert.equal(vscode.notebook.activeNotebookEditor!.selection?.language, 'typescript'); + assert.equal(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first'); + assert.equal(vscode.window.activeNotebookEditor!.selection?.document.getText(), 'test'); + assert.equal(vscode.window.activeNotebookEditor!.selection?.language, 'typescript'); await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow'); - assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), ''); + assert.equal(vscode.window.activeNotebookEditor!.selection?.document.getText(), ''); await vscode.commands.executeCommand('notebook.cell.insertCodeCellAbove'); - const activeCell = vscode.notebook.activeNotebookEditor!.selection; - assert.notEqual(vscode.notebook.activeNotebookEditor!.selection, undefined); + const activeCell = vscode.window.activeNotebookEditor!.selection; + assert.notEqual(vscode.window.activeNotebookEditor!.selection, undefined); assert.equal(activeCell!.document.getText(), ''); - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.length, 3); - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1); + assert.equal(vscode.window.activeNotebookEditor!.document.cells.length, 3); + assert.equal(vscode.window.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1); await vscode.commands.executeCommand('workbench.action.files.save'); await vscode.commands.executeCommand('workbench.action.closeActiveEditor'); @@ -743,69 +741,69 @@ suite('notebook workflow', () => { assertInitalState(); const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first'); - assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), 'test'); - assert.equal(vscode.notebook.activeNotebookEditor!.selection?.language, 'typescript'); + assert.equal(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first'); + assert.equal(vscode.window.activeNotebookEditor!.selection?.document.getText(), 'test'); + assert.equal(vscode.window.activeNotebookEditor!.selection?.language, 'typescript'); // ---- insert cell below and focus ---- // await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow'); - assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), ''); + assert.equal(vscode.window.activeNotebookEditor!.selection?.document.getText(), ''); // ---- insert cell above and focus ---- // await vscode.commands.executeCommand('notebook.cell.insertCodeCellAbove'); - let activeCell = vscode.notebook.activeNotebookEditor!.selection; - assert.notEqual(vscode.notebook.activeNotebookEditor!.selection, undefined); + let activeCell = vscode.window.activeNotebookEditor!.selection; + assert.notEqual(vscode.window.activeNotebookEditor!.selection, undefined); assert.equal(activeCell!.document.getText(), ''); - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.length, 3); - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1); + assert.equal(vscode.window.activeNotebookEditor!.document.cells.length, 3); + assert.equal(vscode.window.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1); // ---- focus bottom ---- // await vscode.commands.executeCommand('notebook.focusBottom'); - activeCell = vscode.notebook.activeNotebookEditor!.selection; - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 2); + activeCell = vscode.window.activeNotebookEditor!.selection; + assert.equal(vscode.window.activeNotebookEditor!.document.cells.indexOf(activeCell!), 2); // ---- focus top and then copy down ---- // await vscode.commands.executeCommand('notebook.focusTop'); - activeCell = vscode.notebook.activeNotebookEditor!.selection; - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 0); + activeCell = vscode.window.activeNotebookEditor!.selection; + assert.equal(vscode.window.activeNotebookEditor!.document.cells.indexOf(activeCell!), 0); await vscode.commands.executeCommand('notebook.cell.copyDown'); - activeCell = vscode.notebook.activeNotebookEditor!.selection; - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1); + activeCell = vscode.window.activeNotebookEditor!.selection; + assert.equal(vscode.window.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1); assert.equal(activeCell?.document.getText(), 'test'); await vscode.commands.executeCommand('notebook.cell.delete'); - activeCell = vscode.notebook.activeNotebookEditor!.selection; - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1); + activeCell = vscode.window.activeNotebookEditor!.selection; + assert.equal(vscode.window.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1); assert.equal(activeCell?.document.getText(), ''); // ---- focus top and then copy up ---- // await vscode.commands.executeCommand('notebook.focusTop'); await vscode.commands.executeCommand('notebook.cell.copyUp'); - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.length, 4); - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells[0].document.getText(), 'test'); - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells[1].document.getText(), 'test'); - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells[2].document.getText(), ''); - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells[3].document.getText(), ''); - activeCell = vscode.notebook.activeNotebookEditor!.selection; - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 0); + assert.equal(vscode.window.activeNotebookEditor!.document.cells.length, 4); + assert.equal(vscode.window.activeNotebookEditor!.document.cells[0].document.getText(), 'test'); + assert.equal(vscode.window.activeNotebookEditor!.document.cells[1].document.getText(), 'test'); + assert.equal(vscode.window.activeNotebookEditor!.document.cells[2].document.getText(), ''); + assert.equal(vscode.window.activeNotebookEditor!.document.cells[3].document.getText(), ''); + activeCell = vscode.window.activeNotebookEditor!.selection; + assert.equal(vscode.window.activeNotebookEditor!.document.cells.indexOf(activeCell!), 0); // ---- move up and down ---- // await vscode.commands.executeCommand('notebook.cell.moveDown'); - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(vscode.notebook.activeNotebookEditor!.selection!), 1, - `first move down, active cell ${vscode.notebook.activeNotebookEditor!.selection!.uri.toString()}, ${vscode.notebook.activeNotebookEditor!.selection!.document.getText()}`); + assert.equal(vscode.window.activeNotebookEditor!.document.cells.indexOf(vscode.window.activeNotebookEditor!.selection!), 1, + `first move down, active cell ${vscode.window.activeNotebookEditor!.selection!.uri.toString()}, ${vscode.window.activeNotebookEditor!.selection!.document.getText()}`); // await vscode.commands.executeCommand('notebook.cell.moveDown'); - // activeCell = vscode.notebook.activeNotebookEditor!.selection; + // activeCell = vscode.window.activeNotebookEditor!.selection; - // assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 2, - // `second move down, active cell ${vscode.notebook.activeNotebookEditor!.selection!.uri.toString()}, ${vscode.notebook.activeNotebookEditor!.selection!.document.getText()}`); - // assert.equal(vscode.notebook.activeNotebookEditor!.document.cells[0].document.getText(), 'test'); - // assert.equal(vscode.notebook.activeNotebookEditor!.document.cells[1].document.getText(), ''); - // assert.equal(vscode.notebook.activeNotebookEditor!.document.cells[2].document.getText(), 'test'); - // assert.equal(vscode.notebook.activeNotebookEditor!.document.cells[3].document.getText(), ''); + // assert.equal(vscode.window.activeNotebookEditor!.document.cells.indexOf(activeCell!), 2, + // `second move down, active cell ${vscode.window.activeNotebookEditor!.selection!.uri.toString()}, ${vscode.window.activeNotebookEditor!.selection!.document.getText()}`); + // assert.equal(vscode.window.activeNotebookEditor!.document.cells[0].document.getText(), 'test'); + // assert.equal(vscode.window.activeNotebookEditor!.document.cells[1].document.getText(), ''); + // assert.equal(vscode.window.activeNotebookEditor!.document.cells[2].document.getText(), 'test'); + // assert.equal(vscode.window.activeNotebookEditor!.document.cells[3].document.getText(), ''); // ---- ---- // @@ -817,21 +815,21 @@ suite('notebook workflow', () => { assertInitalState(); const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first'); - assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), 'test'); - assert.equal(vscode.notebook.activeNotebookEditor!.selection?.language, 'typescript'); + assert.equal(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first'); + assert.equal(vscode.window.activeNotebookEditor!.selection?.document.getText(), 'test'); + assert.equal(vscode.window.activeNotebookEditor!.selection?.language, 'typescript'); await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow'); - assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), ''); + assert.equal(vscode.window.activeNotebookEditor!.selection?.document.getText(), ''); const edit = new vscode.WorkspaceEdit(); - edit.insert(vscode.notebook.activeNotebookEditor!.selection!.uri, new vscode.Position(0, 0), 'var abc = 0;'); + edit.insert(vscode.window.activeNotebookEditor!.selection!.uri, new vscode.Position(0, 0), 'var abc = 0;'); await vscode.workspace.applyEdit(edit); const cellsChangeEvent = getEventOncePromise(vscode.notebook.onDidChangeNotebookCells); await vscode.commands.executeCommand('notebook.cell.joinAbove'); await cellsChangeEvent; - assert.deepEqual(vscode.notebook.activeNotebookEditor!.selection?.document.getText().split(/\r\n|\r|\n/), ['test', 'var abc = 0;']); + assert.deepEqual(vscode.window.activeNotebookEditor!.selection?.document.getText().split(/\r\n|\r|\n/), ['test', 'var abc = 0;']); await vscode.commands.executeCommand('workbench.action.files.save'); await vscode.commands.executeCommand('workbench.action.closeActiveEditor'); @@ -845,25 +843,25 @@ suite('notebook workflow', () => { await vscode.commands.executeCommand('notebook.cell.insertCodeCellAbove'); await vscode.commands.executeCommand('notebook.focusTop'); - const activeCell = vscode.notebook.activeNotebookEditor!.selection; - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 0); + const activeCell = vscode.window.activeNotebookEditor!.selection; + assert.equal(vscode.window.activeNotebookEditor!.document.cells.indexOf(activeCell!), 0); await vscode.commands.executeCommand('notebook.cell.moveDown'); await vscode.commands.executeCommand('notebook.cell.moveDown'); - const newActiveCell = vscode.notebook.activeNotebookEditor!.selection; + const newActiveCell = vscode.window.activeNotebookEditor!.selection; assert.deepEqual(activeCell, newActiveCell); await saveFileAndCloseAll(resource); // TODO@rebornix, there are still some events order issue. - // assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(newActiveCell!), 2); + // assert.equal(vscode.window.activeNotebookEditor!.document.cells.indexOf(newActiveCell!), 2); }); // test.only('document metadata is respected', async function () { // const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); // await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - // assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first'); - // const editor = vscode.notebook.activeNotebookEditor!; + // assert.equal(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first'); + // const editor = vscode.window.activeNotebookEditor!; // assert.equal(editor.document.cells.length, 1); // editor.document.metadata.editable = false; @@ -886,8 +884,8 @@ suite('notebook workflow', () => { assertInitalState(); const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first'); - const editor = vscode.notebook.activeNotebookEditor!; + assert.equal(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first'); + const editor = vscode.window.activeNotebookEditor!; await vscode.commands.executeCommand('notebook.focusTop'); const cell = editor.document.cells[0]; @@ -915,8 +913,8 @@ suite('notebook workflow', () => { assertInitalState(); const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first'); - const editor = vscode.notebook.activeNotebookEditor!; + assert.equal(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first'); + const editor = vscode.window.activeNotebookEditor!; const cell = editor.document.cells[0]; assert.equal(cell.outputs.length, 0); @@ -944,27 +942,27 @@ suite('notebook dirty state', () => { assertInitalState(); const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first'); - assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), 'test'); - assert.equal(vscode.notebook.activeNotebookEditor!.selection?.language, 'typescript'); + assert.equal(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first'); + assert.equal(vscode.window.activeNotebookEditor!.selection?.document.getText(), 'test'); + assert.equal(vscode.window.activeNotebookEditor!.selection?.language, 'typescript'); await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow'); - assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), ''); + assert.equal(vscode.window.activeNotebookEditor!.selection?.document.getText(), ''); await vscode.commands.executeCommand('notebook.cell.insertCodeCellAbove'); - const activeCell = vscode.notebook.activeNotebookEditor!.selection; - assert.notEqual(vscode.notebook.activeNotebookEditor!.selection, undefined); + const activeCell = vscode.window.activeNotebookEditor!.selection; + assert.notEqual(vscode.window.activeNotebookEditor!.selection, undefined); assert.equal(activeCell!.document.getText(), ''); - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.length, 3); - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1); + assert.equal(vscode.window.activeNotebookEditor!.document.cells.length, 3); + assert.equal(vscode.window.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1); const edit = new vscode.WorkspaceEdit(); edit.insert(activeCell!.uri, new vscode.Position(0, 0), 'var abc = 0;'); await vscode.workspace.applyEdit(edit); - assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true); - assert.equal(vscode.notebook.activeNotebookEditor?.selection !== undefined, true); - assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells[1], vscode.notebook.activeNotebookEditor?.selection); - assert.equal(vscode.notebook.activeNotebookEditor?.selection?.document.getText(), 'var abc = 0;'); + assert.equal(vscode.window.activeNotebookEditor !== undefined, true); + assert.equal(vscode.window.activeNotebookEditor?.selection !== undefined, true); + assert.deepEqual(vscode.window.activeNotebookEditor?.document.cells[1], vscode.window.activeNotebookEditor?.selection); + assert.equal(vscode.window.activeNotebookEditor?.selection?.document.getText(), 'var abc = 0;'); await saveFileAndCloseAll(resource); }); @@ -975,41 +973,41 @@ suite('notebook undo redo', () => { assertInitalState(); const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first'); - assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), 'test'); - assert.equal(vscode.notebook.activeNotebookEditor!.selection?.language, 'typescript'); + assert.equal(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first'); + assert.equal(vscode.window.activeNotebookEditor!.selection?.document.getText(), 'test'); + assert.equal(vscode.window.activeNotebookEditor!.selection?.language, 'typescript'); await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow'); - assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), ''); + assert.equal(vscode.window.activeNotebookEditor!.selection?.document.getText(), ''); await vscode.commands.executeCommand('notebook.cell.insertCodeCellAbove'); - const activeCell = vscode.notebook.activeNotebookEditor!.selection; - assert.notEqual(vscode.notebook.activeNotebookEditor!.selection, undefined); + const activeCell = vscode.window.activeNotebookEditor!.selection; + assert.notEqual(vscode.window.activeNotebookEditor!.selection, undefined); assert.equal(activeCell!.document.getText(), ''); - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.length, 3); - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1); + assert.equal(vscode.window.activeNotebookEditor!.document.cells.length, 3); + assert.equal(vscode.window.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1); // modify the second cell, delete it const edit = new vscode.WorkspaceEdit(); - edit.insert(vscode.notebook.activeNotebookEditor!.selection!.uri, new vscode.Position(0, 0), 'var abc = 0;'); + edit.insert(vscode.window.activeNotebookEditor!.selection!.uri, new vscode.Position(0, 0), 'var abc = 0;'); await vscode.workspace.applyEdit(edit); await vscode.commands.executeCommand('notebook.cell.delete'); - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.length, 2); - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(vscode.notebook.activeNotebookEditor!.selection!), 1); + assert.equal(vscode.window.activeNotebookEditor!.document.cells.length, 2); + assert.equal(vscode.window.activeNotebookEditor!.document.cells.indexOf(vscode.window.activeNotebookEditor!.selection!), 1); // undo should bring back the deleted cell, and revert to previous content and selection await vscode.commands.executeCommand('undo'); - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.length, 3); - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(vscode.notebook.activeNotebookEditor!.selection!), 1); - assert.equal(vscode.notebook.activeNotebookEditor?.selection?.document.getText(), 'var abc = 0;'); + assert.equal(vscode.window.activeNotebookEditor!.document.cells.length, 3); + assert.equal(vscode.window.activeNotebookEditor!.document.cells.indexOf(vscode.window.activeNotebookEditor!.selection!), 1); + assert.equal(vscode.window.activeNotebookEditor?.selection?.document.getText(), 'var abc = 0;'); // redo // await vscode.commands.executeCommand('notebook.redo'); - // assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.length, 2); - // assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(vscode.notebook.activeNotebookEditor!.selection!), 1); - // assert.equal(vscode.notebook.activeNotebookEditor?.selection?.document.getText(), 'test'); + // assert.equal(vscode.window.activeNotebookEditor!.document.cells.length, 2); + // assert.equal(vscode.window.activeNotebookEditor!.document.cells.indexOf(vscode.window.activeNotebookEditor!.selection!), 1); + // assert.equal(vscode.window.activeNotebookEditor?.selection?.document.getText(), 'test'); await saveFileAndCloseAll(resource); }); @@ -1022,24 +1020,24 @@ suite('notebook undo redo', () => { const cellsChangeEvent = getEventOncePromise(vscode.notebook.onDidChangeNotebookCells); await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow'); const cellChangeEventRet = await cellsChangeEvent; - assert.equal(cellChangeEventRet.document, vscode.notebook.activeNotebookEditor?.document); + assert.equal(cellChangeEventRet.document, vscode.window.activeNotebookEditor?.document); assert.equal(cellChangeEventRet.changes.length, 1); assert.deepEqual(cellChangeEventRet.changes[0], { start: 1, deletedCount: 0, deletedItems: [], items: [ - vscode.notebook.activeNotebookEditor!.document.cells[1] + vscode.window.activeNotebookEditor!.document.cells[1] ] }); - const secondCell = vscode.notebook.activeNotebookEditor!.document.cells[1]; + const secondCell = vscode.window.activeNotebookEditor!.document.cells[1]; const moveCellEvent = getEventOncePromise(vscode.notebook.onDidChangeNotebookCells); await vscode.commands.executeCommand('notebook.cell.moveUp'); const moveCellEventRet = await moveCellEvent; assert.deepEqual(moveCellEventRet, { - document: vscode.notebook.activeNotebookEditor!.document, + document: vscode.window.activeNotebookEditor!.document, changes: [ { start: 1, @@ -1051,7 +1049,7 @@ suite('notebook undo redo', () => { start: 0, deletedCount: 0, deletedItems: [], - items: [vscode.notebook.activeNotebookEditor?.document.cells[0]] + items: [vscode.window.activeNotebookEditor?.document.cells[0]] } ] }); @@ -1060,8 +1058,8 @@ suite('notebook undo redo', () => { await vscode.commands.executeCommand('notebook.cell.execute'); const cellOutputsAddedRet = await cellOutputChange; assert.deepEqual(cellOutputsAddedRet, { - document: vscode.notebook.activeNotebookEditor!.document, - cells: [vscode.notebook.activeNotebookEditor!.document.cells[0]] + document: vscode.window.activeNotebookEditor!.document, + cells: [vscode.window.activeNotebookEditor!.document.cells[0]] }); assert.equal(cellOutputsAddedRet.cells[0].outputs.length, 1); @@ -1069,8 +1067,8 @@ suite('notebook undo redo', () => { await vscode.commands.executeCommand('undo'); const cellOutputsCleardRet = await cellOutputClear; assert.deepEqual(cellOutputsCleardRet, { - document: vscode.notebook.activeNotebookEditor!.document, - cells: [vscode.notebook.activeNotebookEditor!.document.cells[0]] + document: vscode.window.activeNotebookEditor!.document, + cells: [vscode.window.activeNotebookEditor!.document.cells[0]] }); assert.equal(cellOutputsAddedRet.cells[0].outputs.length, 0); @@ -1084,7 +1082,7 @@ suite('notebook working copy', () => { // const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); // await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); // await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow'); - // assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), ''); + // assert.equal(vscode.window.activeNotebookEditor!.selection?.document.getText(), ''); // await vscode.commands.executeCommand('notebook.cell.insertCodeCellAbove'); // await vscode.commands.executeCommand('default:type', { text: 'var abc = 0;' }); @@ -1092,10 +1090,10 @@ suite('notebook working copy', () => { // // close active editor from command will revert the file // await vscode.commands.executeCommand('workbench.action.closeActiveEditor'); // await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - // assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true); - // assert.equal(vscode.notebook.activeNotebookEditor?.selection !== undefined, true); - // assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells[0], vscode.notebook.activeNotebookEditor?.selection); - // assert.equal(vscode.notebook.activeNotebookEditor?.selection?.document.getText(), 'test'); + // assert.equal(vscode.window.activeNotebookEditor !== undefined, true); + // assert.equal(vscode.window.activeNotebookEditor?.selection !== undefined, true); + // assert.deepEqual(vscode.window.activeNotebookEditor?.document.cells[0], vscode.window.activeNotebookEditor?.selection); + // assert.equal(vscode.window.activeNotebookEditor?.selection?.document.getText(), 'test'); // await vscode.commands.executeCommand('workbench.action.files.save'); // await vscode.commands.executeCommand('workbench.action.closeActiveEditor'); @@ -1105,17 +1103,17 @@ suite('notebook working copy', () => { // const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); // await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); // await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow'); - // assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), ''); + // assert.equal(vscode.window.activeNotebookEditor!.selection?.document.getText(), ''); // await vscode.commands.executeCommand('notebook.cell.insertCodeCellAbove'); // await vscode.commands.executeCommand('default:type', { text: 'var abc = 0;' }); // await vscode.commands.executeCommand('workbench.action.files.revert'); - // assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true); - // assert.equal(vscode.notebook.activeNotebookEditor?.selection !== undefined, true); - // assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells[0], vscode.notebook.activeNotebookEditor?.selection); - // assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells.length, 1); - // assert.equal(vscode.notebook.activeNotebookEditor?.selection?.document.getText(), 'test'); + // assert.equal(vscode.window.activeNotebookEditor !== undefined, true); + // assert.equal(vscode.window.activeNotebookEditor?.selection !== undefined, true); + // assert.deepEqual(vscode.window.activeNotebookEditor?.document.cells[0], vscode.window.activeNotebookEditor?.selection); + // assert.deepEqual(vscode.window.activeNotebookEditor?.document.cells.length, 1); + // assert.equal(vscode.window.activeNotebookEditor?.selection?.document.getText(), 'test'); // await vscode.commands.executeCommand('workbench.action.files.saveAll'); // await vscode.commands.executeCommand('workbench.action.closeAllEditors'); @@ -1126,11 +1124,11 @@ suite('notebook working copy', () => { const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow'); - assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), ''); + assert.equal(vscode.window.activeNotebookEditor!.selection?.document.getText(), ''); await vscode.commands.executeCommand('notebook.cell.insertCodeCellAbove'); const edit = new vscode.WorkspaceEdit(); - edit.insert(vscode.notebook.activeNotebookEditor!.selection!.uri, new vscode.Position(0, 0), 'var abc = 0;'); + edit.insert(vscode.window.activeNotebookEditor!.selection!.uri, new vscode.Position(0, 0), 'var abc = 0;'); await vscode.workspace.applyEdit(edit); const secondResource = await createRandomFile('', undefined, 'second', '.vsctestnb'); @@ -1138,11 +1136,11 @@ suite('notebook working copy', () => { await vscode.commands.executeCommand('workbench.action.closeActiveEditor'); // make sure that the previous dirty editor is still restored in the extension host and no data loss - assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true); - assert.equal(vscode.notebook.activeNotebookEditor?.selection !== undefined, true); - assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells[1], vscode.notebook.activeNotebookEditor?.selection); - assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells.length, 3); - assert.equal(vscode.notebook.activeNotebookEditor?.selection?.document.getText(), 'var abc = 0;'); + assert.equal(vscode.window.activeNotebookEditor !== undefined, true); + assert.equal(vscode.window.activeNotebookEditor?.selection !== undefined, true); + assert.deepEqual(vscode.window.activeNotebookEditor?.document.cells[1], vscode.window.activeNotebookEditor?.selection); + assert.deepEqual(vscode.window.activeNotebookEditor?.document.cells.length, 3); + assert.equal(vscode.window.activeNotebookEditor?.selection?.document.getText(), 'var abc = 0;'); await saveFileAndCloseAll(resource); }); @@ -1152,33 +1150,33 @@ suite('notebook working copy', () => { const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow'); - assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), ''); + assert.equal(vscode.window.activeNotebookEditor!.selection?.document.getText(), ''); await vscode.commands.executeCommand('notebook.cell.insertCodeCellAbove'); const edit = new vscode.WorkspaceEdit(); - edit.insert(vscode.notebook.activeNotebookEditor!.selection!.uri, new vscode.Position(0, 0), 'var abc = 0;'); + edit.insert(vscode.window.activeNotebookEditor!.selection!.uri, new vscode.Position(0, 0), 'var abc = 0;'); await vscode.workspace.applyEdit(edit); const secondResource = await createRandomFile('', undefined, 'second', '.vsctestnb'); await vscode.commands.executeCommand('vscode.openWith', secondResource, 'notebookCoreTest'); await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow'); - assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), ''); + assert.equal(vscode.window.activeNotebookEditor!.selection?.document.getText(), ''); // switch to the first editor await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true); - assert.equal(vscode.notebook.activeNotebookEditor?.selection !== undefined, true); - assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells[1], vscode.notebook.activeNotebookEditor?.selection); - assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells.length, 3); - assert.equal(vscode.notebook.activeNotebookEditor?.selection?.document.getText(), 'var abc = 0;'); + assert.equal(vscode.window.activeNotebookEditor !== undefined, true); + assert.equal(vscode.window.activeNotebookEditor?.selection !== undefined, true); + assert.deepEqual(vscode.window.activeNotebookEditor?.document.cells[1], vscode.window.activeNotebookEditor?.selection); + assert.deepEqual(vscode.window.activeNotebookEditor?.document.cells.length, 3); + assert.equal(vscode.window.activeNotebookEditor?.selection?.document.getText(), 'var abc = 0;'); // switch to the second editor await vscode.commands.executeCommand('vscode.openWith', secondResource, 'notebookCoreTest'); - assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true); - assert.equal(vscode.notebook.activeNotebookEditor?.selection !== undefined, true); - assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells[1], vscode.notebook.activeNotebookEditor?.selection); - assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells.length, 2); - assert.equal(vscode.notebook.activeNotebookEditor?.selection?.document.getText(), ''); + assert.equal(vscode.window.activeNotebookEditor !== undefined, true); + assert.equal(vscode.window.activeNotebookEditor?.selection !== undefined, true); + assert.deepEqual(vscode.window.activeNotebookEditor?.document.cells[1], vscode.window.activeNotebookEditor?.selection); + assert.deepEqual(vscode.window.activeNotebookEditor?.document.cells.length, 2); + assert.equal(vscode.window.activeNotebookEditor?.selection?.document.getText(), ''); await saveAllFilesAndCloseAll(secondResource); // await vscode.commands.executeCommand('workbench.action.files.saveAll'); @@ -1190,13 +1188,13 @@ suite('notebook working copy', () => { const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - const firstNotebookEditor = vscode.notebook.activeNotebookEditor; + const firstNotebookEditor = vscode.window.activeNotebookEditor; assert.equal(firstNotebookEditor !== undefined, true, 'notebook first'); assert.equal(firstNotebookEditor!.selection?.document.getText(), 'test'); assert.equal(firstNotebookEditor!.selection?.language, 'typescript'); await splitEditor(); - const secondNotebookEditor = vscode.notebook.activeNotebookEditor; + const secondNotebookEditor = vscode.window.activeNotebookEditor; assert.equal(secondNotebookEditor !== undefined, true, 'notebook first'); assert.equal(secondNotebookEditor!.selection?.document.getText(), 'test'); assert.equal(secondNotebookEditor!.selection?.language, 'typescript'); @@ -1217,10 +1215,10 @@ suite('metadata', () => { assertInitalState(); const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first'); - assert.equal(vscode.notebook.activeNotebookEditor!.document.metadata.custom!['testMetadata'] as boolean, false); - assert.equal(vscode.notebook.activeNotebookEditor!.selection?.metadata.custom!['testCellMetadata'] as number, 123); - assert.equal(vscode.notebook.activeNotebookEditor!.selection?.language, 'typescript'); + assert.equal(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first'); + assert.equal(vscode.window.activeNotebookEditor!.document.metadata.custom!['testMetadata'] as boolean, false); + assert.equal(vscode.window.activeNotebookEditor!.selection?.metadata.custom!['testCellMetadata'] as number, 123); + assert.equal(vscode.window.activeNotebookEditor!.selection?.language, 'typescript'); await saveFileAndCloseAll(resource); }); @@ -1231,15 +1229,15 @@ suite('metadata', () => { assertInitalState(); const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first'); - assert.equal(vscode.notebook.activeNotebookEditor!.document.metadata.custom!['testMetadata'] as boolean, false); - assert.equal(vscode.notebook.activeNotebookEditor!.selection?.metadata.custom!['testCellMetadata'] as number, 123); - assert.equal(vscode.notebook.activeNotebookEditor!.selection?.language, 'typescript'); + assert.equal(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first'); + assert.equal(vscode.window.activeNotebookEditor!.document.metadata.custom!['testMetadata'] as boolean, false); + assert.equal(vscode.window.activeNotebookEditor!.selection?.metadata.custom!['testCellMetadata'] as number, 123); + assert.equal(vscode.window.activeNotebookEditor!.selection?.language, 'typescript'); // TODO see #101462 // await vscode.commands.executeCommand('notebook.cell.copyDown'); - // const activeCell = vscode.notebook.activeNotebookEditor!.selection; - // assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1); + // const activeCell = vscode.window.activeNotebookEditor!.selection; + // assert.equal(vscode.window.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1); // assert.equal(activeCell?.metadata.custom!['testCellMetadata'] as number, 123); await saveFileAndCloseAll(resource); @@ -1250,9 +1248,9 @@ suite('regression', () => { // test('microsoft/vscode-github-issue-notebooks#26. Insert template cell in the new empty document', async function () { // assertInitalState(); // await vscode.commands.executeCommand('workbench.action.files.newUntitledFile', { "viewType": "notebookCoreTest" }); - // assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first'); - // assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), ''); - // assert.equal(vscode.notebook.activeNotebookEditor!.selection?.language, 'typescript'); + // assert.equal(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first'); + // assert.equal(vscode.window.activeNotebookEditor!.selection?.document.getText(), ''); + // assert.equal(vscode.window.activeNotebookEditor!.selection?.language, 'typescript'); // await vscode.commands.executeCommand('workbench.action.closeAllEditors'); // }); @@ -1261,17 +1259,17 @@ suite('regression', () => { const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - const document = vscode.notebook.activeNotebookEditor?.document!; + const document = vscode.window.activeNotebookEditor?.document!; const [cell] = document.cells; await saveAllFilesAndCloseAll(document.uri); - assert.strictEqual(vscode.notebook.activeNotebookEditor, undefined); + assert.strictEqual(vscode.window.activeNotebookEditor, undefined); // opening a cell-uri opens a notebook editor await vscode.commands.executeCommand('vscode.open', cell.uri, vscode.ViewColumn.Active); - assert.strictEqual(!!vscode.notebook.activeNotebookEditor, true); - assert.strictEqual(vscode.notebook.activeNotebookEditor?.document.uri.toString(), resource.toString()); + assert.strictEqual(!!vscode.window.activeNotebookEditor, true); + assert.strictEqual(vscode.window.activeNotebookEditor?.document.uri.toString(), resource.toString()); }); test('Cannot open notebook from cell-uri with vscode.open-command', async function () { @@ -1280,17 +1278,17 @@ suite('regression', () => { const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - const document = vscode.notebook.activeNotebookEditor?.document!; + const document = vscode.window.activeNotebookEditor?.document!; const [cell] = document.cells; await saveAllFilesAndCloseAll(document.uri); - assert.strictEqual(vscode.notebook.activeNotebookEditor, undefined); + assert.strictEqual(vscode.window.activeNotebookEditor, undefined); // BUG is that the editor opener (https://github.com/microsoft/vscode/blob/8e7877bdc442f1e83a7fec51920d82b696139129/src/vs/editor/browser/services/openerService.ts#L69) // removes the fragment if it matches something numeric. For notebooks that's not wanted... await vscode.commands.executeCommand('vscode.open', cell.uri); - assert.strictEqual(vscode.notebook.activeNotebookEditor?.document.uri.toString(), resource.toString()); + assert.strictEqual(vscode.window.activeNotebookEditor?.document.uri.toString(), resource.toString()); }); test('#97830, #97764. Support switch to other editor types', async function () { @@ -1299,12 +1297,12 @@ suite('regression', () => { await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow'); const edit = new vscode.WorkspaceEdit(); - edit.insert(vscode.notebook.activeNotebookEditor!.selection!.uri, new vscode.Position(0, 0), 'var abc = 0;'); + edit.insert(vscode.window.activeNotebookEditor!.selection!.uri, new vscode.Position(0, 0), 'var abc = 0;'); await vscode.workspace.applyEdit(edit); - assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first'); - assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), 'var abc = 0;'); - assert.equal(vscode.notebook.activeNotebookEditor!.selection?.language, 'typescript'); + assert.equal(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first'); + assert.equal(vscode.window.activeNotebookEditor!.selection?.document.getText(), 'var abc = 0;'); + assert.equal(vscode.window.activeNotebookEditor!.selection?.language, 'typescript'); await vscode.commands.executeCommand('vscode.openWith', resource, 'default'); assert.equal(vscode.window.activeTextEditor?.document.uri.path, resource.path); @@ -1323,7 +1321,7 @@ suite('regression', () => { // now it's dirty, open the resource with notebook editor should open a new one await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - assert.notEqual(vscode.notebook.activeNotebookEditor, undefined, 'notebook first'); + assert.notEqual(vscode.window.activeNotebookEditor, undefined, 'notebook first'); // assert.notEqual(vscode.window.activeTextEditor, undefined); await vscode.commands.executeCommand('workbench.action.closeAllEditors'); @@ -1332,7 +1330,7 @@ suite('regression', () => { test('#102411 - untitled notebook creation failed', async function () { assertInitalState(); await vscode.commands.executeCommand('workbench.action.files.newUntitledFile', { viewType: 'notebookCoreTest' }); - assert.notEqual(vscode.notebook.activeNotebookEditor, undefined, 'untitled notebook editor is not undefined'); + assert.notEqual(vscode.window.activeNotebookEditor, undefined, 'untitled notebook editor is not undefined'); await vscode.commands.executeCommand('workbench.action.closeAllEditors'); }); @@ -1342,21 +1340,21 @@ suite('regression', () => { const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - let activeCell = vscode.notebook.activeNotebookEditor!.selection; + let activeCell = vscode.window.activeNotebookEditor!.selection; assert.equal(activeCell?.document.getText(), 'test'); await vscode.commands.executeCommand('notebook.cell.copyDown'); await vscode.commands.executeCommand('notebook.cell.edit'); - activeCell = vscode.notebook.activeNotebookEditor!.selection; - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1); + activeCell = vscode.window.activeNotebookEditor!.selection; + assert.equal(vscode.window.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1); assert.equal(activeCell?.document.getText(), 'test'); const edit = new vscode.WorkspaceEdit(); - edit.insert(vscode.notebook.activeNotebookEditor!.selection!.uri, new vscode.Position(0, 0), 'var abc = 0;'); + edit.insert(vscode.window.activeNotebookEditor!.selection!.uri, new vscode.Position(0, 0), 'var abc = 0;'); await vscode.workspace.applyEdit(edit); - assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.length, 2); - assert.notEqual(vscode.notebook.activeNotebookEditor!.document.cells[0].document.getText(), vscode.notebook.activeNotebookEditor!.document.cells[1].document.getText()); + assert.equal(vscode.window.activeNotebookEditor!.document.cells.length, 2); + assert.notEqual(vscode.window.activeNotebookEditor!.document.cells[0].document.getText(), vscode.window.activeNotebookEditor!.document.cells[1].document.getText()); await vscode.commands.executeCommand('workbench.action.closeAllEditors'); }); @@ -1371,8 +1369,8 @@ suite('webview', () => { // const resource = await createRandomFile('', undefined, 'first', '.vsctestnb'); // await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - // assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first'); - // const uri = vscode.notebook.activeNotebookEditor!.asWebviewUri(vscode.Uri.file('./hello.png')); + // assert.equal(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first'); + // const uri = vscode.window.activeNotebookEditor!.asWebviewUri(vscode.Uri.file('./hello.png')); // assert.equal(uri.scheme, 'vscode-webview-resource'); // await vscode.commands.executeCommand('workbench.action.closeAllEditors'); // }); @@ -1387,7 +1385,7 @@ suite('webview', () => { // const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './customRenderer.vsctestnb')); // await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); - // const editor = vscode.notebook.activeNotebookEditor; + // const editor = vscode.window.activeNotebookEditor; // const promise = new Promise(resolve => { // const messageEmitter = editor?.onDidReceiveMessage(e => { // if (e.type === 'custom_renderer_initialize') {