提交 266e4759 编写于 作者: J Johannes Rieken

before removing cell documents capture its API objects, after inserting cell...

before removing cell documents capture its API objects, after inserting cell documents capture its API objects, fixes https://github.com/microsoft/vscode/issues/116711
上级 1bb2e0a9
......@@ -18,13 +18,13 @@ import * as vscode from 'vscode';
class RawContentChangeEvent {
constructor(readonly start: number, readonly deletedCount: number, readonly deletedItems: ExtHostCell[], readonly items: ExtHostCell[]) { }
constructor(readonly start: number, readonly deletedCount: number, readonly deletedItems: vscode.NotebookCell[], readonly items: ExtHostCell[]) { }
static asApiEvent(event: RawContentChangeEvent): vscode.NotebookCellsChangeData {
return Object.freeze({
start: event.start,
deletedCount: event.deletedCount,
deletedItems: event.deletedItems.map(data => data.cell),
deletedItems: event.deletedItems,
items: event.items.map(data => data.cell)
});
}
......@@ -252,12 +252,14 @@ export class ExtHostNotebookDocument extends Disposable {
this._cellDisposableMapping.delete(this._cells[j].handle);
}
const changeEvent = new RawContentChangeEvent(splice[0], splice[1], [], newCells);
const deletedItems = this._cells.splice(splice[0], splice[1], ...newCells);
for (let cell of deletedItems) {
removedCellDocuments.push(cell.uri);
changeEvent.deletedItems.push(cell.cell);
}
contentChangeEvents.push(new RawContentChangeEvent(splice[0], splice[1], deletedItems, newCells));
contentChangeEvents.push(changeEvent);
});
this._documentsAndEditors.acceptDocumentsAndEditorsDelta({
......
......@@ -21,6 +21,7 @@ import { nullExtensionDescription } from 'vs/workbench/services/extensions/commo
import { isEqual } from 'vs/base/common/resources';
import { IExtensionStoragePaths } from 'vs/workbench/api/common/extHostStoragePaths';
import { generateUuid } from 'vs/base/common/uuid';
import { Event } from 'vs/base/common/event';
suite('NotebookCell#Document', function () {
......@@ -33,9 +34,11 @@ suite('NotebookCell#Document', function () {
const notebookUri = URI.parse('test:///notebook.file');
const disposables = new DisposableStore();
setup(async function () {
teardown(function () {
disposables.clear();
});
setup(async function () {
rpcProtocol = new TestRPCProtocol();
rpcProtocol.set(MainContext.MainThreadCommands, new class extends mock<MainThreadCommandsShape>() {
$registerCommand() { }
......@@ -305,4 +308,49 @@ suite('NotebookCell#Document', function () {
assert.strictEqual(notebook.notebookDocument.cells.length, 3);
assert.strictEqual(second.index, 2);
});
test('ERR MISSING extHostDocument for notebook cell: #116711', async 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);
extHostNotebooks.$acceptModelChanged(notebook.uri, {
versionId: 100,
rawEvents: [{
kind: NotebookCellsChangeType.ModelChange,
changes: [[0, 2, [{
handle: 3,
uri: CellUri.generate(notebookUri, 3),
source: ['### Heading'],
eol: '\n',
language: 'markdown',
cellKind: CellKind.Markdown,
outputs: [],
}, {
handle: 4,
uri: CellUri.generate(notebookUri, 4),
source: ['console.log("aaa")', 'console.log("bbb")'],
eol: '\n',
language: 'javascript',
cellKind: CellKind.Code,
outputs: [],
}]]]
}]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 2);
const event = await p;
assert.strictEqual(event.document === notebook.notebookDocument, true);
assert.strictEqual(event.changes.length, 1);
assert.strictEqual(event.changes[0].deletedCount, 2);
assert.strictEqual(event.changes[0].deletedItems[0].document.isClosed, true);
assert.strictEqual(event.changes[0].deletedItems[1].document.isClosed, true);
assert.strictEqual(event.changes[0].items.length, 2);
assert.strictEqual(event.changes[0].items[0].document.isClosed, false);
assert.strictEqual(event.changes[0].items[1].document.isClosed, false);
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册