mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-20 00:28:52 +01:00
refine NotebookCell API
This commit is contained in:
@@ -527,7 +527,7 @@ suite('Notebook API tests', function () {
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.document.getText(), 'test');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.language, 'typescript');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.document.languageId, 'typescript');
|
||||
|
||||
const secondCell = vscode.window.activeNotebookEditor!.document.cells[1];
|
||||
assert.strictEqual(secondCell!.outputs.length, 1);
|
||||
@@ -556,7 +556,7 @@ suite('Notebook API tests', function () {
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.document.getText(), 'test');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.language, 'typescript');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.document.languageId, 'typescript');
|
||||
|
||||
// ---- insert cell below and focus ---- //
|
||||
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
|
||||
@@ -606,7 +606,7 @@ suite('Notebook API tests', function () {
|
||||
|
||||
await vscode.commands.executeCommand('notebook.cell.moveDown');
|
||||
assert.strictEqual(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()}`);
|
||||
`first move down, active cell ${vscode.window.activeNotebookEditor!.selection!.document.uri.toString()}, ${vscode.window.activeNotebookEditor!.selection!.document.getText()}`);
|
||||
|
||||
// await vscode.commands.executeCommand('notebook.cell.moveDown');
|
||||
// activeCell = vscode.window.activeNotebookEditor!.selection;
|
||||
@@ -629,12 +629,12 @@ suite('Notebook API tests', function () {
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.document.getText(), 'test');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.language, 'typescript');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.document.languageId, 'typescript');
|
||||
|
||||
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.document.getText(), '');
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.insert(vscode.window.activeNotebookEditor!.selection!.uri, new vscode.Position(0, 0), 'var abc = 0;');
|
||||
edit.insert(vscode.window.activeNotebookEditor!.selection!.document.uri, new vscode.Position(0, 0), 'var abc = 0;');
|
||||
await vscode.workspace.applyEdit(edit);
|
||||
|
||||
const cellsChangeEvent = asPromise<vscode.NotebookCellsChangeEvent>(vscode.notebook.onDidChangeNotebookCells);
|
||||
@@ -801,7 +801,7 @@ suite('Notebook API tests', function () {
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.document.getText(), 'test');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.language, 'typescript');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.document.languageId, 'typescript');
|
||||
|
||||
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.document.getText(), '');
|
||||
@@ -815,7 +815,7 @@ suite('Notebook API tests', function () {
|
||||
|
||||
await withEvent(vscode.workspace.onDidChangeTextDocument, async event => {
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.insert(activeCell!.uri, new vscode.Position(0, 0), 'var abc = 0;');
|
||||
edit.insert(activeCell!.document.uri, new vscode.Position(0, 0), 'var abc = 0;');
|
||||
await vscode.workspace.applyEdit(edit);
|
||||
await event;
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true);
|
||||
@@ -834,7 +834,7 @@ suite('Notebook API tests', function () {
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.document.getText(), 'test');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.language, 'typescript');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.document.languageId, 'typescript');
|
||||
|
||||
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.document.getText(), '');
|
||||
@@ -849,7 +849,7 @@ suite('Notebook API tests', function () {
|
||||
|
||||
// modify the second cell, delete it
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.insert(vscode.window.activeNotebookEditor!.selection!.uri, new vscode.Position(0, 0), 'var abc = 0;');
|
||||
edit.insert(vscode.window.activeNotebookEditor!.selection!.document.uri, new vscode.Position(0, 0), 'var abc = 0;');
|
||||
await vscode.workspace.applyEdit(edit);
|
||||
await vscode.commands.executeCommand('notebook.cell.delete');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.document.cells.length, 3);
|
||||
@@ -879,7 +879,7 @@ suite('Notebook API tests', function () {
|
||||
|
||||
await vscode.commands.executeCommand('notebook.cell.insertCodeCellAbove');
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.insert(vscode.window.activeNotebookEditor!.selection!.uri, new vscode.Position(0, 0), 'var abc = 0;');
|
||||
edit.insert(vscode.window.activeNotebookEditor!.selection!.document.uri, new vscode.Position(0, 0), 'var abc = 0;');
|
||||
await vscode.workspace.applyEdit(edit);
|
||||
|
||||
const secondResource = await createRandomFile('', undefined, '.vsctestnb');
|
||||
@@ -904,7 +904,7 @@ suite('Notebook API tests', function () {
|
||||
|
||||
await vscode.commands.executeCommand('notebook.cell.insertCodeCellAbove');
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.insert(vscode.window.activeNotebookEditor!.selection!.uri, new vscode.Position(0, 0), 'var abc = 0;');
|
||||
edit.insert(vscode.window.activeNotebookEditor!.selection!.document.uri, new vscode.Position(0, 0), 'var abc = 0;');
|
||||
await vscode.workspace.applyEdit(edit);
|
||||
|
||||
const secondResource = await createRandomFile('', undefined, '.vsctestnb');
|
||||
@@ -937,13 +937,13 @@ suite('Notebook API tests', function () {
|
||||
const firstNotebookEditor = vscode.window.activeNotebookEditor;
|
||||
assert.strictEqual(firstNotebookEditor !== undefined, true, 'notebook first');
|
||||
assert.strictEqual(firstNotebookEditor!.selection?.document.getText(), 'test');
|
||||
assert.strictEqual(firstNotebookEditor!.selection?.language, 'typescript');
|
||||
assert.strictEqual(firstNotebookEditor!.selection?.document.languageId, 'typescript');
|
||||
|
||||
await splitEditor();
|
||||
const secondNotebookEditor = vscode.window.activeNotebookEditor;
|
||||
assert.strictEqual(secondNotebookEditor !== undefined, true, 'notebook first');
|
||||
assert.strictEqual(secondNotebookEditor!.selection?.document.getText(), 'test');
|
||||
assert.strictEqual(secondNotebookEditor!.selection?.language, 'typescript');
|
||||
assert.strictEqual(secondNotebookEditor!.selection?.document.languageId, 'typescript');
|
||||
|
||||
assert.notEqual(firstNotebookEditor, secondNotebookEditor);
|
||||
assert.strictEqual(firstNotebookEditor?.document, secondNotebookEditor?.document, 'split notebook editors share the same document');
|
||||
@@ -957,7 +957,7 @@ suite('Notebook API tests', function () {
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.document.metadata.custom!['testMetadata'] as boolean, false);
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.metadata.custom!['testCellMetadata'] as number, 123);
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.language, 'typescript');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.document.languageId, 'typescript');
|
||||
|
||||
await saveFileAndCloseAll(resource);
|
||||
});
|
||||
@@ -970,7 +970,7 @@ suite('Notebook API tests', function () {
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.document.metadata.custom!['testMetadata'] as boolean, false);
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.metadata.custom!['testCellMetadata'] as number, 123);
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.language, 'typescript');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.document.languageId, 'typescript');
|
||||
|
||||
// TODO see #101462
|
||||
// await vscode.commands.executeCommand('notebook.cell.copyDown');
|
||||
@@ -993,7 +993,7 @@ suite('Notebook API tests', function () {
|
||||
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);
|
||||
await vscode.commands.executeCommand('vscode.open', cell.document.uri, vscode.ViewColumn.Active);
|
||||
|
||||
assert.strictEqual(!!vscode.window.activeNotebookEditor, true);
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.document.uri.toString(), resource.toString());
|
||||
@@ -1011,7 +1011,7 @@ suite('Notebook API tests', function () {
|
||||
|
||||
// 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);
|
||||
await vscode.commands.executeCommand('vscode.open', cell.document.uri);
|
||||
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.document.uri.toString(), resource.toString());
|
||||
});
|
||||
@@ -1021,7 +1021,7 @@ suite('Notebook API tests', function () {
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.insert(vscode.window.activeNotebookEditor!.selection!.uri, new vscode.Position(0, 0), 'var abc = 0;');
|
||||
edit.insert(vscode.window.activeNotebookEditor!.selection!.document.uri, new vscode.Position(0, 0), 'var abc = 0;');
|
||||
await vscode.workspace.applyEdit(edit);
|
||||
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first');
|
||||
@@ -1029,7 +1029,7 @@ suite('Notebook API tests', function () {
|
||||
|
||||
// no kernel -> no default language
|
||||
// assert.strictEqual(vscode.window.activeNotebookEditor!.kernel, undefined);
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.language, 'typescript');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.document.languageId, 'typescript');
|
||||
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'default');
|
||||
assert.strictEqual(vscode.window.activeTextEditor?.document.uri.path, resource.path);
|
||||
@@ -1074,7 +1074,7 @@ suite('Notebook API tests', function () {
|
||||
assert.strictEqual(activeCell?.document.getText(), 'test');
|
||||
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.insert(vscode.window.activeNotebookEditor!.selection!.uri, new vscode.Position(0, 0), 'var abc = 0;');
|
||||
edit.insert(vscode.window.activeNotebookEditor!.selection!.document.uri, new vscode.Position(0, 0), 'var abc = 0;');
|
||||
await vscode.workspace.applyEdit(edit);
|
||||
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.document.cells.length, 3);
|
||||
|
||||
Reference in New Issue
Block a user