remove NotebookDocument#cells in favor of cellsAt, getCells, and cellCount

上级 6b67774b
......@@ -83,7 +83,7 @@ suite('Notebook Document', function () {
assert.strictEqual(notebook.uri.toString(), uri.toString());
assert.strictEqual(notebook.isDirty, false);
assert.strictEqual(notebook.isUntitled, false);
assert.strictEqual(notebook.cells.length, 1);
assert.strictEqual(notebook.cellCount, 1);
assert.strictEqual(notebook.viewType, 'notebook.nbdtest');
});
......@@ -96,7 +96,7 @@ suite('Notebook Document', function () {
return;
}
const notebook = vscode.notebook.notebookDocuments.find(notebook => {
const cell = notebook.cells.find(cell => cell.document === doc);
const cell = notebook.getCells().find(cell => cell.document === doc);
return Boolean(cell);
});
assert.ok(notebook, `notebook for cell ${doc.uri} NOT found`);
......@@ -112,7 +112,9 @@ suite('Notebook Document', function () {
const uri = await utils.createRandomFile(undefined, undefined, '.nbdtest');
const p = utils.asPromise(vscode.notebook.onDidOpenNotebookDocument).then(notebook => {
for (let cell of notebook.cells) {
for (let i = 0; i < notebook.cellCount; i++) {
let cell = notebook.cellAt(i);
const doc = vscode.workspace.textDocuments.find(doc => doc.uri.toString() === cell.document.uri.toString());
assert.ok(doc);
assert.strictEqual(doc.notebook === notebook, true);
......@@ -132,7 +134,7 @@ suite('Notebook Document', function () {
const uri = await utils.createRandomFile(undefined, undefined, '.nbdtest');
const document = await vscode.notebook.openNotebookDocument(uri);
assert.strictEqual(document.cells.length, 1);
assert.strictEqual(document.cellCount, 1);
// inserting two new cells
{
......@@ -155,9 +157,9 @@ suite('Notebook Document', function () {
assert.strictEqual(success, true);
}
assert.strictEqual(document.cells.length, 3);
assert.strictEqual(document.cells[0].document.getText(), 'new_markdown');
assert.strictEqual(document.cells[1].document.getText(), 'new_code');
assert.strictEqual(document.cellCount, 3);
assert.strictEqual(document.cellAt(0).document.getText(), 'new_markdown');
assert.strictEqual(document.cellAt(1).document.getText(), 'new_code');
// deleting cell 1 and 3
{
......@@ -168,8 +170,8 @@ suite('Notebook Document', function () {
assert.strictEqual(success, true);
}
assert.strictEqual(document.cells.length, 1);
assert.strictEqual(document.cells[0].document.getText(), 'new_code');
assert.strictEqual(document.cellCount, 1);
assert.strictEqual(document.cellAt(0).document.getText(), 'new_code');
// replacing all cells
{
......@@ -190,24 +192,24 @@ suite('Notebook Document', function () {
const success = await vscode.workspace.applyEdit(edit);
assert.strictEqual(success, true);
}
assert.strictEqual(document.cells.length, 2);
assert.strictEqual(document.cells[0].document.getText(), 'new2_markdown');
assert.strictEqual(document.cells[1].document.getText(), 'new2_code');
assert.strictEqual(document.cellCount, 2);
assert.strictEqual(document.cellAt(0).document.getText(), 'new2_markdown');
assert.strictEqual(document.cellAt(1).document.getText(), 'new2_code');
// remove all cells
{
const edit = new vscode.WorkspaceEdit();
edit.replaceNotebookCells(document.uri, 0, document.cells.length, []);
edit.replaceNotebookCells(document.uri, 0, document.cellCount, []);
const success = await vscode.workspace.applyEdit(edit);
assert.strictEqual(success, true);
}
assert.strictEqual(document.cells.length, 0);
assert.strictEqual(document.cellCount, 0);
});
test('workspace edit API (replaceCells, event)', async function () {
const uri = await utils.createRandomFile(undefined, undefined, '.nbdtest');
const document = await vscode.notebook.openNotebookDocument(uri);
assert.strictEqual(document.cells.length, 1);
assert.strictEqual(document.cellCount, 1);
const edit = new vscode.WorkspaceEdit();
edit.replaceNotebookCells(document.uri, 0, 0, [{
......@@ -232,9 +234,9 @@ suite('Notebook Document', function () {
const data = await event;
// check document
assert.strictEqual(document.cells.length, 3);
assert.strictEqual(document.cells[0].document.getText(), 'new_markdown');
assert.strictEqual(document.cells[1].document.getText(), 'new_code');
assert.strictEqual(document.cellCount, 3);
assert.strictEqual(document.cellAt(0).document.getText(), 'new_markdown');
assert.strictEqual(document.cellAt(1).document.getText(), 'new_code');
// check event data
assert.strictEqual(data.document === document, true);
......@@ -242,8 +244,8 @@ suite('Notebook Document', function () {
assert.strictEqual(data.changes[0].deletedCount, 0);
assert.strictEqual(data.changes[0].deletedItems.length, 0);
assert.strictEqual(data.changes[0].items.length, 2);
assert.strictEqual(data.changes[0].items[0], document.cells[0]);
assert.strictEqual(data.changes[0].items[1], document.cells[1]);
assert.strictEqual(data.changes[0].items[0], document.cellAt(0));
assert.strictEqual(data.changes[0].items[1], document.cellAt(1));
});
test('workspace edit API (appendNotebookCellOutput, replaceCellOutput, event)', async function () {
......@@ -258,9 +260,9 @@ suite('Notebook Document', function () {
const data = await outputChangeEvent;
assert.strictEqual(success, true);
assert.strictEqual(document.cells.length, 1);
assert.strictEqual(document.cells[0].outputs.length, 1);
assert.deepStrictEqual(document.cells[0].outputs, [firstCellOutput]);
assert.strictEqual(document.cellCount, 1);
assert.strictEqual(document.cellAt(0).outputs.length, 1);
assert.deepStrictEqual(document.cellAt(0).outputs, [firstCellOutput]);
assert.strictEqual(data.document === document, true);
assert.strictEqual(data.cells.length, 1);
......@@ -277,9 +279,9 @@ suite('Notebook Document', function () {
const data = await outputChangeEvent;
assert.strictEqual(success, true);
assert.strictEqual(document.cells.length, 1);
assert.strictEqual(document.cells[0].outputs.length, 2);
assert.deepStrictEqual(document.cells[0].outputs, [firstCellOutput, secondCellOutput]);
assert.strictEqual(document.cellCount, 1);
assert.strictEqual(document.cellAt(0).outputs.length, 2);
assert.deepStrictEqual(document.cellAt(0).outputs, [firstCellOutput, secondCellOutput]);
assert.strictEqual(data.document === document, true);
assert.strictEqual(data.cells.length, 1);
......@@ -296,9 +298,9 @@ suite('Notebook Document', function () {
const data = await outputChangeEvent;
assert.strictEqual(success, true);
assert.strictEqual(document.cells.length, 1);
assert.strictEqual(document.cells[0].outputs.length, 1);
assert.deepStrictEqual(document.cells[0].outputs, [thirdOutput]);
assert.strictEqual(document.cellCount, 1);
assert.strictEqual(document.cellAt(0).outputs.length, 1);
assert.deepStrictEqual(document.cellAt(0).outputs, [thirdOutput]);
assert.strictEqual(data.document === document, true);
assert.strictEqual(data.cells.length, 1);
......@@ -314,7 +316,7 @@ suite('Notebook Document', function () {
assert.strictEqual(notebook.uri.toString(), uri.toString());
assert.strictEqual(notebook.isDirty, false);
assert.strictEqual(notebook.isUntitled, false);
assert.strictEqual(notebook.cells.length, 1);
assert.strictEqual(notebook.cellCount, 1);
assert.strictEqual(notebook.viewType, 'notebook.nbdtest');
const edit = new vscode.WorkspaceEdit();
......@@ -345,7 +347,7 @@ suite('Notebook Document', function () {
const uri = await utils.createRandomFile(undefined, undefined, '.nbdtest');
const notebook = await vscode.notebook.openNotebookDocument(uri);
const first = notebook.cells[0];
const first = notebook.cellAt(0);
assert.strictEqual(first.document.languageId, 'javascript');
const pclose = utils.asPromise(vscode.workspace.onDidCloseTextDocument);
......@@ -378,10 +380,10 @@ suite('Notebook Document', function () {
let success = await vscode.workspace.applyEdit(edit);
assert.ok(success);
assert.strictEqual(document.cells[0].outputs.length, 1);
assert.strictEqual(document.cells[0].outputs[0].outputs.length, 1);
assert.deepStrictEqual(document.cells[0].outputs[0].metadata, { outputType: 'stream', streamName: 'stdout' });
assert.deepStrictEqual(document.cells[0].outputs[0].outputs[0].metadata, { outputType: 'stream', streamName: 'stdout' });
assert.strictEqual(document.cellAt(0).outputs.length, 1);
assert.strictEqual(document.cellAt(0).outputs[0].outputs.length, 1);
assert.deepStrictEqual(document.cellAt(0).outputs[0].metadata, { outputType: 'stream', streamName: 'stdout' });
assert.deepStrictEqual(document.cellAt(0).outputs[0].outputs[0].metadata, { outputType: 'stream', streamName: 'stdout' });
const edit2 = new vscode.WorkspaceEdit();
edit2.appendNotebookCellOutput(document.uri, 0, [
......@@ -393,13 +395,13 @@ suite('Notebook Document', function () {
success = await vscode.workspace.applyEdit(edit2);
assert.ok(success);
assert.strictEqual(document.cells[0].outputs.length, 2);
assert.strictEqual(document.cells[0].outputs[0].outputs.length, 1);
assert.strictEqual(document.cells[0].outputs[1].outputs.length, 1);
assert.deepStrictEqual(document.cells[0].outputs[0].metadata, { outputType: 'stream', streamName: 'stdout' });
assert.deepStrictEqual(document.cells[0].outputs[0].outputs[0].metadata, { outputType: 'stream', streamName: 'stdout' });
assert.deepStrictEqual(document.cells[0].outputs[1].metadata, { outputType: 'stream', streamName: 'stderr' });
assert.deepStrictEqual(document.cells[0].outputs[1].outputs[0].metadata, { outputType: 'stream', streamName: 'stderr' });
assert.strictEqual(document.cellAt(0).outputs.length, 2);
assert.strictEqual(document.cellAt(0).outputs[0].outputs.length, 1);
assert.strictEqual(document.cellAt(0).outputs[1].outputs.length, 1);
assert.deepStrictEqual(document.cellAt(0).outputs[0].metadata, { outputType: 'stream', streamName: 'stdout' });
assert.deepStrictEqual(document.cellAt(0).outputs[0].outputs[0].metadata, { outputType: 'stream', streamName: 'stdout' });
assert.deepStrictEqual(document.cellAt(0).outputs[1].metadata, { outputType: 'stream', streamName: 'stderr' });
assert.deepStrictEqual(document.cellAt(0).outputs[1].outputs[0].metadata, { outputType: 'stream', streamName: 'stderr' });
});
test('dirty state - complex', async function () {
......
......@@ -1090,10 +1090,6 @@ declare module 'vscode' {
// todo@API should we really expose this?
readonly viewType: string;
// todo@API cellsAt(range)? getCell(index>)?
/** @deprecated Use `getCells(<...>) instead */
readonly cells: ReadonlyArray<NotebookCell>;
/**
* The number of cells in the notebook document.
*/
......
......@@ -702,7 +702,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
if (document) {
document.dispose();
this._documents.delete(revivedUri);
this._textDocumentsAndEditors.$acceptDocumentsAndEditorsDelta({ removedDocuments: document.notebookDocument.cells.map(cell => cell.document.uri) });
this._textDocumentsAndEditors.$acceptDocumentsAndEditorsDelta({ removedDocuments: document.notebookDocument.getCells().map(cell => cell.document.uri) });
this._onDidCloseNotebookDocument.fire(document.notebookDocument);
}
......
......@@ -73,7 +73,7 @@ export class ExtHostNotebookConcatDocument implements vscode.NotebookConcatTextD
this._cellUris = new ResourceMap();
const cellLengths: number[] = [];
const cellLineCounts: number[] = [];
for (const cell of this._notebook.cells) {
for (const cell of this._notebook.getCells()) {
if (cell.kind === types.NotebookCellKind.Code && (!this._selector || score(this._selector, cell.document.uri, cell.document.languageId, true))) {
this._cellUris.set(cell.document.uri, this._cells.length);
this._cells.push(cell);
......
......@@ -179,7 +179,6 @@ export class ExtHostNotebookDocument extends Disposable {
get isUntitled() { return that.uri.scheme === Schemas.untitled; },
get isClosed() { return that._disposed; },
get metadata() { return that._metadata; },
get cells(): ReadonlyArray<vscode.NotebookCell> { return that._cells.map(cell => cell.cell); },
get cellCount() { return that._cells.length; },
cellAt(index) {
index = that._validateIndex(index);
......
......@@ -100,9 +100,9 @@ suite('NotebookCell#Document', function () {
test('cell document is vscode.TextDocument', async function () {
assert.strictEqual(notebook.notebookDocument.cells.length, 2);
assert.strictEqual(notebook.notebookDocument.cellCount, 2);
const [c1, c2] = notebook.notebookDocument.cells;
const [c1, c2] = notebook.notebookDocument.getCells();
const d1 = extHostDocuments.getDocument(c1.document.uri);
assert.ok(d1);
......@@ -119,7 +119,7 @@ suite('NotebookCell#Document', function () {
test('cell document goes when notebook closes', async function () {
const cellUris: string[] = [];
for (let cell of notebook.notebookDocument.cells) {
for (let cell of notebook.notebookDocument.getCells()) {
assert.ok(extHostDocuments.getDocument(cell.document.uri));
cellUris.push(cell.document.uri.toString());
}
......@@ -196,7 +196,7 @@ suite('NotebookCell#Document', function () {
const docs: vscode.TextDocument[] = [];
const addData: IModelAddedData[] = [];
for (let cell of notebook.notebookDocument.cells) {
for (let cell of notebook.notebookDocument.getCells()) {
const doc = extHostDocuments.getDocument(cell.document.uri);
assert.ok(doc);
assert.strictEqual(extHostDocuments.getDocument(cell.document.uri).isClosed, false);
......@@ -218,14 +218,14 @@ suite('NotebookCell#Document', function () {
extHostDocumentsAndEditors.$acceptDocumentsAndEditorsDelta({ removedDocuments: docs.map(d => d.uri) });
// notebook is still open -> cell documents stay open
for (let cell of notebook.notebookDocument.cells) {
for (let cell of notebook.notebookDocument.getCells()) {
assert.ok(extHostDocuments.getDocument(cell.document.uri));
assert.strictEqual(extHostDocuments.getDocument(cell.document.uri).isClosed, false);
}
// close notebook -> docs are closed
extHostNotebooks.$acceptDocumentAndEditorsDelta({ removedDocuments: [notebook.uri] });
for (let cell of notebook.notebookDocument.cells) {
for (let cell of notebook.notebookDocument.getCells()) {
assert.throws(() => extHostDocuments.getDocument(cell.document.uri));
}
for (let doc of docs) {
......@@ -235,8 +235,8 @@ suite('NotebookCell#Document', function () {
test('cell document goes when cell is removed', async function () {
assert.strictEqual(notebook.notebookDocument.cells.length, 2);
const [cell1, cell2] = notebook.notebookDocument.cells;
assert.strictEqual(notebook.notebookDocument.cellCount, 2);
const [cell1, cell2] = notebook.notebookDocument.getCells();
extHostNotebooks.$acceptModelChanged(notebook.uri, {
versionId: 2,
......@@ -248,7 +248,7 @@ suite('NotebookCell#Document', function () {
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1);
assert.strictEqual(notebook.notebookDocument.cellCount, 1);
assert.strictEqual(cell1.document.isClosed, true); // ref still alive!
assert.strictEqual(cell2.document.isClosed, false);
......@@ -256,15 +256,15 @@ suite('NotebookCell#Document', function () {
});
test('cell document knows notebook', function () {
for (let cells of notebook.notebookDocument.cells) {
for (let cells of notebook.notebookDocument.getCells()) {
assert.strictEqual(cells.document.notebook === notebook.notebookDocument, true);
}
});
test('cell#index', function () {
assert.strictEqual(notebook.notebookDocument.cells.length, 2);
const [first, second] = notebook.notebookDocument.cells;
assert.strictEqual(notebook.notebookDocument.cellCount, 2);
const [first, second] = notebook.notebookDocument.getCells();
assert.strictEqual(first.index, 0);
assert.strictEqual(second.index, 1);
......@@ -277,7 +277,7 @@ suite('NotebookCell#Document', function () {
}]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1);
assert.strictEqual(notebook.notebookDocument.cellCount, 1);
assert.strictEqual(second.index, 0);
extHostNotebooks.$acceptModelChanged(notebookUri, {
......@@ -304,7 +304,7 @@ suite('NotebookCell#Document', function () {
}]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 3);
assert.strictEqual(notebook.notebookDocument.cellCount, 3);
assert.strictEqual(second.index, 2);
});
......@@ -313,7 +313,7 @@ suite('NotebookCell#Document', function () {
const p = Event.toPromise(extHostNotebooks.onDidChangeNotebookCells);
// DON'T call this, make sure the cell-documents have not been created yet
// assert.strictEqual(notebook.notebookDocument.cells.length, 2);
// assert.strictEqual(notebook.notebookDocument.cellCount, 2);
extHostNotebooks.$acceptModelChanged(notebook.uri, {
versionId: 100,
......@@ -339,7 +339,7 @@ suite('NotebookCell#Document', function () {
}]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 2);
assert.strictEqual(notebook.notebookDocument.cellCount, 2);
const event = await p;
......@@ -391,7 +391,7 @@ suite('NotebookCell#Document', function () {
test('change cell language triggers onDidChange events', async function () {
const [first] = notebook.notebookDocument.cells;
const first = notebook.notebookDocument.cellAt(0);
assert.strictEqual(first.document.languageId, 'markdown');
......
......@@ -150,7 +150,7 @@ suite('NotebookConcatDocument', function () {
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 2); // markdown and code
assert.strictEqual(notebook.notebookDocument.cellCount, 1 + 2); // markdown and code
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
......@@ -188,16 +188,16 @@ suite('NotebookConcatDocument', function () {
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 2); // markdown and code
assert.strictEqual(notebook.notebookDocument.cellCount, 1 + 2); // markdown and code
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!');
assertLocation(doc, new Position(0, 0), new Location(notebook.notebookDocument.cells[0].document.uri, new Position(0, 0)));
assertLocation(doc, new Position(4, 0), new Location(notebook.notebookDocument.cells[1].document.uri, new Position(1, 0)));
assertLocation(doc, new Position(4, 3), new Location(notebook.notebookDocument.cells[1].document.uri, new Position(1, 3)));
assertLocation(doc, new Position(5, 11), new Location(notebook.notebookDocument.cells[1].document.uri, new Position(2, 11)));
assertLocation(doc, new Position(5, 12), new Location(notebook.notebookDocument.cells[1].document.uri, new Position(2, 11)), false); // don't check identity because position will be clamped
assertLocation(doc, new Position(0, 0), new Location(notebook.notebookDocument.cellAt(0).document.uri, new Position(0, 0)));
assertLocation(doc, new Position(4, 0), new Location(notebook.notebookDocument.cellAt(1).document.uri, new Position(1, 0)));
assertLocation(doc, new Position(4, 3), new Location(notebook.notebookDocument.cellAt(1).document.uri, new Position(1, 3)));
assertLocation(doc, new Position(5, 11), new Location(notebook.notebookDocument.cellAt(1).document.uri, new Position(2, 11)));
assertLocation(doc, new Position(5, 12), new Location(notebook.notebookDocument.cellAt(1).document.uri, new Position(2, 11)), false); // don't check identity because position will be clamped
});
......@@ -223,13 +223,13 @@ suite('NotebookConcatDocument', function () {
}
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 1);
assert.strictEqual(notebook.notebookDocument.cellCount, 1 + 1);
assert.strictEqual(doc.version, 1);
assertLines(doc, 'Hello', 'World', 'Hello World!');
assertLocation(doc, new Position(0, 0), new Location(notebook.notebookDocument.cells[0].document.uri, new Position(0, 0)));
assertLocation(doc, new Position(2, 2), new Location(notebook.notebookDocument.cells[0].document.uri, new Position(2, 2)));
assertLocation(doc, new Position(4, 0), new Location(notebook.notebookDocument.cells[0].document.uri, new Position(2, 12)), false); // clamped
assertLocation(doc, new Position(0, 0), new Location(notebook.notebookDocument.cellAt(0).document.uri, new Position(0, 0)));
assertLocation(doc, new Position(2, 2), new Location(notebook.notebookDocument.cellAt(0).document.uri, new Position(2, 2)));
assertLocation(doc, new Position(4, 0), new Location(notebook.notebookDocument.cellAt(0).document.uri, new Position(2, 12)), false); // clamped
// UPDATE 2
......@@ -251,14 +251,14 @@ suite('NotebookConcatDocument', function () {
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 2);
assert.strictEqual(notebook.notebookDocument.cellCount, 1 + 2);
assert.strictEqual(doc.version, 2);
assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!');
assertLocation(doc, new Position(0, 0), new Location(notebook.notebookDocument.cells[0].document.uri, new Position(0, 0)));
assertLocation(doc, new Position(4, 0), new Location(notebook.notebookDocument.cells[1].document.uri, new Position(1, 0)));
assertLocation(doc, new Position(4, 3), new Location(notebook.notebookDocument.cells[1].document.uri, new Position(1, 3)));
assertLocation(doc, new Position(5, 11), new Location(notebook.notebookDocument.cells[1].document.uri, new Position(2, 11)));
assertLocation(doc, new Position(5, 12), new Location(notebook.notebookDocument.cells[1].document.uri, new Position(2, 11)), false); // don't check identity because position will be clamped
assertLocation(doc, new Position(0, 0), new Location(notebook.notebookDocument.cellAt(0).document.uri, new Position(0, 0)));
assertLocation(doc, new Position(4, 0), new Location(notebook.notebookDocument.cellAt(1).document.uri, new Position(1, 0)));
assertLocation(doc, new Position(4, 3), new Location(notebook.notebookDocument.cellAt(1).document.uri, new Position(1, 3)));
assertLocation(doc, new Position(5, 11), new Location(notebook.notebookDocument.cellAt(1).document.uri, new Position(2, 11)));
assertLocation(doc, new Position(5, 12), new Location(notebook.notebookDocument.cellAt(1).document.uri, new Position(2, 11)), false); // don't check identity because position will be clamped
// UPDATE 3 (remove cell #2 again)
extHostNotebooks.$acceptModelChanged(notebookUri, {
......@@ -270,12 +270,12 @@ suite('NotebookConcatDocument', function () {
}
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 1);
assert.strictEqual(notebook.notebookDocument.cellCount, 1 + 1);
assert.strictEqual(doc.version, 3);
assertLines(doc, 'Hello', 'World', 'Hello World!');
assertLocation(doc, new Position(0, 0), new Location(notebook.notebookDocument.cells[0].document.uri, new Position(0, 0)));
assertLocation(doc, new Position(2, 2), new Location(notebook.notebookDocument.cells[0].document.uri, new Position(2, 2)));
assertLocation(doc, new Position(4, 0), new Location(notebook.notebookDocument.cells[0].document.uri, new Position(2, 12)), false); // clamped
assertLocation(doc, new Position(0, 0), new Location(notebook.notebookDocument.cellAt(0).document.uri, new Position(0, 0)));
assertLocation(doc, new Position(2, 2), new Location(notebook.notebookDocument.cellAt(0).document.uri, new Position(2, 2)));
assertLocation(doc, new Position(4, 0), new Location(notebook.notebookDocument.cellAt(0).document.uri, new Position(2, 12)), false); // clamped
});
test('location, position mapping, cell-document changes', function () {
......@@ -309,21 +309,21 @@ suite('NotebookConcatDocument', function () {
}
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 2);
assert.strictEqual(notebook.notebookDocument.cellCount, 1 + 2);
assert.strictEqual(doc.version, 1);
assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!');
assertLocation(doc, new Position(0, 0), new Location(notebook.notebookDocument.cells[0].document.uri, new Position(0, 0)));
assertLocation(doc, new Position(2, 2), new Location(notebook.notebookDocument.cells[0].document.uri, new Position(2, 2)));
assertLocation(doc, new Position(2, 12), new Location(notebook.notebookDocument.cells[0].document.uri, new Position(2, 12)));
assertLocation(doc, new Position(4, 0), new Location(notebook.notebookDocument.cells[1].document.uri, new Position(1, 0)));
assertLocation(doc, new Position(4, 3), new Location(notebook.notebookDocument.cells[1].document.uri, new Position(1, 3)));
assertLocation(doc, new Position(0, 0), new Location(notebook.notebookDocument.cellAt(0).document.uri, new Position(0, 0)));
assertLocation(doc, new Position(2, 2), new Location(notebook.notebookDocument.cellAt(0).document.uri, new Position(2, 2)));
assertLocation(doc, new Position(2, 12), new Location(notebook.notebookDocument.cellAt(0).document.uri, new Position(2, 12)));
assertLocation(doc, new Position(4, 0), new Location(notebook.notebookDocument.cellAt(1).document.uri, new Position(1, 0)));
assertLocation(doc, new Position(4, 3), new Location(notebook.notebookDocument.cellAt(1).document.uri, new Position(1, 3)));
// offset math
let cell1End = doc.offsetAt(new Position(2, 12));
assert.strictEqual(doc.positionAt(cell1End).isEqual(new Position(2, 12)), true);
extHostDocuments.$acceptModelChanged(notebook.notebookDocument.cells[0].document.uri, {
extHostDocuments.$acceptModelChanged(notebook.notebookDocument.cellAt(0).document.uri, {
versionId: 0,
eol: '\n',
changes: [{
......@@ -334,7 +334,7 @@ suite('NotebookConcatDocument', function () {
}]
}, false);
assertLines(doc, 'Hello', 'World', 'Hi World!', 'Hallo', 'Welt', 'Hallo Welt!');
assertLocation(doc, new Position(2, 12), new Location(notebook.notebookDocument.cells[0].document.uri, new Position(2, 9)), false);
assertLocation(doc, new Position(2, 12), new Location(notebook.notebookDocument.cellAt(0).document.uri, new Position(2, 9)), false);
assert.strictEqual(doc.positionAt(cell1End).isEqual(new Position(3, 2)), true);
......@@ -440,7 +440,7 @@ suite('NotebookConcatDocument', function () {
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 2); // markdown and code
assert.strictEqual(notebook.notebookDocument.cellCount, 1 + 2); // markdown and code
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!');
......@@ -497,17 +497,17 @@ suite('NotebookConcatDocument', function () {
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 2); // markdown and code
assert.strictEqual(notebook.notebookDocument.cellCount, 1 + 2); // markdown and code
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!');
assertLocationAtPosition(doc, { line: 0, character: 0 }, { uri: notebook.notebookDocument.cells[0].document.uri, line: 0, character: 0 });
assertLocationAtPosition(doc, { line: 2, character: 0 }, { uri: notebook.notebookDocument.cells[0].document.uri, line: 2, character: 0 });
assertLocationAtPosition(doc, { line: 2, character: 12 }, { uri: notebook.notebookDocument.cells[0].document.uri, line: 2, character: 12 });
assertLocationAtPosition(doc, { line: 3, character: 0 }, { uri: notebook.notebookDocument.cells[1].document.uri, line: 0, character: 0 });
assertLocationAtPosition(doc, { line: 5, character: 0 }, { uri: notebook.notebookDocument.cells[1].document.uri, line: 2, character: 0 });
assertLocationAtPosition(doc, { line: 5, character: 11 }, { uri: notebook.notebookDocument.cells[1].document.uri, line: 2, character: 11 });
assertLocationAtPosition(doc, { line: 0, character: 0 }, { uri: notebook.notebookDocument.cellAt(0).document.uri, line: 0, character: 0 });
assertLocationAtPosition(doc, { line: 2, character: 0 }, { uri: notebook.notebookDocument.cellAt(0).document.uri, line: 2, character: 0 });
assertLocationAtPosition(doc, { line: 2, character: 12 }, { uri: notebook.notebookDocument.cellAt(0).document.uri, line: 2, character: 12 });
assertLocationAtPosition(doc, { line: 3, character: 0 }, { uri: notebook.notebookDocument.cellAt(1).document.uri, line: 0, character: 0 });
assertLocationAtPosition(doc, { line: 5, character: 0 }, { uri: notebook.notebookDocument.cellAt(1).document.uri, line: 2, character: 0 });
assertLocationAtPosition(doc, { line: 5, character: 11 }, { uri: notebook.notebookDocument.cellAt(1).document.uri, line: 2, character: 11 });
});
test('getText(range)', function () {
......@@ -538,7 +538,7 @@ suite('NotebookConcatDocument', function () {
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 2); // markdown and code
assert.strictEqual(notebook.notebookDocument.cellCount, 1 + 2); // markdown and code
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!');
......@@ -576,7 +576,7 @@ suite('NotebookConcatDocument', function () {
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 2); // markdown and code
assert.strictEqual(notebook.notebookDocument.cellCount, 1 + 2); // markdown and code
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册