Skip to content

Commit bae6405

Browse files
committed
unit test for document remove
1 parent 5f6d850 commit bae6405

5 files changed

Lines changed: 50 additions & 9 deletions

File tree

src/vs/workbench/api/browser/mainThreadNotebook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
203203

204204
async removeNotebookTextModel(uri: URI): Promise<void> {
205205
// TODO@rebornix, remove cell should use emitDelta as well to ensure document/editor events are sent together
206-
await this._proxy.$acceptDocumentAndEditorsDelta({ removedDocuments: [uri] });
206+
this._proxy.$acceptDocumentAndEditorsDelta({ removedDocuments: [uri] });
207207
let textModelDisposableStore = this._editorEventListenersMapping.get(uri.toString());
208208
textModelDisposableStore?.dispose();
209209
this._editorEventListenersMapping.delete(URI.from(uri).toString());

src/vs/workbench/api/common/extHost.protocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,7 @@ export interface ExtHostNotebookShape {
16331633
$acceptModelChanged(uriComponents: UriComponents, event: NotebookCellsChangedEvent): void;
16341634
$acceptModelSaved(uriComponents: UriComponents): void;
16351635
$acceptEditorPropertiesChanged(uriComponents: UriComponents, data: INotebookEditorPropertiesChangeData): void;
1636-
$acceptDocumentAndEditorsDelta(delta: INotebookDocumentsAndEditorsDelta): Promise<void>;
1636+
$acceptDocumentAndEditorsDelta(delta: INotebookDocumentsAndEditorsDelta): void;
16371637
$undoNotebook(viewType: string, uri: UriComponents, editId: number, isDirty: boolean): Promise<void>;
16381638
$redoNotebook(viewType: string, uri: UriComponents, editId: number, isDirty: boolean): Promise<void>;
16391639

src/vs/workbench/api/common/extHostNotebook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
15131513
this._editors.set(editorId, { editor });
15141514
}
15151515

1516-
async $acceptDocumentAndEditorsDelta(delta: INotebookDocumentsAndEditorsDelta) {
1516+
$acceptDocumentAndEditorsDelta(delta: INotebookDocumentsAndEditorsDelta): void {
15171517
let editorChanged = false;
15181518

15191519
if (delta.removedDocuments) {

src/vs/workbench/test/browser/api/extHostNotebook.test.ts

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { TestRPCProtocol } from 'vs/workbench/test/browser/api/testRPCProtocol';
1010
import { DisposableStore } from 'vs/base/common/lifecycle';
1111
import { NullLogService } from 'vs/platform/log/common/log';
1212
import { mock } from 'vs/base/test/common/mock';
13-
import { MainContext, MainThreadCommandsShape, MainThreadNotebookShape } from 'vs/workbench/api/common/extHost.protocol';
13+
import { IModelAddedData, MainContext, MainThreadCommandsShape, MainThreadNotebookShape } from 'vs/workbench/api/common/extHost.protocol';
1414
import { ExtHostNotebookDocument, ExtHostNotebookController } from 'vs/workbench/api/common/extHostNotebook';
1515
import { CellKind, CellUri, NotebookCellsChangeType } from 'vs/workbench/contrib/notebook/common/notebookCommon';
1616
import { URI } from 'vs/base/common/uri';
@@ -47,7 +47,7 @@ suite('NotebookCell#Document', function () {
4747
let reg = extHostNotebooks.registerNotebookContentProvider(nullExtensionDescription, 'test', new class extends mock<vscode.NotebookContentProvider>() {
4848
// async openNotebook() { }
4949
});
50-
await extHostNotebooks.$acceptDocumentAndEditorsDelta({
50+
extHostNotebooks.$acceptDocumentAndEditorsDelta({
5151
addedDocuments: [{
5252
handle: 0,
5353
uri: notebookUri,
@@ -77,7 +77,7 @@ suite('NotebookCell#Document', function () {
7777
selections: [0]
7878
}]
7979
});
80-
await extHostNotebooks.$acceptDocumentAndEditorsDelta({ newActiveEditor: '_notebook_editor_0' });
80+
extHostNotebooks.$acceptDocumentAndEditorsDelta({ newActiveEditor: '_notebook_editor_0' });
8181

8282
notebook = extHostNotebooks.notebookDocuments[0]!;
8383

@@ -116,7 +116,7 @@ suite('NotebookCell#Document', function () {
116116
removedCellUris.push(doc.uri.toString());
117117
});
118118

119-
await extHostNotebooks.$acceptDocumentAndEditorsDelta({ removedDocuments: [notebook.uri] });
119+
extHostNotebooks.$acceptDocumentAndEditorsDelta({ removedDocuments: [notebook.uri] });
120120
reg.dispose();
121121

122122
assert.strictEqual(removedCellUris.length, 2);
@@ -174,4 +174,45 @@ suite('NotebookCell#Document', function () {
174174
await p;
175175

176176
});
177+
178+
test('cell document stays open when notebook is still open', async function () {
179+
180+
const docs: vscode.TextDocument[] = [];
181+
const addData: IModelAddedData[] = [];
182+
for (let cell of notebook.cells) {
183+
const doc = extHostDocuments.getDocument(cell.uri);
184+
assert.ok(doc);
185+
assert.equal(extHostDocuments.getDocument(cell.uri).isClosed, false);
186+
docs.push(doc);
187+
addData.push({
188+
EOL: '\n',
189+
isDirty: doc.isDirty,
190+
lines: doc.getText().split('\n'),
191+
modeId: doc.languageId,
192+
uri: doc.uri,
193+
versionId: doc.version
194+
});
195+
}
196+
197+
// this call happens when opening a document on the main side
198+
extHostDocumentsAndEditors.$acceptDocumentsAndEditorsDelta({ addedDocuments: addData });
199+
200+
// this call happens when closing a document from the main side
201+
extHostDocumentsAndEditors.$acceptDocumentsAndEditorsDelta({ removedDocuments: docs.map(d => d.uri) });
202+
203+
// notebook is still open -> cell documents stay open
204+
for (let cell of notebook.cells) {
205+
assert.ok(extHostDocuments.getDocument(cell.uri));
206+
assert.equal(extHostDocuments.getDocument(cell.uri).isClosed, false);
207+
}
208+
209+
// close notebook -> docs are closed
210+
extHostNotebooks.$acceptDocumentAndEditorsDelta({ removedDocuments: [notebook.uri] });
211+
for (let cell of notebook.cells) {
212+
assert.throws(() => extHostDocuments.getDocument(cell.uri));
213+
}
214+
for (let doc of docs) {
215+
assert.equal(doc.isClosed, true);
216+
}
217+
});
177218
});

src/vs/workbench/test/browser/api/extHostNotebookConcatDocument.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ suite('NotebookConcatDocument', function () {
4848
let reg = extHostNotebooks.registerNotebookContentProvider(nullExtensionDescription, 'test', new class extends mock<vscode.NotebookContentProvider>() {
4949
// async openNotebook() { }
5050
});
51-
await extHostNotebooks.$acceptDocumentAndEditorsDelta({
51+
extHostNotebooks.$acceptDocumentAndEditorsDelta({
5252
addedDocuments: [{
5353
handle: 0,
5454
uri: notebookUri,
@@ -72,7 +72,7 @@ suite('NotebookConcatDocument', function () {
7272
}
7373
]
7474
});
75-
await extHostNotebooks.$acceptDocumentAndEditorsDelta({ newActiveEditor: '_notebook_editor_0' });
75+
extHostNotebooks.$acceptDocumentAndEditorsDelta({ newActiveEditor: '_notebook_editor_0' });
7676

7777
notebook = extHostNotebooks.notebookDocuments[0]!;
7878

0 commit comments

Comments
 (0)